ignore function declarations in TDZ detection
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user