diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-11-27 17:35:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-27 17:35:21 +0800 |
commit | d4b701067805f5041c3b27225742a7b36c3db90c (patch) | |
tree | 6d43085a36f7eafcdcf217b717e46c8ca2c92ac2 /lib | |
parent | e27493f3c2e637b8f3e9da4757e76959a8705cd9 (diff) | |
download | tracifyjs-d4b701067805f5041c3b27225742a7b36c3db90c.tar.gz tracifyjs-d4b701067805f5041c3b27225742a7b36c3db90c.zip |
fix corner case in `unsafe_regexp` (#3609)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js index 46a7816e..19fba0b6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -362,6 +362,7 @@ merge(Compressor.prototype, { function reset_def(tw, compressor, def) { def.assignments = 0; def.chained = false; + def.cross_loop = false; def.direct_access = false; def.escaped = []; def.fixed = !def.scope.pinned() @@ -765,6 +766,9 @@ merge(Compressor.prototype, { d.fixed = false; } } + if (d.fixed && tw.loop_ids[d.id] !== tw.in_loop) { + d.cross_loop = true; + } mark_escaped(tw, d, this.scope, this, value, 0, 1); } var parent; @@ -6494,14 +6498,13 @@ merge(Compressor.prototype, { if (fixed && def.should_replace === undefined) { var init; if (fixed instanceof AST_This) { - if (!(def.orig[0] instanceof AST_SymbolFunarg) && all(def.references, function(ref) { - return def.scope === ref.scope; - })) { + if (!(def.orig[0] instanceof AST_SymbolFunarg) && same_scope(def)) { init = fixed; } } else { var ev = fixed.evaluate(compressor); - if (ev !== fixed && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))) { + if (ev !== fixed && (!(ev instanceof RegExp) + || compressor.option("unsafe_regexp") && !def.cross_loop && same_scope(def))) { init = make_node_from_constant(ev, fixed); } } @@ -6538,6 +6541,13 @@ merge(Compressor.prototype, { } return self; + function same_scope(def) { + var scope = def.scope.resolve(); + return all(def.references, function(ref) { + return scope === ref.scope.resolve(); + }); + } + function has_symbol_ref(value) { var found; value.walk(new TreeWalker(function(node) { |