Skip to content

Commit 6a8ccd0

Browse files
committed
Dont default to CommonJS modules for ES6 target
(cherry picked from commit 4a67dc5)
1 parent a370103 commit 6a8ccd0

File tree

5 files changed

+3
-6
lines changed

5 files changed

+3
-6
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 = typeof compilerOptions.module === "number" ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
52+
const modulekind = getEmitModuleKind(compilerOptions);
5353
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
5454

5555
const emitResolver = createResolver();

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ namespace ts {
606606
const options: CompilerOptions = {};
607607
const errors: Diagnostic[] = [];
608608

609-
options.module = ModuleKind.CommonJS;
610609
if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
611610
options.allowJs = true;
612611
}

src/compiler/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ namespace ts {
16521652

16531653
const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
16541654
if (options.isolatedModules) {
1655-
if (!options.module && languageVersion < ScriptTarget.ES6) {
1655+
if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES6) {
16561656
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
16571657
}
16581658

@@ -1662,7 +1662,7 @@ namespace ts {
16621662
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
16631663
}
16641664
}
1665-
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
1665+
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) {
16661666
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
16671667
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
16681668
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));

src/harness/harness.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ namespace Harness {
966966

967967
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.clone(compilerOptions) : { noResolve: false };
968968
options.target = options.target || ts.ScriptTarget.ES3;
969-
options.module = options.module || ts.ModuleKind.None;
970969
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
971970
options.noErrorTruncation = true;
972971
options.skipDefaultLibCheck = true;

src/services/services.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,6 @@ namespace ts {
17131713
// Always default to "ScriptTarget.ES5" for the language service
17141714
return {
17151715
target: ScriptTarget.ES5,
1716-
module: ModuleKind.CommonJS,
17171716
jsx: JsxEmit.Preserve
17181717
};
17191718
}

0 commit comments

Comments
 (0)