Skip to content

Commit a370103

Browse files
committed
Added back errors for module kind none
(cherry picked from commit 73fa45b)
1 parent ece7786 commit a370103

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@
447447
"category": "Error",
448448
"code": 1147
449449
},
450+
"Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.": {
451+
"category": "Error",
452+
"code": 1148
453+
},
450454
"File name '{0}' differs from already included file name '{1}' only in casing": {
451455
"category": "Error",
452456
"code": 1149
@@ -2131,6 +2135,10 @@
21312135
"category": "Error",
21322136
"code": 5042
21332137
},
2138+
"Option 'isolatedModules' can only be used when either option '--module' is provided or option 'target' is 'ES2015' or higher.": {
2139+
"category": "Error",
2140+
"code": 5047
2141+
},
21342142
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
21352143
"category": "Error",
21362144
"code": 5051

src/compiler/program.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,12 +1652,21 @@ namespace ts {
16521652

16531653
const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
16541654
if (options.isolatedModules) {
1655+
if (!options.module && languageVersion < ScriptTarget.ES6) {
1656+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
1657+
}
1658+
16551659
const firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined);
16561660
if (firstNonExternalModuleSourceFile) {
16571661
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
16581662
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
16591663
}
16601664
}
1665+
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
1666+
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
1667+
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
1668+
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));
1669+
}
16611670

16621671
// Cannot specify module gen target of es6 when below es6
16631672
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)