ignore function declarations in TDZ detection

This commit is contained in:
Sebastian McKenzie
2015-01-18 21:33:22 +11:00
parent 6a884c58a7
commit a80945cfb4
2 changed files with 10 additions and 5 deletions

View File

@@ -130,16 +130,18 @@ LetScoping.prototype.checkTDZ = function () {
// declared node is different in this scope
if (scope.get(node.name, true) !== declared) return;
var declaredLoc = declared.loc.start;
var referenceLoc = node.loc.start;
var declaredLoc = declared.loc;
var referenceLoc = node.loc;
if (!declaredLoc || !referenceLoc) return;
// does this reference appear on a line before the declaration?
var before = referenceLoc.line < declaredLoc.line;
var before = referenceLoc.start.line < declaredLoc.start.line;
if (referenceLoc.line === declaredLoc.line) {
if (referenceLoc.start.line === declaredLoc.start.line) {
// this reference appears on the same line
// check it appears before the declaration
before = referenceLoc.col < declaredLoc.col;
before = referenceLoc.start.col < declaredLoc.start.col;
}
if (before) {

View File

@@ -7,6 +7,9 @@ exports.FunctionDeclaration = function (node, parent) {
return;
}
// this is to avoid triggering the TDZ detection
node.id.loc = null;
var declar = t.variableDeclaration("let", [
t.variableDeclarator(node.id, t.toExpression(node))
]);