store all undeclared references on Program to better handle let scoping

This commit is contained in:
Sebastian McKenzie
2015-01-22 10:12:03 +11:00
parent 5463872926
commit 3e2d611707

View File

@@ -156,10 +156,6 @@ var functionVariableVisitor = {
// function identifier doesn't belong to this scope
if (state.blockId && node === state.blockId) return;
if (t.isIdentifier(node) && t.isReferenced(node, parent) && !scope.has(node.name)) {
state.add(node, true);
}
// we've ran into a declaration!
// we'll let the BlockStatement scope deal with `let` declarations unless
if (t.isDeclaration(node) && !t.isBlockScoped(node)) {
@@ -168,6 +164,14 @@ var functionVariableVisitor = {
}
};
var programReferenceVisitor = {
enter: function (node, parent, scope, context, add) {
if (t.isReferencedIdentifier(node, parent) && !scope.has(node.name)) {
add(node, true);
}
}
};
var blockVariableVisitor = {
enter: function (node, parent, scope, context, add) {
if (t.isBlockScoped(node)) {
@@ -243,6 +247,12 @@ Scope.prototype.getInfo = function () {
});
}
// Program
if (t.isProgram(block)) {
traverse(block, programReferenceVisitor, this, add);
}
// Function - params, rest
if (t.isFunction(block)) {