aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-08-23 06:03:39 +0800
committerGitHub <noreply@github.com>2018-08-23 06:03:39 +0800
commit694ca5d04590fc22001f7a1c9cc185198f32248f (patch)
tree278e456909f7c5bcb8783e921129838b6c866819
parent57fb58b263677d8667eadc94634c2018934a0f52 (diff)
downloadtracifyjs-694ca5d04590fc22001f7a1c9cc185198f32248f.tar.gz
tracifyjs-694ca5d04590fc22001f7a1c9cc185198f32248f.zip
fix corner case in `unused` (#3234)
fixes #3233
-rw-r--r--lib/compress.js21
-rw-r--r--test/compress/drop-unused.js23
-rw-r--r--test/mocha/cli.js6
3 files changed, 36 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js
index eded00c7..ad86dd84 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -450,8 +450,7 @@ merge(Compressor.prototype, {
return value instanceof AST_Node && def.fixed.parent_scope === scope;
}
return all(def.orig, function(sym) {
- return !(sym instanceof AST_SymbolDefun
- || sym instanceof AST_SymbolLambda);
+ return !(sym instanceof AST_SymbolDefun || sym instanceof AST_SymbolLambda);
});
}
@@ -3329,13 +3328,14 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_Unary && node.write_only) {
sym = node.expression;
}
- if (/strict/.test(compressor.option("pure_getters"))) {
- while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
- if (sym instanceof AST_Sub) props.unshift(sym.property);
- sym = sym.expression;
- }
+ if (!/strict/.test(compressor.option("pure_getters"))) return sym instanceof AST_SymbolRef && sym;
+ while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
+ if (sym instanceof AST_Sub) props.unshift(sym.property);
+ sym = sym.expression;
}
- return sym;
+ return sym instanceof AST_SymbolRef && all(sym.definition().orig, function(sym) {
+ return !(sym instanceof AST_SymbolLambda);
+ }) && sym;
};
var in_use = [];
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
@@ -3430,7 +3430,7 @@ merge(Compressor.prototype, {
var parent = tt.parent();
if (drop_vars) {
var props = [], sym = assign_as_unused(node, props);
- if (sym instanceof AST_SymbolRef) {
+ if (sym) {
var def = sym.definition();
var in_use = def.id in in_use_ids;
var value = null;
@@ -3629,8 +3629,7 @@ merge(Compressor.prototype, {
function scan_ref_scoped(node, descend) {
var node_def, props = [], sym = assign_as_unused(node, props);
- if (sym instanceof AST_SymbolRef
- && self.variables.get(sym.name) === (node_def = sym.definition())) {
+ if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) {
props.forEach(function(prop) {
prop.walk(tw);
});
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 9dc45e57..b75c3ac5 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1982,3 +1982,26 @@ issue_3192: {
"foo bar",
]
}
+
+issue_3233: {
+ options = {
+ pure_getters: "strict",
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = function b() {
+ b.c = "PASS";
+ };
+ a();
+ console.log(a.c);
+ }
+ expect: {
+ var a = function b() {
+ b.c = "PASS";
+ };
+ a();
+ console.log(a.c);
+ }
+ expect_stdout: "PASS"
+}
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 56f6b184..1e27f64e 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -651,7 +651,7 @@ describe("bin/uglifyjs", function() {
});
});
it("Should work with explicit --no-rename", function(done) {
- var command = uglifyjscmd + " test/input/rename/input.js -mc --no-rename";
+ var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
exec(command, function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
@@ -659,7 +659,7 @@ describe("bin/uglifyjs", function() {
});
});
it("Should work with implicit --rename", function(done) {
- var command = uglifyjscmd + " test/input/rename/input.js -mc";
+ var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
exec(command, function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, "function f(n){return n}\n");
@@ -667,7 +667,7 @@ describe("bin/uglifyjs", function() {
});
});
it("Should work with implicit --no-rename", function(done) {
- var command = uglifyjscmd + " test/input/rename/input.js -c";
+ var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
exec(command, function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");