aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-06-05 07:28:08 +0100
committerGitHub <noreply@github.com>2020-06-05 14:28:08 +0800
commitfbc9d8009bee522fe784602ba8b157a38a45bd69 (patch)
tree64eab854a7d7fafe6bff452ed2f78043986fdc88
parent04fd3d90f8600bc8c6c5715abce06617110d88d6 (diff)
downloadtracifyjs-fbc9d8009bee522fe784602ba8b157a38a45bd69.tar.gz
tracifyjs-fbc9d8009bee522fe784602ba8b157a38a45bd69.zip
fix corner case in `collapse_vars` (#3954)
-rw-r--r--lib/compress.js14
-rw-r--r--test/compress/collapse_vars.js24
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 17b3ecf7..23a9f923 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1832,13 +1832,13 @@ merge(Compressor.prototype, {
return make_node(AST_SymbolRef, expr.name, expr.name);
}
} else if (expr instanceof AST_Assign) {
- var lhs = expr.left;
- if (expr.operator == "=" && lhs instanceof AST_SymbolRef) {
- var def = lhs.definition();
- if (def.references[0] === lhs) {
- var referenced = def.references.length - def.replaced;
- if (referenced > 1) mangleable_var(expr.right);
- }
+ var def, lhs = expr.left;
+ if (expr.operator == "="
+ && lhs instanceof AST_SymbolRef
+ && (def = lhs.definition()).references[0] === lhs
+ && !compressor.exposed(def)) {
+ var referenced = def.references.length - def.replaced;
+ if (referenced > 1) mangleable_var(expr.right);
}
return lhs;
} else {
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index cea5ca84..0c232aa0 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -6888,6 +6888,30 @@ sequence_in_iife_2: {
}
expect: {
var a = "foo", b = 42;
+ b = a;
+ console.log(a, b);
+ }
+ expect_stdout: "foo foo"
+}
+
+sequence_in_iife_3: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ passes: 2,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = "foo", b = 42;
+ (function() {
+ var c = (b = a, b);
+ })();
+ console.log(a, b);
+ }
+ expect: {
+ var a = "foo";
console.log(a, a);
}
expect_stdout: "foo foo"