aboutsummaryrefslogtreecommitdiff
path: root/lib/scope.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-02 16:29:58 +0100
committerGitHub <noreply@github.com>2020-10-02 23:29:58 +0800
commitccd91b9952c986ec071f4bf7a552a1dd09b6f570 (patch)
tree41eed86078284779ccceaf448f7f227dd1ca6492 /lib/scope.js
parent47a5e6e17a91719dd8ee124f818e6a1996b4d668 (diff)
downloadtracifyjs-ccd91b9952c986ec071f4bf7a552a1dd09b6f570.tar.gz
tracifyjs-ccd91b9952c986ec071f4bf7a552a1dd09b6f570.zip
retrofit `catch` as block-scoped (#4165)
Diffstat (limited to 'lib/scope.js')
-rw-r--r--lib/scope.js35
1 files changed, 10 insertions, 25 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 405f563d..af888008 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -100,19 +100,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
var next_def_id = 0;
var scope = self.parent_scope = null;
var tw = new TreeWalker(function(node, descend) {
- if (node instanceof AST_Catch) {
- var save_scope = scope;
- scope = new AST_Scope(node);
- scope.init_scope_vars(save_scope);
- descend();
- scope = save_scope;
- return true;
- }
- if (node instanceof AST_Scope) {
+ if (node instanceof AST_BlockScope) {
node.init_scope_vars(scope);
- var save_scope = scope;
var save_defun = defun;
- defun = scope = node;
+ var save_scope = scope;
+ if (node instanceof AST_Scope) defun = node;
+ scope = node;
descend();
scope = save_scope;
defun = save_defun;
@@ -267,7 +260,7 @@ function init_scope_vars(scope, parent) {
if (parent) scope.make_def = parent.make_def; // top-level tracking of SymbolDef instances
}
-AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
+AST_BlockScope.DEFMETHOD("init_scope_vars", function(parent_scope) {
init_scope_vars(this, parent_scope);
});
@@ -300,20 +293,20 @@ AST_Symbol.DEFMETHOD("reference", function(options) {
this.mark_enclosed(options);
});
-AST_Scope.DEFMETHOD("find_variable", function(name) {
+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));
});
-AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
+AST_BlockScope.DEFMETHOD("def_function", function(symbol, init) {
var def = this.def_variable(symbol, init);
if (!def.init || def.init instanceof AST_Defun) def.init = init;
this.functions.set(symbol.name, def);
return def;
});
-AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
+AST_BlockScope.DEFMETHOD("def_variable", function(symbol, init) {
var def = this.variables.get(symbol.name);
if (def) {
def.orig.push(symbol);
@@ -326,12 +319,6 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
return symbol.thedef = def;
});
-AST_Lambda.DEFMETHOD("resolve", return_this);
-AST_Scope.DEFMETHOD("resolve", function() {
- return this.parent_scope.resolve();
-});
-AST_Toplevel.DEFMETHOD("resolve", return_this);
-
function names_in_use(scope, options) {
var names = scope.names_in_use;
if (!names) {
@@ -495,8 +482,7 @@ AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
options.reserved.forEach(to_avoid);
this.globals.each(add_def);
this.walk(new TreeWalker(function(node) {
- if (node instanceof AST_Scope) node.variables.each(add_def);
- if (node instanceof AST_SymbolCatch) add_def(node.definition());
+ if (node instanceof AST_BlockScope) node.variables.each(add_def);
}));
return avoid;
@@ -520,8 +506,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
var cname = 0;
this.globals.each(rename);
this.walk(new TreeWalker(function(node) {
- if (node instanceof AST_Scope) node.variables.each(rename);
- if (node instanceof AST_SymbolCatch) rename(node.definition());
+ if (node instanceof AST_BlockScope) node.variables.each(rename);
}));
function next_name() {