cache scope ids and limit id variable declarations to kind
This commit is contained in:
parent
56271efada
commit
71d87f5b97
@ -6,12 +6,15 @@ var _ = require("lodash");
|
||||
|
||||
function Scope(parent, block) {
|
||||
this.parent = parent;
|
||||
this.ids = block._scopeIds = block._scopeIds || Scope.getIds(block);
|
||||
}
|
||||
|
||||
Scope.getIds = function (block) {
|
||||
var ids = [];
|
||||
|
||||
if (t.isBlockStatement(block)) {
|
||||
_.each(block.body, function (node) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (t.isVariableDeclaration(node) && node.kind !== "var") {
|
||||
ids = ids.concat(t.getIds(node));
|
||||
}
|
||||
});
|
||||
@ -19,7 +22,7 @@ function Scope(parent, block) {
|
||||
|
||||
if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, function (node) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (t.isVariableDeclaration(node) && node.kind === "var") {
|
||||
ids = ids.concat(t.getIds(node));
|
||||
} else if (t.isFunction(node)) {
|
||||
return false;
|
||||
@ -33,12 +36,12 @@ function Scope(parent, block) {
|
||||
});
|
||||
}
|
||||
|
||||
this.ids = ids;
|
||||
}
|
||||
return ids;
|
||||
};
|
||||
|
||||
Scope.prototype.has = function (id) {
|
||||
Scope.prototype.has = function (id, noParent) {
|
||||
if (!id) return false;
|
||||
if (_.contains(this.ids, id)) return true;
|
||||
if (this.parent) return this.parent.has(id);
|
||||
if (noParent !== false && this.parent) return this.parent.has(id);
|
||||
return false;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user