aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-16 20:47:48 +0000
committerGitHub <noreply@github.com>2020-12-17 04:47:48 +0800
commitf68e267830c94f129df4c9e93674abfafbc0125b (patch)
treebac0fbdd864b40346222a1e0634ab879832f6824
parent8b10b93ee1cd583aa15f608a89a51353a1828944 (diff)
downloadtracifyjs-f68e267830c94f129df4c9e93674abfafbc0125b.tar.gz
tracifyjs-f68e267830c94f129df4c9e93674abfafbc0125b.zip
fix corner case in `reduce_vars` (#4384)
fixes #4383
-rw-r--r--lib/compress.js15
-rw-r--r--test/compress/destructured.js22
2 files changed, 33 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fb5bcb74..b767264c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -644,7 +644,14 @@ merge(Compressor.prototype, {
fixed = save;
return true;
}
- visit(node, fixed);
+ visit(node, fixed, function() {
+ var save_len = tw.stack.length;
+ for (var i = 0, len = scanner.stack.length - 1; i < len; i++) {
+ tw.stack.push(scanner.stack[i]);
+ }
+ node.walk(tw);
+ tw.stack.length = save_len;
+ });
return true;
});
lhs.walk(scanner);
@@ -678,10 +685,10 @@ merge(Compressor.prototype, {
node.right.walk(tw);
scan_declaration(tw, left, function() {
return node.right;
- }, function(sym, fixed) {
+ }, function(sym, fixed, walk) {
if (!(sym instanceof AST_SymbolRef)) {
mark_assignment_to_arguments(sym);
- sym.walk(tw);
+ walk();
return;
}
var d = sym.definition();
@@ -696,7 +703,7 @@ merge(Compressor.prototype, {
sym.fixed = d.fixed = fixed;
sym.fixed.assigns = [ node ];
} else {
- sym.walk(tw);
+ walk();
d.fixed = false;
}
});
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 086790f0..9fd425d1 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -1844,3 +1844,25 @@ issue_4372_2: {
expect_stdout: "PASS"
node_version: ">=6"
}
+
+issue_4383: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ unsafe: true,
+ }
+ input: {
+ console.log(function(a) {
+ [ a[0] ] = [];
+ return a.length;
+ }([]));
+ }
+ expect: {
+ console.log(function(a) {
+ [ a[0] ] = [];
+ return a.length;
+ }([]));
+ }
+ expect_stdout: "1"
+ node_version: ">=6"
+}