aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-04-06 05:39:07 +0800
committerGitHub <noreply@github.com>2018-04-06 05:39:07 +0800
commit44116c6d2bf80f08195f2a7568e80cc57113953f (patch)
tree76ba08d61fddaa05ad985c1359c188018ebbf0e6
parentb5bab254ce2122a43e9ca0fdc757aecda7191576 (diff)
downloadtracifyjs-44116c6d2bf80f08195f2a7568e80cc57113953f.tar.gz
tracifyjs-44116c6d2bf80f08195f2a7568e80cc57113953f.zip
fix AST corruption during `inline` of simple `return` (#3056)
fixes #3054
-rw-r--r--lib/compress.js7
-rw-r--r--test/compress/functions.js30
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 55584fc5..ddba6245 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4576,7 +4576,12 @@ merge(Compressor.prototype, {
if (compressor.option("inline") && stat instanceof AST_Return) {
var value = stat.value;
if (!value || value.is_constant_expression()) {
- var args = self.args.concat(value || make_node(AST_Undefined, self));
+ if (value) {
+ value = value.clone(true);
+ } else {
+ value = make_node(AST_Undefined, self);
+ }
+ var args = self.args.concat(value);
return make_sequence(self, args).optimize(compressor);
}
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index ceaf0643..471ebf7f 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -2237,3 +2237,33 @@ issue_3018: {
}
expect_stdout: "PASS"
}
+
+issue_3054: {
+ options = {
+ booleans: true,
+ collapse_vars: true,
+ inline: 1,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ "use strict";
+ function f() {
+ return { a: true };
+ }
+ console.log(function(b) {
+ b = false;
+ return f();
+ }().a, f.call().a);
+ }
+ expect: {
+ "use strict";
+ function f() {
+ return { a: !0 };
+ }
+ console.log(function(b) {
+ return { a: !(b = !1) };
+ }().a, f.call().a);
+ }
+ expect_stdout: "true true"
+}