Skip to content

Commit 73fa45b

Browse files
committed
Added back errors for module kind none
1 parent fc5d94d commit 73fa45b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace ts {
4949

5050
const compilerOptions = host.getCompilerOptions();
5151
const languageVersion = compilerOptions.target || ScriptTarget.ES3;
52-
const modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
52+
const modulekind = typeof compilerOptions.module === "number" ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
5353
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
5454

5555
const emitResolver = createResolver();

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@
439439
"category": "Error",
440440
"code": 1147
441441
},
442+
"Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.": {
443+
"category": "Error",
444+
"code": 1148
445+
},
442446
"File name '{0}' differs from already included file name '{1}' only in casing": {
443447
"category": "Error",
444448
"code": 1149
@@ -2127,6 +2131,10 @@
21272131
"category": "Error",
21282132
"code": 5042
21292133
},
2134+
"Option 'isolatedModules' can only be used when either option '--module' is provided or option 'target' is 'ES2015' or higher.": {
2135+
"category": "Error",
2136+
"code": 5047
2137+
},
21302138
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
21312139
"category": "Error",
21322140
"code": 5051
@@ -2163,7 +2171,7 @@
21632171
"category": "Error",
21642172
"code": 5059
21652173
},
2166-
2174+
21672175

21682176
"Concatenate and emit output to single file.": {
21692177
"category": "Message",

src/compiler/program.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,13 +1288,23 @@ namespace ts {
12881288
const languageVersion = options.target || ScriptTarget.ES3;
12891289
const outFile = options.outFile || options.out;
12901290

1291+
const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
12911292
if (options.isolatedModules) {
1293+
if (!options.module && languageVersion < ScriptTarget.ES6) {
1294+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
1295+
}
1296+
12921297
const firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined);
12931298
if (firstNonExternalModuleSourceFile) {
12941299
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
12951300
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
12961301
}
12971302
}
1303+
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
1304+
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
1305+
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
1306+
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file));
1307+
}
12981308

12991309
// Cannot specify module gen target of es6 when below es6
13001310
if (options.module === ModuleKind.ES6 && languageVersion < ScriptTarget.ES6) {

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ namespace ts {
20112011
}
20122012

20132013
export function getEmitModuleKind(compilerOptions: CompilerOptions) {
2014-
return compilerOptions.module ?
2014+
return typeof compilerOptions.module === "number" ?
20152015
compilerOptions.module :
20162016
getEmitScriptTarget(compilerOptions) === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
20172017
}

0 commit comments

Comments
 (0)