Skip to content

Commit fd3a84c

Browse files
authoredSep 2, 2022
Report every instance of TS1208 (#50101)
* Report every instance of TS1208 * Test case for multiple cases of TS1208 * Add test case for isolatedModules with moduleDetection forced
1 parent 62f980a commit fd3a84c

10 files changed

+99
-5
lines changed
 

‎src/compiler/program.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -3535,11 +3535,12 @@ namespace ts {
35353535
createDiagnosticForOptionName(Diagnostics.Option_preserveConstEnums_cannot_be_disabled_when_isolatedModules_is_enabled, "preserveConstEnums", "isolatedModules");
35363536
}
35373537

3538-
const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !isSourceFileJS(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON);
3539-
if (firstNonExternalModuleSourceFile) {
3540-
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
3541-
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length,
3542-
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(firstNonExternalModuleSourceFile.fileName)));
3538+
for (const file of files) {
3539+
if (!isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON) {
3540+
const span = getErrorSpanForNode(file, file);
3541+
programDiagnostics.add(createFileDiagnostic(file, span.start, span.length,
3542+
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(file.fileName)));
3543+
}
35433544
}
35443545
}
35453546
else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [file1.ts]
2+
var x;
3+
4+
//// [file1.js]
5+
var x;
6+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
var x;
3+
>x : Symbol(x, Decl(file1.ts, 0, 3))
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
var x;
3+
>x : any
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/compiler/file1.ts(1,1): error TS1208: 'file1.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
2+
tests/cases/compiler/file2.ts(1,1): error TS1208: 'file2.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
3+
tests/cases/compiler/file3.ts(1,1): error TS1208: 'file3.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
4+
5+
6+
==== tests/cases/compiler/file1.ts (1 errors) ====
7+
var x;
8+
~~~
9+
!!! error TS1208: 'file1.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
10+
11+
==== tests/cases/compiler/file2.ts (1 errors) ====
12+
var y;
13+
~~~
14+
!!! error TS1208: 'file2.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
15+
16+
==== tests/cases/compiler/file3.ts (1 errors) ====
17+
var z;
18+
~~~
19+
!!! error TS1208: 'file3.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/isolatedModulesNoExternalModuleMultiple.ts] ////
2+
3+
//// [file1.ts]
4+
var x;
5+
6+
//// [file2.ts]
7+
var y;
8+
9+
//// [file3.ts]
10+
var z;
11+
12+
13+
//// [file1.js]
14+
var x;
15+
//// [file2.js]
16+
var y;
17+
//// [file3.js]
18+
var z;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
var x;
3+
>x : Symbol(x, Decl(file1.ts, 0, 3))
4+
5+
=== tests/cases/compiler/file2.ts ===
6+
var y;
7+
>y : Symbol(y, Decl(file2.ts, 0, 3))
8+
9+
=== tests/cases/compiler/file3.ts ===
10+
var z;
11+
>z : Symbol(z, Decl(file3.ts, 0, 3))
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
var x;
3+
>x : any
4+
5+
=== tests/cases/compiler/file2.ts ===
6+
var y;
7+
>y : any
8+
9+
=== tests/cases/compiler/file3.ts ===
10+
var z;
11+
>z : any
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @isolatedModules: true
2+
// @target: es6
3+
// @moduleDetection: force
4+
5+
// @filename: file1.ts
6+
var x;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @isolatedModules: true
2+
// @target: es6
3+
4+
// @filename: file1.ts
5+
var x;
6+
7+
// @filename: file2.ts
8+
var y;
9+
10+
// @filename: file3.ts
11+
var z;

0 commit comments

Comments
 (0)
Please sign in to comment.