Skip to content

Commit f9e6298

Browse files
committed
Add module: es2022
Closes #44653
1 parent 580bb06 commit f9e6298

File tree

157 files changed

+2204
-134
lines changed

Some content is hidden

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

157 files changed

+2204
-134
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30338,8 +30338,8 @@ namespace ts {
3033830338
}
3033930339

3034030340
function checkImportMetaProperty(node: MetaProperty) {
30341-
if (moduleKind !== ModuleKind.ES2020 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
30342-
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_or_system);
30341+
if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System) {
30342+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_or_system);
3034330343
}
3034430344
const file = getSourceFileOfNode(node);
3034530345
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
@@ -31306,10 +31306,10 @@ namespace ts {
3130631306
Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module);
3130731307
diagnostics.add(diagnostic);
3130831308
}
31309-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
31309+
if ((moduleKind < ModuleKind.ES2022 && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
3131031310
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
3131131311
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
31312-
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher);
31312+
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher);
3131331313
diagnostics.add(diagnostic);
3131431314
}
3131531315
}
@@ -41642,9 +41642,9 @@ namespace ts {
4164241642
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
4164341643
Diagnostics.for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module));
4164441644
}
41645-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
41645+
if ((moduleKind < ModuleKind.ES2022 && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
4164641646
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
41647-
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher));
41647+
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher));
4164841648
}
4164941649
}
4165041650
}
@@ -42394,7 +42394,7 @@ namespace ts {
4239442394

4239542395
function checkGrammarImportCallExpression(node: ImportCall): boolean {
4239642396
if (moduleKind === ModuleKind.ES2015) {
42397-
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd);
42397+
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_or_umd);
4239842398
}
4239942399

4240042400
if (node.typeArguments) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ namespace ts {
393393
es6: ModuleKind.ES2015,
394394
es2015: ModuleKind.ES2015,
395395
es2020: ModuleKind.ES2020,
396+
es2022: ModuleKind.ES2022,
396397
esnext: ModuleKind.ESNext
397398
})),
398399
affectsModuleResolution: true,

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@
944944
"category": "Error",
945945
"code": 1322
946946
},
947-
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
947+
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
948948
"category": "Error",
949949
"code": 1323
950950
},
@@ -1020,7 +1020,7 @@
10201020
"category": "Error",
10211021
"code": 1342
10221022
},
1023-
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.": {
1023+
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', or 'system'.": {
10241024
"category": "Error",
10251025
"code": 1343
10261026
},
@@ -1148,7 +1148,7 @@
11481148
"category": "Message",
11491149
"code": 1377
11501150
},
1151-
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.": {
1151+
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', or 'system', and the 'target' option is set to 'es2017' or higher.": {
11521152
"category": "Error",
11531153
"code": 1378
11541154
},
@@ -1364,7 +1364,7 @@
13641364
"category": "Error",
13651365
"code": 1431
13661366
},
1367-
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.": {
1367+
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', or 'system', and the 'target' option is set to 'es2017' or higher.": {
13681368
"category": "Error",
13691369
"code": 1432
13701370
},
@@ -5637,7 +5637,7 @@
56375637
"category": "Message",
56385638
"code": 6803
56395639
},
5640-
5640+
56415641
"one of:": {
56425642
"category": "Message",
56435643
"code": 6900

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.ES2022:
67
case ModuleKind.ES2020:
78
case ModuleKind.ES2015:
89
return transformECMAScriptModule;

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,9 +2517,7 @@ namespace ts {
25172517
function hasNamespaceQualifiedExportName(node: Node) {
25182518
return isExportOfNamespace(node)
25192519
|| (isExternalModuleExport(node)
2520-
&& moduleKind !== ModuleKind.ES2015
2521-
&& moduleKind !== ModuleKind.ES2020
2522-
&& moduleKind !== ModuleKind.ESNext
2520+
&& moduleKind < ModuleKind.ES2015
25232521
&& moduleKind !== ModuleKind.System);
25242522
}
25252523

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6103,6 +6103,7 @@ namespace ts {
61036103
// module kind).
61046104
ES2015 = 5,
61056105
ES2020 = 6,
6106+
ES2022 = 7,
61066107
ESNext = 99
61076108
}
61086109

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6052,6 +6052,7 @@ namespace ts {
60526052
case ModuleKind.AMD:
60536053
case ModuleKind.ES2015:
60546054
case ModuleKind.ES2020:
6055+
case ModuleKind.ES2022:
60556056
case ModuleKind.ESNext:
60566057
return true;
60576058
default:

src/services/codefixes/fixModuleAndTargetOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace ts.codefix {
33
registerCodeFix({
44
errorCodes: [
5-
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
6-
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
5+
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
6+
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher.code,
77
],
88
getCodeActions: context => {
99
const compilerOptions = context.program.getCompilerOptions();

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ namespace ts.codefix {
603603
case ModuleKind.System:
604604
case ModuleKind.ES2015:
605605
case ModuleKind.ES2020:
606+
case ModuleKind.ES2022:
606607
case ModuleKind.ESNext:
607608
case ModuleKind.None:
608609
// 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
@@ -159,7 +159,7 @@ namespace ts {
159159
start: undefined,
160160
length: undefined,
161161
}, {
162-
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'.",
162+
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext'.",
163163
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
164164
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
165165

0 commit comments

Comments
 (0)