Skip to content

Commit 4a67dc5

Browse files
committed
Dont default to CommonJS modules for ES6 target
1 parent 73fa45b commit 4a67dc5

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
@@ -580,7 +580,6 @@ namespace ts {
580580
const options: CompilerOptions = {};
581581
const errors: Diagnostic[] = [];
582582

583-
options.module = ModuleKind.CommonJS;
584583
if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
585584
options.allowJs = true;
586585
}

src/compiler/program.ts

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

12911291
const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
12921292
if (options.isolatedModules) {
1293-
if (!options.module && languageVersion < ScriptTarget.ES6) {
1293+
if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES6) {
12941294
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
12951295
}
12961296

@@ -1300,7 +1300,7 @@ namespace ts {
13001300
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
13011301
}
13021302
}
1303-
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
1303+
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) {
13041304
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
13051305
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
13061306
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
@@ -974,7 +974,6 @@ namespace Harness {
974974

975975
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.clone(compilerOptions) : { noResolve: false };
976976
options.target = options.target || ts.ScriptTarget.ES3;
977-
options.module = options.module || ts.ModuleKind.None;
978977
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
979978
options.noErrorTruncation = true;
980979
options.skipDefaultLibCheck = true;

src/services/services.ts

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

0 commit comments

Comments
 (0)