Skip to content

Commit 1173473

Browse files
committed
Merge pull request #7016 from Microsoft/CommonJSDefault
Make CommonJS the default (and some default "exclude" values).
2 parents 2d4bc0c + d446d06 commit 1173473

File tree

120 files changed

+1406
-605
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

+1406
-605
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",
@@ -525,7 +526,21 @@ namespace ts {
525526
}
526527
else {
527528
const filesSeen: Map<boolean> = {};
528-
const exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
529+
530+
let exclude: string[] = [];
531+
if (json["exclude"] instanceof Array) {
532+
exclude = json["exclude"];
533+
}
534+
else {
535+
// by default exclude node_modules, and any specificied output directory
536+
exclude = ["node_modules"];
537+
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
538+
if (outDir) {
539+
exclude.push(outDir);
540+
}
541+
}
542+
exclude = map(exclude, normalizeSlashes);
543+
529544
const supportedExtensions = getSupportedExtensions(options);
530545
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick");
531546

@@ -539,6 +554,11 @@ namespace ts {
539554
continue;
540555
}
541556

557+
// Skip over any minified JavaScript files (ending in ".min.js")
558+
if (/\.min\.js$/.test(fileName)) {
559+
continue;
560+
}
561+
542562
// If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
543563
// 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
544564
if (extension === ".d.ts" || (options.allowJs && contains(supportedJavascriptExtensions, extension))) {
@@ -562,7 +582,6 @@ namespace ts {
562582
const errors: Diagnostic[] = [];
563583

564584
if (configFileName && getBaseFileName(configFileName) === "jsconfig.json") {
565-
options.module = ModuleKind.CommonJS;
566585
options.allowJs = true;
567586
}
568587

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
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.": {
442+
"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.": {
443443
"category": "Error",
444444
"code": 1148
445445
},
@@ -2171,7 +2171,7 @@
21712171
"category": "Error",
21722172
"code": 5059
21732173
},
2174-
2174+
21752175

21762176
"Concatenate and emit output to single file.": {
21772177
"category": "Message",
@@ -2305,7 +2305,7 @@
23052305
"category": "Error",
23062306
"code": 6045
23072307
},
2308-
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es2015'.": {
2308+
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'none'.": {
23092309
"category": "Error",
23102310
"code": 6046
23112311
},

src/compiler/program.ts

Lines changed: 3 additions & 3 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,10 +1300,10 @@ 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);
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));
1306+
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));
13071307
}
13081308

13091309
// 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, getDirectoryPath(configFileName), commandLine.options);
379+
const configParseResult = parseJsonConfigFileContent(configObject, sys, getDirectoryPath(configFileName), 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
@@ -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.None,
17161715
jsx: JsxEmit.Preserve
17171716
};
17181717
}

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)