Skip to content

Commit bdfb7a2

Browse files
committed
Use function like to determine if it is in different scope
1 parent a7f85d5 commit bdfb7a2

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,14 @@ namespace ts {
398398
}
399399

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

403403
function isInSameLexicalScope() {
404404
let referenceDeclarationScope = getEnclosingBlockScopeContainer(referenceDeclaration);
405405
let locationNodeScope = getEnclosingBlockScopeContainer(locationNode);
406406

407407
while (locationNodeScope && referenceDeclarationScope !== locationNodeScope) {
408-
switch (locationNodeScope.kind) {
409-
// In function like scope
410-
case SyntaxKind.FunctionExpression:
411-
case SyntaxKind.FunctionDeclaration:
412-
case SyntaxKind.ArrowFunction:
408+
if (isFunctionLike(locationNodeScope)) {
413409
return false;
414410
}
415411

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [letUsedInClassMethodOutOfOrder.ts]
2+
class c {
3+
method1() {
4+
a; // shouldnt error
5+
}
6+
}
7+
8+
let a = 10;
9+
10+
//// [letUsedInClassMethodOutOfOrder.js]
11+
var c = (function () {
12+
function c() {
13+
}
14+
c.prototype.method1 = function () {
15+
a; // shouldnt error
16+
};
17+
return c;
18+
})();
19+
var a = 10;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/letUsedInClassMethodOutOfOrder.ts ===
2+
class c {
3+
>c : Symbol(c, Decl(letUsedInClassMethodOutOfOrder.ts, 0, 0))
4+
5+
method1() {
6+
>method1 : Symbol(method1, Decl(letUsedInClassMethodOutOfOrder.ts, 0, 9))
7+
8+
a; // shouldnt error
9+
>a : Symbol(a, Decl(letUsedInClassMethodOutOfOrder.ts, 6, 3))
10+
}
11+
}
12+
13+
let a = 10;
14+
>a : Symbol(a, Decl(letUsedInClassMethodOutOfOrder.ts, 6, 3))
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/letUsedInClassMethodOutOfOrder.ts ===
2+
class c {
3+
>c : c
4+
5+
method1() {
6+
>method1 : () => void
7+
8+
a; // shouldnt error
9+
>a : number
10+
}
11+
}
12+
13+
let a = 10;
14+
>a : number
15+
>10 : number
16+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class c {
2+
method1() {
3+
a; // shouldnt error
4+
}
5+
}
6+
7+
let a = 10;

0 commit comments

Comments
 (0)