[Pkg-javascript-commits] [uglifyjs] 26/228: improve keep_fargs & keep_fnames - utilise in_use_ids instead of unreferenced() - drop_unused now up-to-date for subsequent passes
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:13 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit b8b133d91a7a65f3375d391a036623901d1e357f
Author: alexlamsl <alexlamsl at gmail.com>
Date: Sat Feb 18 19:19:12 2017 +0800
improve keep_fargs & keep_fnames
- utilise in_use_ids instead of unreferenced()
- drop_unused now up-to-date for subsequent passes
closes #1476
---
lib/compress.js | 20 ++++++++------------
test/compress/drop-unused.js | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 1f710f1..345a414 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1420,7 +1420,7 @@ merge(Compressor.prototype, {
drop_funcs = drop_vars = true;
}
var in_use = [];
- var in_use_ids = {}; // avoid expensive linear scans of in_use
+ var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
if (self instanceof AST_Toplevel && compressor.top_retain) {
self.variables.each(function(def) {
if (compressor.top_retain(def) && !(def.id in in_use_ids)) {
@@ -1514,11 +1514,17 @@ merge(Compressor.prototype, {
// pass 3: we should drop declarations not in_use
var tt = new TreeTransformer(
function before(node, descend, in_list) {
+ if (node instanceof AST_Function
+ && node.name
+ && !compressor.option("keep_fnames")
+ && !(node.name.definition().id in in_use_ids)) {
+ node.name = null;
+ }
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
if (!compressor.option("keep_fargs")) {
for (var a = node.argnames, i = a.length; --i >= 0;) {
var sym = a[i];
- if (sym.unreferenced()) {
+ if (!(sym.definition().id in in_use_ids)) {
a.pop();
compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
name : sym.name,
@@ -2145,16 +2151,6 @@ merge(Compressor.prototype, {
return self;
});
- OPT(AST_Function, function(self, compressor){
- self = AST_Lambda.prototype.optimize.call(self, compressor);
- if (compressor.option("unused") && !compressor.option("keep_fnames")) {
- if (self.name && self.name.unreferenced()) {
- self.name = null;
- }
- }
- return self;
- });
-
OPT(AST_Call, function(self, compressor){
if (compressor.option("unsafe")) {
var exp = self.expression;
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 5620cf4..5a09c6c 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -556,3 +556,37 @@ drop_toplevel_keep_assign: {
console.log(b = 3);
}
}
+
+drop_fargs: {
+ options = {
+ keep_fargs: false,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b = a;
+ }
+ }
+ expect: {
+ function f() {}
+ }
+}
+
+drop_fnames: {
+ options = {
+ keep_fnames: false,
+ unused: true,
+ }
+ input: {
+ function f() {
+ return function g() {
+ var a = g;
+ };
+ }
+ }
+ expect: {
+ function f() {
+ return function() {};
+ }
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list