Skip to content

Commit 02df499

Browse files
committed
Merge pull request #7034 from Microsoft/portCommonJSDefault
Port CommonJs as default module type, and adds default exclude values
2 parents 2d0b00f + 7d2ce0f commit 02df499

File tree

120 files changed

+1405
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+1405
-608
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.None;
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: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace ts {
7878
name: "module",
7979
shortName: "m",
8080
type: {
81+
"none": ModuleKind.None,
8182
"commonjs": ModuleKind.CommonJS,
8283
"amd": ModuleKind.AMD,
8384
"system": ModuleKind.System,
@@ -87,7 +88,7 @@ namespace ts {
8788
},
8889
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
8990
paramType: Diagnostics.KIND,
90-
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es2015
91+
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_es2015_or_none
9192
},
9293
{
9394
name: "newLine",
@@ -551,7 +552,21 @@ namespace ts {
551552
}
552553
else {
553554
const filesSeen: Map<boolean> = {};
554-
const exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
555+
556+
let exclude: string[] = [];
557+
if (json["exclude"] instanceof Array) {
558+
exclude = json["exclude"];
559+
}
560+
else {
561+
// by default exclude node_modules, and any specificied output directory
562+
exclude = ["node_modules"];
563+
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
564+
if (outDir) {
565+
exclude.push(outDir);
566+
}
567+
}
568+
exclude = map(exclude, normalizeSlashes);
569+
555570
const supportedExtensions = getSupportedExtensions(options);
556571
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick");
557572

@@ -565,6 +580,11 @@ namespace ts {
565580
continue;
566581
}
567582

583+
// Skip over any minified JavaScript files (ending in ".min.js")
584+
if (/\.min\.js$/.test(fileName)) {
585+
continue;
586+
}
587+
568588
// If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
569589
// do not include this file if we included .ts or .tsx file with same base name as it could be output of the earlier compilation
570590
if (extension === ".d.ts" || (options.allowJs && contains(supportedJavascriptExtensions, extension))) {
@@ -588,7 +608,6 @@ namespace ts {
588608
const errors: Diagnostic[] = [];
589609

590610
if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
591-
options.module = ModuleKind.CommonJS;
592611
options.allowJs = true;
593612
}
594613

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
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.": {
450+
"Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file.": {
451451
"category": "Error",
452452
"code": 1148
453453
},
@@ -2320,7 +2320,7 @@
23202320
"category": "Error",
23212321
"code": 6045
23222322
},
2323-
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es2015'.": {
2323+
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'none'.": {
23242324
"category": "Error",
23252325
"code": 6046
23262326
},

src/compiler/program.ts

Lines changed: 3 additions & 3 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,10 +1662,10 @@ 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);
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));
1668+
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file));
16691669
}
16701670

16711671
// Cannot specify module gen target of es6 when below es6

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ namespace ts {
376376
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
377377
return;
378378
}
379-
const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options);
379+
const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options, configFileName);
380380
if (configParseResult.errors.length > 0) {
381381
reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined);
382382
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,9 +2011,9 @@ namespace ts {
20112011
}
20122012

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

20192019
export interface EmitFileNames {

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.None,
17171716
jsx: JsxEmit.Preserve
17181717
};
17191718
}

tests/baselines/reference/ExportAssignment7.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
tests/cases/compiler/ExportAssignment7.ts(1,14): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
21
tests/cases/compiler/ExportAssignment7.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
32
tests/cases/compiler/ExportAssignment7.ts(4,10): error TS2304: Cannot find name 'B'.
43

54

6-
==== tests/cases/compiler/ExportAssignment7.ts (3 errors) ====
5+
==== tests/cases/compiler/ExportAssignment7.ts (2 errors) ====
76
export class C {
8-
~
9-
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
107
}
118

129
export = B;

tests/baselines/reference/ExportAssignment8.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
tests/cases/compiler/ExportAssignment8.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
21
tests/cases/compiler/ExportAssignment8.ts(1,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
32
tests/cases/compiler/ExportAssignment8.ts(1,10): error TS2304: Cannot find name 'B'.
43

54

6-
==== tests/cases/compiler/ExportAssignment8.ts (3 errors) ====
5+
==== tests/cases/compiler/ExportAssignment8.ts (2 errors) ====
76
export = B;
87
~~~~~~~~~~~
9-
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file.
10-
~~~~~~~~~~~
118
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
129
~
1310
!!! error TS2304: Cannot find name 'B'.

0 commit comments

Comments
 (0)