In resolveNameHelper, use a lastNonBlockLocation (#18918)

This commit is contained in:
Andy
2017-10-09 11:04:28 -07:00
committed by GitHub
parent 8a55baf9a3
commit 2796ebfe35
6 changed files with 77 additions and 32 deletions

View File

@@ -908,6 +908,7 @@ namespace ts {
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
let result: Symbol;
let lastLocation: Node;
let lastNonBlockLocation: Node;
let propertyWithInvalidInitializer: Node;
const errorLocation = location;
let grandparent: Node;
@@ -1126,6 +1127,9 @@ namespace ts {
}
break;
}
if (location.kind !== SyntaxKind.Block) {
lastNonBlockLocation = location;
}
lastLocation = location;
location = location.parent;
}
@@ -1133,7 +1137,7 @@ namespace ts {
// We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
// If `result === lastLocation.symbol`, that means that we are somewhere inside `lastLocation` looking up a name, and resolving to `lastLocation` itself.
// That means that this is a self-reference of `lastLocation`, and shouldn't count this when considering whether `lastLocation` is used.
if (isUse && result && nameNotFoundMessage && noUnusedIdentifiers && result !== lastLocation.symbol) {
if (isUse && result && nameNotFoundMessage && noUnusedIdentifiers && result !== lastNonBlockLocation.symbol) {
result.isReferenced = true;
}