aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-10-22 15:41:55 +0800
committerGitHub <noreply@github.com>2019-10-22 15:41:55 +0800
commit0b3705e82f550b82bebb0c4f877ce8f41fc7495d (patch)
tree40c746e3814c7464de74042dae62133ea4cb8b39
parentda5a21b2408ec3194728a15d2f7406c0098631f9 (diff)
downloadtracifyjs-0b3705e82f550b82bebb0c4f877ce8f41fc7495d.tar.gz
tracifyjs-0b3705e82f550b82bebb0c4f877ce8f41fc7495d.zip
fix corner cases in `inline` (#3507)
fixes #3506
-rw-r--r--lib/compress.js12
-rw-r--r--test/compress/collapse_vars.js2
-rw-r--r--test/compress/functions.js164
-rw-r--r--test/compress/pure_getters.js2
-rw-r--r--test/compress/reduce_vars.js4
5 files changed, 167 insertions, 17 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8ef94e43..2b61e91c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3643,8 +3643,8 @@ merge(Compressor.prototype, {
if (!(sym.definition().id in in_use_ids)) {
sym.__unused = true;
if (trim) {
+ log(sym, "Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
a.pop();
- AST_Node[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
}
} else {
trim = false;
@@ -3654,7 +3654,7 @@ merge(Compressor.prototype, {
if (drop_funcs && node instanceof AST_Defun && node !== self) {
var def = node.name.definition();
if (!(def.id in in_use_ids)) {
- AST_Node[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
+ log(node.name, "Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
def.eliminated++;
return make_node(AST_EmptyStatement, node);
}
@@ -3742,7 +3742,7 @@ merge(Compressor.prototype, {
AST_Node.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
side_effects.push(value);
} else {
- AST_Node[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
+ log(def.name, "Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
}
sym.eliminated++;
}
@@ -3820,6 +3820,10 @@ merge(Compressor.prototype, {
return node;
}
+ function log(sym, text, props) {
+ AST_Node[sym.unreferenced() ? "warn" : "info"](text, props);
+ }
+
function template(sym) {
return {
name : sym.name,
@@ -5202,7 +5206,7 @@ merge(Compressor.prototype, {
if (stat instanceof AST_SimpleStatement) {
return make_node(AST_UnaryPrefix, stat, {
operator: "void",
- expression: stat.body.clone(true)
+ expression: stat.body
});
}
}
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 951d72d6..a793ef6c 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3511,7 +3511,7 @@ issue_2437_2: {
conditionals: true,
inline: true,
join_vars: true,
- passes: 2,
+ passes: 3,
reduce_funcs: true,
reduce_vars: true,
sequences: true,
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 92a0f99c..5c8533de 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -3066,7 +3066,7 @@ class_iife: {
expect_stdout: "PASS"
}
-issue_3400: {
+issue_3400_1: {
options = {
collapse_vars: true,
inline: true,
@@ -3096,16 +3096,70 @@ issue_3400: {
});
}
expect: {
+ void console.log(function() {
+ function g() {
+ function h(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }
+ function e() {
+ return [ 42 ].map(function(v) {
+ return h(v);
+ });
+ }
+ return e();
+ }
+ return g;
+ }()()[0].p);
+ }
+ expect_stdout: [
+ "undefined",
+ "42",
+ ]
+}
+
+issue_3400_2: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(f) {
+ console.log(f()()[0].p);
+ })(function() {
+ function g() {
+ function h(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }
+ function e() {
+ return [ 42 ].map(function(v) {
+ return h(v);
+ });
+ }
+ return e();
+ }
+ return g;
+ });
+ }
+ expect: {
void console.log(function g() {
- function e() {
- return [42].map(function(v) {
- return o = {
- p: v
- }, console.log(o[g]) , o;
- var o;
- });
- }
- return e();
+ return [ 42 ].map(function(v) {
+ return function(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
+ }(v);
+ });
}()[0].p);
}
expect_stdout: [
@@ -3196,3 +3250,93 @@ issue_3444: {
}
expect_stdout: "PASS"
}
+
+issue_3506_1: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ inline: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(b) {
+ b && (a = "PASS");
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(b) {
+ b && (a = "PASS");
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3506_2: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ inline: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3506_3: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ evaluate: true,
+ inline: true,
+ loops: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function(b) {
+ (function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ })(b);
+ })(a);
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ !function(c) {
+ var d = 1;
+ for (;c && (a = "PASS") && 0 < --d;);
+ }(a);
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js
index 54c89c6d..9764f0f4 100644
--- a/test/compress/pure_getters.js
+++ b/test/compress/pure_getters.js
@@ -1193,6 +1193,7 @@ issue_3427: {
assignments: true,
collapse_vars: true,
inline: true,
+ passes: 2,
pure_getters: "strict",
sequences: true,
side_effects: true,
@@ -1206,4 +1207,5 @@ issue_3427: {
})(a || (a = {}));
}
expect: {}
+ expect_stdout: true
}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 7bf7508a..744cdf1b 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -6609,10 +6609,10 @@ issues_3267_1: {
}
expect: {
!function(i) {
- if (i)
+ if (Object())
return console.log("PASS");
throw "FAIL";
- }(Object());
+ }();
}
expect_stdout: "PASS"
}