fix(15230): change the diagnostic message about a non-module file in an --isolatedModules project (#40032)

This commit is contained in:
Alexander T
2020-08-14 00:03:17 +03:00
committed by GitHub
parent 44d9ceaf14
commit edc88c51ca
11 changed files with 21 additions and 20 deletions

View File

@@ -659,7 +659,7 @@
"category": "Error",
"code": 1207
},
"All files must be modules when the '--isolatedModules' flag is provided.": {
"'{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.": {
"category": "Error",
"code": 1208
},

View File

@@ -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_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)));
}
}
else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) {

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== tests/cases/compiler/external.ts (0 errors) ====
@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
class B extends A { }
declare var dec: any;

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
!!! error TS5053: Option 'out' cannot be specified with option 'isolatedModules'.
@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
run(1);

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
run(1);

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
run(1);

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
run(1);

View File

@@ -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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
==== 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 under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
run(1);

View File

@@ -37,7 +37,7 @@ Output::
[12:00:23 AM] Starting compilation in watch mode...
a/b/globalFile3.ts:1:1 - error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
a/b/globalFile3.ts:1:1 - error TS1208: 'globalFile3.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.
1 interface GlobalFoo { age: number }
  ~~~~~~~~~
@@ -136,7 +136,7 @@ Output::
[12:00:38 AM] File change detected. Starting incremental compilation...
a/b/globalFile3.ts:1:1 - error TS1208: All files must be modules when the '--isolatedModules' flag is provided.
a/b/globalFile3.ts:1:1 - error TS1208: 'globalFile3.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.
1 interface GlobalFoo { age: number }
  ~~~~~~~~~