[Pkg-javascript-commits] [node-acorn-jsx] 168/484: [walker] Handle catch scopes more accurately in scopeVisitor
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit e6ff440e9f7ce036b78f19db16a9413e0e7d8811
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Thu Nov 28 16:56:14 2013 +0100
[walker] Handle catch scopes more accurately in scopeVisitor
---
util/walk.js | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/util/walk.js b/util/walk.js
index 49e44b1..4c0d9a7 100644
--- a/util/walk.js
+++ b/util/walk.js
@@ -272,8 +272,12 @@
// A custom walker that keeps track of the scope chain and the
// variables defined in it.
- function makeScope(prev) {
- return {vars: Object.create(null), prev: prev};
+ function makeScope(prev, isCatch) {
+ return {vars: Object.create(null), prev: prev, isCatch: isCatch};
+ }
+ function normalScope(scope) {
+ while (scope.isCatch) scope = scope.prev;
+ return scope;
}
exports.scopeVisitor = exports.make({
Function: function(node, scope, c) {
@@ -282,7 +286,7 @@
inner.vars[node.params[i].name] = {type: "argument", node: node.params[i]};
if (node.id) {
var decl = node.type == "FunctionDeclaration";
- (decl ? scope : inner).vars[node.id.name] =
+ (decl ? normalScope(scope) : inner).vars[node.id.name] =
{type: decl ? "function" : "function name", node: node.id};
}
c(node.body, inner, "ScopeBody");
@@ -290,16 +294,17 @@
TryStatement: function(node, scope, c) {
c(node.block, scope, "Statement");
if (node.handler) {
- var inner = makeScope(scope);
+ var inner = makeScope(scope, true);
inner.vars[node.handler.param.name] = {type: "catch clause", node: node.handler.param};
c(node.handler.body, inner, "ScopeBody");
}
if (node.finalizer) c(node.finalizer, scope, "Statement");
},
VariableDeclaration: function(node, scope, c) {
+ var target = normalScope(scope);
for (var i = 0; i < node.declarations.length; ++i) {
var decl = node.declarations[i];
- scope.vars[decl.id.name] = {type: "var", node: decl.id};
+ target.vars[decl.id.name] = {type: "var", node: decl.id};
if (decl.init) c(decl.init, scope, "Expression");
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list