diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-10-20 03:53:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-20 03:53:20 +0800 |
commit | ca6dce43feb9d92cb5004c6ee4d5b2e0b4336d93 (patch) | |
tree | 993c51498c77a037410589184a907e765f72282f /lib/compress.js | |
parent | 543dd7d3d750e83b00e50bbf74fa786a7c1d243e (diff) | |
download | tracifyjs-ca6dce43feb9d92cb5004c6ee4d5b2e0b4336d93.tar.gz tracifyjs-ca6dce43feb9d92cb5004c6ee4d5b2e0b4336d93.zip |
fix corner case in `collapse_vars` (#3501)
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/lib/compress.js b/lib/compress.js index 0888c107..8ef94e43 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1465,50 +1465,20 @@ merge(Compressor.prototype, { hit_stack.pop(); } - function find_stop(node, level, write_only) { + function find_stop(node, level) { var parent = scanner.parent(level); - if (parent instanceof AST_Assign) { - if (write_only - && !(parent.left instanceof AST_PropAccess - || parent.left.name in lvalues)) { - return find_stop(parent, level + 1, write_only); - } - return node; - } - if (parent instanceof AST_Binary) { - if (write_only && (!lazy_op[parent.operator] || parent.left === node)) { - return find_stop(parent, level + 1, write_only); - } - return node; - } + if (parent instanceof AST_Assign) return node; + if (parent instanceof AST_Binary) return node; if (parent instanceof AST_Call) return node; if (parent instanceof AST_Case) return node; - if (parent instanceof AST_Conditional) { - if (write_only && parent.condition === node) { - return find_stop(parent, level + 1, write_only); - } - return node; - } - if (parent instanceof AST_Definitions) { - return find_stop(parent, level + 1, true); - } - if (parent instanceof AST_Exit) { - return write_only ? find_stop(parent, level + 1, write_only) : node; - } - if (parent instanceof AST_If) { - if (write_only && parent.condition === node) { - return find_stop(parent, level + 1, write_only); - } - return node; - } + if (parent instanceof AST_Conditional) return node; + if (parent instanceof AST_Definitions) return find_stop(parent, level + 1); + if (parent instanceof AST_Exit) return node; + if (parent instanceof AST_If) return node; if (parent instanceof AST_IterationStatement) return node; if (parent instanceof AST_PropAccess) return node; - if (parent instanceof AST_Sequence) { - return find_stop(parent, level + 1, parent.tail_node() !== node); - } - if (parent instanceof AST_SimpleStatement) { - return find_stop(parent, level + 1, true); - } + if (parent instanceof AST_Sequence) return find_stop(parent, level + 1); + if (parent instanceof AST_SimpleStatement) return find_stop(parent, level + 1); if (parent instanceof AST_Switch) return node; if (parent instanceof AST_Unary) return node; if (parent instanceof AST_VarDef) return node; |