aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-06-29 02:06:23 +0100
committerGitHub <noreply@github.com>2020-06-29 09:06:23 +0800
commit3bf8699f951c32a93414d1ac4c72364e2e282b33 (patch)
tree770c9164afcb11659c4dd5f9e36eff8bcef5c2ba
parent58c24f80078cd819ee1ae741655628cc6ec74c02 (diff)
downloadtracifyjs-3bf8699f951c32a93414d1ac4c72364e2e282b33.tar.gz
tracifyjs-3bf8699f951c32a93414d1ac4c72364e2e282b33.zip
fix corner case in `inline` (#4007)
fixes #4006
-rw-r--r--lib/compress.js15
-rw-r--r--test/compress/functions.js31
-rw-r--r--test/ufuzz/index.js1
3 files changed, 37 insertions, 10 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 0e11ba96..10a84c6b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6415,16 +6415,11 @@ merge(Compressor.prototype, {
function return_value(stat) {
if (!stat) return make_node(AST_Undefined, self);
- if (stat instanceof AST_Return) {
- if (!stat.value) return make_node(AST_Undefined, self);
- return stat.value.clone(true);
- }
- if (stat instanceof AST_SimpleStatement) {
- return make_node(AST_UnaryPrefix, stat, {
- operator: "void",
- expression: stat.body
- });
- }
+ if (stat instanceof AST_Return) return stat.value || make_node(AST_Undefined, self);
+ if (stat instanceof AST_SimpleStatement) return make_node(AST_UnaryPrefix, stat, {
+ operator: "void",
+ expression: stat.body
+ });
}
function can_flatten_body(stat) {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 1383dbe9..18f4f900 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -4747,3 +4747,34 @@ issue_3929: {
}
expect_stdout: "function"
}
+
+issue_4006: {
+ options = {
+ dead_code: true,
+ evaluate: true,
+ inline: true,
+ keep_fargs: "strict",
+ reduce_vars: true,
+ sequences: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = 0;
+ (function() {
+ (function(b, c) {
+ for (var k in console.log(c), 0)
+ return b += 0;
+ })(0, --a);
+ return a ? 0 : --a;
+ })();
+ }
+ expect: {
+ var a = 0;
+ (function(c) {
+ for (var k in console.log(c), 0)
+ return;
+ })(--a), a || --a;
+ }
+ expect_stdout: "-1"
+}
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 7fe35308..64ea805c 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -197,6 +197,7 @@ BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
+BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS.push(" in ");
var ASSIGNMENTS = [