aboutsummaryrefslogtreecommitdiff
path: root/lib/scope.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-10 07:45:39 +0000
committerGitHub <noreply@github.com>2020-12-10 15:45:39 +0800
commita59593cac8b5acbefa07daf1fca3af6a72c9d262 (patch)
tree06c805beca2673bedad14c47f15190a08d8fd1a7 /lib/scope.js
parent046bbde9d44a131ec60952e369ec4b22b9718def (diff)
downloadtracifyjs-a59593cac8b5acbefa07daf1fca3af6a72c9d262.tar.gz
tracifyjs-a59593cac8b5acbefa07daf1fca3af6a72c9d262.zip
fix corner case in `loops` & `unused` (#4356)
fixes #4355
Diffstat (limited to 'lib/scope.js')
-rw-r--r--lib/scope.js35
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 6c521bcc..ff0cb58c 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -190,7 +190,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
function entangle(defun, scope) {
if (defun === scope) return;
node.mark_enclosed(options);
- var def = scope.find_variable(node);
+ var def = scope.find_variable(node.name);
if (node.thedef === def) return;
node.thedef = def;
def.orig.push(node);
@@ -219,6 +219,21 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
if (node.label) node.label.thedef.references.push(node);
return true;
}
+ // ensure mangling works if `catch` reuses a scope variable
+ if (node instanceof AST_SymbolCatch) {
+ var def = node.definition().redefined();
+ if (def) for (var s = node.scope; s; s = s.parent_scope) {
+ push_uniq(s.enclosed, def);
+ if (s === def.scope) break;
+ }
+ return true;
+ }
+ // ensure compression works if `const` reuses a scope variable
+ if (node instanceof AST_SymbolConst) {
+ var redef = node.definition().redefined();
+ if (redef) redef.const_redefs = true;
+ return true;
+ }
if (node instanceof AST_SymbolRef) {
var name = node.name;
var sym = node.scope.find_variable(name);
@@ -258,21 +273,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
node.reference(options);
return true;
}
- // ensure mangling works if `catch` reuses a scope variable
- if (node instanceof AST_SymbolCatch) {
- var def = node.definition().redefined();
- if (def) for (var s = node.scope; s; s = s.parent_scope) {
- push_uniq(s.enclosed, def);
- if (s === def.scope) break;
- }
- return true;
- }
- // ensure compression works if `const` reuses a scope variable
- if (node instanceof AST_SymbolConst) {
- var redef = node.definition().redefined();
- if (redef) redef.const_redefs = true;
- return true;
- }
});
self.walk(tw);
@@ -390,9 +390,8 @@ AST_Symbol.DEFMETHOD("reference", function(options) {
});
AST_BlockScope.DEFMETHOD("find_variable", function(name) {
- if (name instanceof AST_Symbol) name = name.name;
return this.variables.get(name)
- || (this.parent_scope && this.parent_scope.find_variable(name));
+ || this.parent_scope && this.parent_scope.find_variable(name);
});
AST_BlockScope.DEFMETHOD("def_function", function(symbol, init) {