diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-03 04:45:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-03 04:45:20 +0800 |
commit | 17b81350d46e369588523b421d4528212f0f3207 (patch) | |
tree | fce7fd03f9bf7e247b0a61f1b8c481be1dc9f810 /lib/compress.js | |
parent | 4d63d4f5b30d2b46f3b6ed4cfced277f4f8e428f (diff) | |
download | tracifyjs-17b81350d46e369588523b421d4528212f0f3207.tar.gz tracifyjs-17b81350d46e369588523b421d4528212f0f3207.zip |
fix chained assignment with `unused` (#1540)
When #1450 optimises `a=b=42`, it stops after the first variable even if both are unused.
fixes #1539
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index deb55ade..0cc9c518 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1801,14 +1801,17 @@ merge(Compressor.prototype, { } return node; } - if (drop_vars && assign_as_unused - && node instanceof AST_Assign - && node.operator == "=" - && node.left instanceof AST_SymbolRef) { - var def = node.left.definition(); - if (!(def.id in in_use_ids) && self.variables.get(def.name) === def) { - return node.right; + if (drop_vars && assign_as_unused) { + var n = node; + while (n instanceof AST_Assign + && n.operator == "=" + && n.left instanceof AST_SymbolRef) { + var def = n.left.definition(); + if (def.id in in_use_ids + || self.variables.get(def.name) !== def) break; + n = n.right; } + if (n !== node) return n; } if (node instanceof AST_For) { descend(node, this); |