aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-02 15:33:58 +0000
committerGitHub <noreply@github.com>2021-03-02 23:33:58 +0800
commitadcafce04852bb4730e3e699dfdd656dc018cd0f (patch)
tree3f30430a010b2967022755f58bee570a9876bc3c /lib
parentb1e05fd48afd9aceaa00cc621a8f6ac22c097398 (diff)
downloadtracifyjs-adcafce04852bb4730e3e699dfdd656dc018cd0f.tar.gz
tracifyjs-adcafce04852bb4730e3e699dfdd656dc018cd0f.zip
fix corner cases in `varify` (#4719)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e5e822af..7f642797 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -7723,7 +7723,10 @@ merge(Compressor.prototype, {
var name = self.init.definitions[0].name;
if ((name instanceof AST_Destructured || name instanceof AST_SymbolLet)
&& !name.match_symbol(function(node) {
- if (node instanceof AST_SymbolDeclaration) return may_overlap(compressor, node.definition());
+ if (node instanceof AST_SymbolDeclaration) {
+ var def = node.definition();
+ return !same_scope(def) || may_overlap(compressor, def);
+ }
}, true)) {
self.init = to_var(self.init);
}
@@ -8269,7 +8272,7 @@ merge(Compressor.prototype, {
function can_varify(compressor, sym) {
if (!sym.fixed_value()) return false;
var def = sym.definition();
- return is_safe_lexical(def) && !may_overlap(compressor, def);
+ return is_safe_lexical(def) && same_scope(def) && !may_overlap(compressor, def);
}
function varify(self, compressor) {
@@ -10214,6 +10217,13 @@ merge(Compressor.prototype, {
} while (node = compressor.parent(level++));
}
+ function same_scope(def) {
+ var scope = def.scope.resolve();
+ return all(def.references, function(ref) {
+ return scope === ref.scope.resolve();
+ });
+ }
+
OPT(AST_SymbolRef, function(self, compressor) {
if (!compressor.option("ie8")
&& is_undeclared_ref(self)
@@ -10380,13 +10390,6 @@ 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) {