diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-11-06 16:10:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 16:10:57 +0800 |
commit | 2cfb5aa7dadd744bf7fbe16756696fc595f134a2 (patch) | |
tree | 047a685ececbd705d3fd69dd630723fe2c706b72 /lib | |
parent | 6c4510187066555c77003f03fd26e2cf5ff47491 (diff) | |
download | tracifyjs-2cfb5aa7dadd744bf7fbe16756696fc595f134a2.tar.gz tracifyjs-2cfb5aa7dadd744bf7fbe16756696fc595f134a2.zip |
account for `eval` & `with` in `reduce_vars` (#2441)
fixes #2440
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index d8482337..c1232420 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -317,7 +317,7 @@ merge(Compressor.prototype, { d.fixed = false; } else if (d.fixed) { var value = node.fixed_value(); - if (unused && value && d.references.length == 1) { + if (value && ref_once(d)) { if (value instanceof AST_Lambda) { d.single_use = d.scope === node.scope && !(d.orig[0] instanceof AST_SymbolFunarg) @@ -385,7 +385,7 @@ merge(Compressor.prototype, { } else { d.fixed = node; mark(d, true); - if (unused && d.references.length == 1) { + if (ref_once(d)) { d.single_use = d.scope === d.references[0].scope || node.is_constant_expression(d.references[0].scope); } @@ -564,7 +564,7 @@ merge(Compressor.prototype, { function reset_def(def) { def.direct_access = false; def.escaped = false; - if (def.scope.uses_eval) { + if (def.scope.uses_eval || def.scope.uses_with) { def.fixed = false; } else if (!compressor.exposed(def)) { def.fixed = undefined; @@ -576,6 +576,10 @@ merge(Compressor.prototype, { def.single_use = undefined; } + function ref_once(def) { + return unused && !def.scope.uses_eval && !def.scope.uses_with && def.references.length == 1; + } + function is_immutable(value) { if (!value) return false; return value.is_constant() @@ -4237,10 +4241,7 @@ merge(Compressor.prototype, { if (fixed instanceof AST_Defun) { d.fixed = fixed = make_node(AST_Function, fixed, fixed); } - if (compressor.option("unused") - && fixed - && d.references.length == 1 - && d.single_use) { + if (fixed && d.single_use) { var value = fixed.optimize(compressor); return value === fixed ? fixed.clone(true) : value; } |