Skip to content

Commit 7bb739f

Browse files
authored
Merge pull request #9083 from zhengbli/i6853
Check use before declaration if both the use and decalration are not in module file
2 parents 8c38cbf + 85ac67f commit 7bb739f

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ namespace ts {
562562
const declarationFile = getSourceFileOfNode(declaration);
563563
const useFile = getSourceFileOfNode(usage);
564564
if (declarationFile !== useFile) {
565-
if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) {
565+
if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
566+
(!compilerOptions.outFile && !compilerOptions.out)) {
566567
// nodes are in different files and order cannot be determines
567568
return true;
568569
}

src/services/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="..\compiler\program.ts"/>
2+
/// <reference path="..\compiler\commandLineParser.ts"/>
23

34
/// <reference path='breakpoints.ts' />
45
/// <reference path='outliningElementsCollector.ts' />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'c' used before its declaration.
2+
3+
4+
==== tests/cases/compiler/file1.ts (1 errors) ====
5+
6+
c;
7+
~
8+
!!! error TS2448: Block-scoped variable 'c' used before its declaration.
9+
10+
==== tests/cases/compiler/file2.ts (0 errors) ====
11+
const c = 0;

tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
2+
tests/cases/compiler/a.ts(2,1): error TS2448: Block-scoped variable 'a' used before its declaration.
23

34

45
!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
5-
==== tests/cases/compiler/a.ts (0 errors) ====
6+
==== tests/cases/compiler/a.ts (1 errors) ====
67
let b = 30;
78
a = 10;
9+
~
10+
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
811
==== tests/cases/compiler/b.js (0 errors) ====
912
let a = 10;
1013
b = 30;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'l' used before its declaration.
2+
3+
4+
==== tests/cases/compiler/file1.ts (1 errors) ====
5+
6+
l;
7+
~
8+
!!! error TS2448: Block-scoped variable 'l' used before its declaration.
9+
10+
==== tests/cases/compiler/file2.ts (0 errors) ====
11+
const l = 0;

0 commit comments

Comments
 (0)