From 774cb66d9bdd0e6d74c43a280da0a06c5ab1691c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 18 Jan 2015 18:23:37 +1100 Subject: [PATCH] add isBlockedScoped types helper --- lib/6to5/traverse/scope.js | 6 +++--- lib/6to5/types/index.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index c77c75dcb3..e532848246 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -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); } } diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 85c89cb427..ff8af91e5e 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -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 *