Skip to content

Commit ad1d8da

Browse files
committed
Took more code review feedback into account
1 parent bdfb7a2 commit ad1d8da

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,29 +390,18 @@ namespace ts {
390390
let referenceDeclarationFile = getSourceFileOfNode(referenceDeclaration);
391391
let locationNodeFile = getSourceFileOfNode(locationNode);
392392
if (referenceDeclarationFile === locationNodeFile) {
393-
return referenceDeclaration.pos <= locationNode.pos || !isInSameLexicalScope();
393+
return referenceDeclaration.pos <= locationNode.pos || !isInSameContainingFunction();
394394
}
395395

396396
if (!compilerOptions.outFile && !compilerOptions.out) {
397397
return true;
398398
}
399399

400400
let sourceFiles = host.getSourceFiles();
401-
return indexOf(sourceFiles, referenceDeclarationFile) <= indexOf(sourceFiles, locationNodeFile) || !isInSameLexicalScope();
401+
return indexOf(sourceFiles, referenceDeclarationFile) <= indexOf(sourceFiles, locationNodeFile) || !isInSameContainingFunction();
402402

403-
function isInSameLexicalScope() {
404-
let referenceDeclarationScope = getEnclosingBlockScopeContainer(referenceDeclaration);
405-
let locationNodeScope = getEnclosingBlockScopeContainer(locationNode);
406-
407-
while (locationNodeScope && referenceDeclarationScope !== locationNodeScope) {
408-
if (isFunctionLike(locationNodeScope)) {
409-
return false;
410-
}
411-
412-
locationNodeScope = getEnclosingBlockScopeContainer(locationNodeScope);
413-
}
414-
415-
return true;
403+
function isInSameContainingFunction() {
404+
return getContainingFunction(referenceDeclaration) === getContainingFunction(locationNode);
416405
}
417406
}
418407

0 commit comments

Comments
 (0)