diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-02 01:24:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-02 01:24:53 +0800 |
commit | d838b4b52e4b7bea5e2f473469c07f6a3cce397d (patch) | |
tree | bc1bb400113405b82a891417a69406f94f79c6c4 /lib | |
parent | 2f3bddbacaaafb73ed046090a74ce6558c54a218 (diff) | |
download | tracifyjs-d838b4b52e4b7bea5e2f473469c07f6a3cce397d.tar.gz tracifyjs-d838b4b52e4b7bea5e2f473469c07f6a3cce397d.zip |
reset argument value within loop after `inline` (#2699)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js index 73cc9d7b..203c1443 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3991,7 +3991,7 @@ merge(Compressor.prototype, { } } if (is_func) { - var def, value, scope, level = -1; + var def, value, scope, in_loop, level = -1; if (compressor.option("inline") && !fn.uses_arguments && !fn.uses_eval @@ -4038,13 +4038,13 @@ merge(Compressor.prototype, { return self; function can_flatten_args(fn) { - var catches = Object.create(null), defs; + var catches = Object.create(null); do { scope = compressor.parent(++level); if (scope instanceof AST_Catch) { catches[scope.argname.name] = true; } else if (scope instanceof AST_IterationStatement) { - defs = []; + in_loop = []; } else if (scope instanceof AST_SymbolRef) { if (scope.fixed_value() instanceof AST_Scope) return false; } @@ -4059,9 +4059,9 @@ merge(Compressor.prototype, { || scope.var_names()[arg.name]) { return false; } - if (defs) defs.push(arg.definition()); + if (in_loop) in_loop.push(arg.definition()); } - return !defs || defs.length == 0 || !is_reachable(stat, defs); + return !in_loop || in_loop.length == 0 || !is_reachable(stat, in_loop); } function flatten_args(fn) { @@ -4087,6 +4087,7 @@ merge(Compressor.prototype, { })); var sym = make_node(AST_SymbolRef, name, name); def.references.push(sym); + if (!value && in_loop) value = make_node(AST_Undefined, self); if (value) expressions.unshift(make_node(AST_Assign, self, { operator: "=", left: sym, |