aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-11-17 10:03:31 +0000
committerGitHub <noreply@github.com>2020-11-17 18:03:31 +0800
commit383163afa67c5726e18da145d6eb012ee1b064e3 (patch)
tree67a17555d89272b845e5ff291a42a666e87a14dc /lib/compress.js
parent8a83c8dd46dc8e446cd7231116a06c8b217291b7 (diff)
downloadtracifyjs-383163afa67c5726e18da145d6eb012ee1b064e3.tar.gz
tracifyjs-383163afa67c5726e18da145d6eb012ee1b064e3.zip
fix corner case in `collapse_vars` (#4287)
fixes #4286
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e4426fa3..fe2e6242 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1972,15 +1972,9 @@ merge(Compressor.prototype, {
function find_stop_value(node, level) {
var parent = scanner.parent(level);
if (parent instanceof AST_Array) return find_stop_value(parent, level + 1);
- if (parent instanceof AST_Assign) {
- if (may_throw(parent)) return node;
- if (parent.left instanceof AST_SymbolRef) {
- var name = parent.left.name;
- if (lhs.name == name) return node;
- if (value_def.name == name) return node;
- }
- return find_stop_value(parent, level + 1);
- }
+ if (parent instanceof AST_Assign) return may_throw(parent) || parent.left.match_symbol(function(ref) {
+ return ref instanceof AST_SymbolRef && (lhs.name == ref.name || value_def.name == ref.name);
+ }) ? node : find_stop_value(parent, level + 1);
if (parent instanceof AST_Binary) {
if (lazy_op[parent.operator] && parent.left !== node) {
do {
@@ -2034,12 +2028,9 @@ merge(Compressor.prototype, {
if (parent.operator == "delete") return node;
return find_stop_value(parent, level + 1);
}
- if (parent instanceof AST_VarDef) {
- var name = parent.name.name;
- if (lhs.name == name) return node;
- if (value_def.name == name) return node;
- return find_stop_value(parent, level + 1);
- }
+ if (parent instanceof AST_VarDef) return parent.name.match_symbol(function(sym) {
+ return sym instanceof AST_SymbolDeclaration && (lhs.name == sym.name || value_def.name == sym.name);
+ }) ? node : find_stop_value(parent, level + 1);
if (parent instanceof AST_While) {
if (parent.condition !== node) return node;
return find_stop_value(parent, level + 1);