Skip to content

Commit deb5288

Browse files
saschanazDanielRosenwasser
authored andcommitted
Add module: es2020 (#33893)
1 parent 4c7844b commit deb5288

File tree

70 files changed

+127
-92
lines changed

Some content is hidden

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

70 files changed

+127
-92
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31598,7 +31598,7 @@ namespace ts {
3159831598
*/
3159931599
function checkClassNameCollisionWithObject(name: Identifier): void {
3160031600
if (languageVersion === ScriptTarget.ES5 && name.escapedText === "Object"
31601-
&& moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
31601+
&& moduleKind < ModuleKind.ES2015) {
3160231602
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
3160331603
}
3160431604
}
@@ -32763,7 +32763,7 @@ namespace ts {
3276332763
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
3276432764
}
3276532765

32766-
if (moduleKind !== ModuleKind.System && moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
32766+
if (moduleKind !== ModuleKind.System && moduleKind < ModuleKind.ES2015) {
3276732767
checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar);
3276832768
}
3276932769
}
@@ -35977,7 +35977,9 @@ namespace ts {
3597735977
return grammarErrorOnNode(node.exclamationToken, Diagnostics.Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation);
3597835978
}
3597935979

35980-
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&
35980+
const moduleKind = getEmitModuleKind(compilerOptions);
35981+
35982+
if (moduleKind < ModuleKind.ES2015 && moduleKind !== ModuleKind.System && !compilerOptions.noEmit &&
3598135983
!(node.parent.parent.flags & NodeFlags.Ambient) && hasModifier(node.parent.parent, ModifierFlags.Export)) {
3598235984
checkESModuleMarker(node.name);
3598335985
}
@@ -36323,7 +36325,7 @@ namespace ts {
3632336325

3632436326
function checkGrammarImportCallExpression(node: ImportCall): boolean {
3632536327
if (moduleKind === ModuleKind.ES2015) {
36326-
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_commonjs_amd_system_or_umd);
36328+
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd);
3632736329
}
3632836330

3632936331
if (node.typeArguments) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ namespace ts {
304304
umd: ModuleKind.UMD,
305305
es6: ModuleKind.ES2015,
306306
es2015: ModuleKind.ES2015,
307+
es2020: ModuleKind.ES2020,
307308
esnext: ModuleKind.ESNext
308309
}),
309310
affectsModuleResolution: true,

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@
911911
"category": "Error",
912912
"code": 1322
913913
},
914-
"Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
914+
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
915915
"category": "Error",
916916
"code": 1323
917917
},

src/compiler/factory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,7 @@ namespace ts {
15091509
const moduleKind = getEmitModuleKind(compilerOptions);
15101510
let create = (hasExportStarsToExportValues || (compilerOptions.esModuleInterop && hasImportStarOrImportDefault))
15111511
&& moduleKind !== ModuleKind.System
1512-
&& moduleKind !== ModuleKind.ES2015
1513-
&& moduleKind !== ModuleKind.ESNext;
1512+
&& moduleKind < ModuleKind.ES2015;
15141513
if (!create) {
15151514
const helpers = getEmitHelpers(node);
15161515
if (helpers) {

src/compiler/transformer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace ts {
33
function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory<SourceFile | Bundle> {
44
switch (moduleKind) {
55
case ModuleKind.ESNext:
6+
case ModuleKind.ES2020:
67
case ModuleKind.ES2015:
78
return transformECMAScriptModule;
89
case ModuleKind.System:

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,7 @@ namespace ts {
24732473
return isExportOfNamespace(node)
24742474
|| (isExternalModuleExport(node)
24752475
&& moduleKind !== ModuleKind.ES2015
2476+
&& moduleKind !== ModuleKind.ES2020
24762477
&& moduleKind !== ModuleKind.ESNext
24772478
&& moduleKind !== ModuleKind.System);
24782479
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5125,6 +5125,7 @@ namespace ts {
51255125
// Non-ES module kinds should not come between ES2015 (the earliest ES module kind) and ESNext (the last ES
51265126
// module kind).
51275127
ES2015 = 5,
5128+
ES2020 = 6,
51285129
ESNext = 99
51295130
}
51305131

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,6 +5184,7 @@ namespace ts {
51845184
case ModuleKind.CommonJS:
51855185
case ModuleKind.AMD:
51865186
case ModuleKind.ES2015:
5187+
case ModuleKind.ES2020:
51875188
case ModuleKind.ESNext:
51885189
return true;
51895190
default:

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ namespace ts.codefix {
378378
return ImportKind.Equals;
379379
case ModuleKind.System:
380380
case ModuleKind.ES2015:
381+
case ModuleKind.ES2020:
381382
case ModuleKind.ESNext:
382383
case ModuleKind.None:
383384
// Fall back to the `import * as ns` style import.

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace ts {
137137
start: undefined,
138138
length: undefined,
139139
}, {
140-
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.",
140+
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'.",
141141
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
142142
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
143143

0 commit comments

Comments
 (0)