add isBlockedScoped types helper

This commit is contained in:
Sebastian McKenzie 2015-01-18 18:23:37 +11:00
parent d360bd5bb7
commit 774cb66d9b
2 changed files with 14 additions and 3 deletions

View File

@ -135,7 +135,7 @@ Scope.prototype.getInfo = function () {
if (t.isFor(block)) {
_.each(FOR_KEYS, function (key) {
var node = block[key];
if (t.isLet(node)) add(node);
if (t.isBlockScoped(node)) add(node);
});
}
@ -144,7 +144,7 @@ Scope.prototype.getInfo = function () {
if (t.isBlockStatement(block) || t.isProgram(block)) {
_.each(block.body, function (node) {
// check for non-var `VariableDeclaration`s
if (t.isLet(node)) add(node);
if (t.isBlockScoped(node)) add(node);
});
}
@ -190,7 +190,7 @@ Scope.prototype.getInfo = function () {
// we've ran into a declaration!
// we'll let the BlockStatement scope deal with `let` declarations unless
if (t.isDeclaration(node) && !t.isLet(node)) {
if (t.isDeclaration(node) && !t.isBlockScoped(node)) {
state.add(node);
}
}

View File

@ -497,6 +497,17 @@ t.isLet = function (node) {
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
};
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isBlockScoped = function (node) {
return t.isFunctionDeclaration(node) || t.isLet(node);
};
/**
* Description
*