Skip to content

Commit d4655b1

Browse files
committed
Add module: es2022
Closes #44653
1 parent d518bdb commit d4655b1

File tree

163 files changed

+2250
-179
lines changed

Some content is hidden

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

163 files changed

+2250
-179
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30987,16 +30987,14 @@ namespace ts {
3098730987
}
3098830988

3098930989
function checkImportMetaProperty(node: MetaProperty) {
30990-
if (moduleKind !== ModuleKind.ES2020 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
30991-
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
30992-
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
30993-
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
30994-
}
30995-
}
30996-
else {
30997-
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_system_node12_or_nodenext);
30990+
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
30991+
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
30992+
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
3099830993
}
3099930994
}
30995+
else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System) {
30996+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
30997+
}
3100030998
const file = getSourceFileOfNode(node);
3100130999
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
3100231000
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
@@ -32018,10 +32016,10 @@ namespace ts {
3201832016
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);
3201932017
diagnostics.add(diagnostic);
3202032018
}
32021-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
32019+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
3202232020
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
3202332021
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
32024-
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
32022+
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
3202532023
diagnostics.add(diagnostic);
3202632024
}
3202732025
}
@@ -42680,9 +42678,9 @@ namespace ts {
4268042678
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
4268142679
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));
4268242680
}
42683-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
42681+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
4268442682
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
42685-
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher));
42683+
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher));
4268642684
}
4268742685
}
4268842686
}
@@ -43431,7 +43429,7 @@ namespace ts {
4343143429

4343243430
function checkGrammarImportCallExpression(node: ImportCall): boolean {
4343343431
if (moduleKind === ModuleKind.ES2015) {
43434-
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_umd_node12_or_nodenext);
43432+
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node12_or_nodenext);
4343543433
}
4343643434

4343743435
if (node.typeArguments) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ namespace ts {
394394
es6: ModuleKind.ES2015,
395395
es2015: ModuleKind.ES2015,
396396
es2020: ModuleKind.ES2020,
397+
es2022: ModuleKind.ES2022,
397398
esnext: ModuleKind.ESNext,
398399
node12: ModuleKind.Node12,
399400
nodenext: ModuleKind.NodeNext,

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@
920920
"category": "Error",
921921
"code": 1322
922922
},
923-
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'.": {
923+
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'.": {
924924
"category": "Error",
925925
"code": 1323
926926
},
@@ -992,7 +992,7 @@
992992
"category": "Error",
993993
"code": 1342
994994
},
995-
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', 'system', 'node12', or 'nodenext'.": {
995+
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.": {
996996
"category": "Error",
997997
"code": 1343
998998
},
@@ -1116,7 +1116,7 @@
11161116
"category": "Message",
11171117
"code": 1377
11181118
},
1119-
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
1119+
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
11201120
"category": "Error",
11211121
"code": 1378
11221122
},
@@ -1324,7 +1324,7 @@
13241324
"category": "Error",
13251325
"code": 1431
13261326
},
1327-
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
1327+
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
13281328
"category": "Error",
13291329
"code": 1432
13301330
},

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,7 @@ namespace ts {
25072507
|| (isExternalModuleExport(node)
25082508
&& moduleKind !== ModuleKind.ES2015
25092509
&& moduleKind !== ModuleKind.ES2020
2510+
&& moduleKind !== ModuleKind.ES2022
25102511
&& moduleKind !== ModuleKind.ESNext
25112512
&& moduleKind !== ModuleKind.System);
25122513
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6189,6 +6189,7 @@ namespace ts {
61896189
// module kind).
61906190
ES2015 = 5,
61916191
ES2020 = 6,
6192+
ES2022 = 7,
61926193
ESNext = 99,
61936194

61946195
// Node12+ is an amalgam of commonjs (albeit updated) and es2020+, and represents a distinct module system from es2020/esnext

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6166,6 +6166,7 @@ namespace ts {
61666166
case ModuleKind.AMD:
61676167
case ModuleKind.ES2015:
61686168
case ModuleKind.ES2020:
6169+
case ModuleKind.ES2022:
61696170
case ModuleKind.ESNext:
61706171
return true;
61716172
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_system_or_nodenext_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_system_or_nodenext_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_system_or_nodenext_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_system_or_nodenext_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
@@ -593,6 +593,7 @@ namespace ts.codefix {
593593
case ModuleKind.System:
594594
case ModuleKind.ES2015:
595595
case ModuleKind.ES2020:
596+
case ModuleKind.ES2022:
596597
case ModuleKind.ESNext:
597598
case ModuleKind.None:
598599
// 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', 'node12', 'nodenext'.",
162+
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node12', 'nodenext'.",
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)