Skip to content

Commit

Permalink
fix(15230): change the diagnostic message about a non-module file in …
Browse files Browse the repository at this point in the history
…an --isolatedModules project
  • Loading branch information
a-tarasyuk committed Aug 13, 2020
1 parent 610fa28 commit 2838326
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
"category": "Error",
"code": 1207
},
"All files must be modules when the '--isolatedModules' flag is provided.": {
"'{0}' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.": {
"category": "Error",
"code": 1208
},
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3110,7 +3110,8 @@ namespace ts {
const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !isSourceFileJS(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON);
if (firstNonExternalModuleSourceFile) {
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.All_files_must_be_modules_when_the_isolatedModules_flag_is_provided));
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length,
Diagnostics._0_cannot_be_compiled_using_isolatedModules_because_it_is_global_Ensure_that_it_contains_an_import_export_or_an_empty_export_statement, getBaseFileName(firstNonExternalModuleSourceFile.fileName)));
}
}
else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/script.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/script.ts(1,1): error TS1208: 'script.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/external.ts (0 errors) ====
Expand All @@ -16,7 +16,7 @@ tests/cases/compiler/script.ts(1,1): error TS1208: All files must be modules whe
==== tests/cases/compiler/script.ts (1 errors) ====
class A { }
~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'script.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
class B extends A { }

declare var dec: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/file1.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/file1.ts(1,1): error TS1208: 'file1.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/file1.ts (1 errors) ====
var x;
~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'file1.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
4 changes: 2 additions & 2 deletions tests/baselines/reference/isolatedModulesOut.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error TS5053: Option 'out' cannot be specified with option 'isolatedModules'.
tests/cases/compiler/file1.ts(1,1): error TS6131: Cannot compile modules using option 'out' unless the '--module' flag is 'amd' or 'system'.
tests/cases/compiler/file2.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/file2.ts(1,1): error TS1208: 'file2.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


!!! error TS5053: Option 'out' cannot be specified with option 'isolatedModules'.
Expand All @@ -11,4 +11,4 @@ tests/cases/compiler/file2.ts(1,1): error TS1208: All files must be modules when
==== tests/cases/compiler/file2.ts (1 errors) ====
var y;
~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'file2.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: 'isolatedModulesPlainFile-AMD.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/isolatedModulesPlainFile-AMD.ts (1 errors) ====
declare function run(a: number): void;
~~~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'isolatedModulesPlainFile-AMD.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
run(1);

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: 'isolatedModulesPlainFile-CommonJS.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts (1 errors) ====
declare function run(a: number): void;
~~~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'isolatedModulesPlainFile-CommonJS.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
run(1);

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: 'isolatedModulesPlainFile-ES6.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/isolatedModulesPlainFile-ES6.ts (1 errors) ====
declare function run(a: number): void;
~~~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'isolatedModulesPlainFile-ES6.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
run(1);

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: 'isolatedModulesPlainFile-System.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/isolatedModulesPlainFile-System.ts (1 errors) ====
declare function run(a: number): void;
~~~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'isolatedModulesPlainFile-System.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
run(1);

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: 'isolatedModulesPlainFile-UMD.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.


==== tests/cases/compiler/isolatedModulesPlainFile-UMD.ts (1 errors) ====
declare function run(a: number): void;
~~~~~~~
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
!!! error TS1208: 'isolatedModulesPlainFile-UMD.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.
run(1);

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Output::
[12:00:23 AM] Starting compilation in watch mode...


[96ma/b/globalFile3.ts[0m:[93m1[0m:[93m1[0m - [91merror[0m[90m TS1208: [0mAll files must be modules when the '--isolatedModules' flag is provided.
[96ma/b/globalFile3.ts[0m:[93m1[0m:[93m1[0m - [91merror[0m[90m TS1208: [0m'globalFile3.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.

1 interface GlobalFoo { age: number }
  ~~~~~~~~~
Expand Down Expand Up @@ -136,7 +136,7 @@ Output::
[12:00:38 AM] File change detected. Starting incremental compilation...


[96ma/b/globalFile3.ts[0m:[93m1[0m:[93m1[0m - [91merror[0m[90m TS1208: [0mAll files must be modules when the '--isolatedModules' flag is provided.
[96ma/b/globalFile3.ts[0m:[93m1[0m:[93m1[0m - [91merror[0m[90m TS1208: [0m'globalFile3.ts' cannot be compiled using '--isolatedModules' because it is global. Ensure that it contains an import, export, or an empty 'export {}' statement.

1 interface GlobalFoo { age: number }
  ~~~~~~~~~
Expand Down

0 comments on commit 2838326

Please sign in to comment.