aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-05 20:25:32 +0000
committerGitHub <noreply@github.com>2021-03-06 04:25:32 +0800
commitfa09f87589015cf7056d9d0296d2df9c10483331 (patch)
tree51934957a1c351d67afea22cabe5c183105ee636
parent2db1a141ab16911cf10de885a619be7b2b97b28b (diff)
downloadtracifyjs-fa09f87589015cf7056d9d0296d2df9c10483331.tar.gz
tracifyjs-fa09f87589015cf7056d9d0296d2df9c10483331.zip
fix corner case in `hoist_vars` (#4739)
fixes #4736
-rw-r--r--lib/compress.js20
-rw-r--r--test/compress/hoist_vars.js33
2 files changed, 41 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c9ba218d..9d390d09 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6821,18 +6821,14 @@ merge(Compressor.prototype, {
if (vars_found > 0) {
// collect only vars which don't show up in self's arguments list
var defs = [];
+ if (self instanceof AST_Lambda) self.each_argname(function(argname) {
+ vars.del(argname.name);
+ });
vars.each(function(def, name) {
- if (self instanceof AST_Lambda
- && !all(self.argnames, function(argname) {
- return argname.name != name;
- })) {
- vars.del(name);
- } else {
- def = def.clone();
- def.value = null;
- defs.push(def);
- vars.set(name, def);
- }
+ def = def.clone();
+ def.value = null;
+ defs.push(def);
+ vars.set(name, def);
});
if (defs.length > 0) {
// try to merge in assignments
@@ -6856,7 +6852,7 @@ merge(Compressor.prototype, {
&& vars.has(sym.name)) {
var def = vars.get(sym.name);
if (def.value) break;
- def.value = expr.right;
+ def.value = expr.right.clone();
remove(defs, def);
defs.push(def);
body.shift();
diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js
index 020155aa..305f98c6 100644
--- a/test/compress/hoist_vars.js
+++ b/test/compress/hoist_vars.js
@@ -140,6 +140,7 @@ issue_4487: {
functions: true,
hoist_vars: true,
keep_fnames: true,
+ passes: 2,
reduce_vars: true,
toplevel: true,
unused: true,
@@ -207,3 +208,35 @@ issue_4517: {
}
expect_stdout: "2boolean"
}
+
+issue_4736: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ hoist_vars: true,
+ merge_vars: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a;
+ function f() {
+ (function g() {
+ var b = (a = 0, 1 << 30);
+ var c = (a = 0, console.log(b));
+ var d = c;
+ })(f);
+ }
+ f();
+ }
+ expect: {
+ (function() {
+ (function() {
+ 0,
+ console.log(1073741824);
+ })();
+ })();
+ }
+ expect_stdout: "1073741824"
+}