Skip to content

Commit 2161e18

Browse files
authored
Add module: es2022 (#44656)
Closes #44653
1 parent 5ec836d commit 2161e18

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

+11-13
Original file line numberDiff line numberDiff line change
@@ -31110,16 +31110,14 @@ namespace ts {
3111031110
}
3111131111

3111231112
function checkImportMetaProperty(node: MetaProperty) {
31113-
if (moduleKind !== ModuleKind.ES2020 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
31114-
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
31115-
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
31116-
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
31117-
}
31118-
}
31119-
else {
31120-
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_system_node12_or_nodenext);
31113+
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
31114+
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
31115+
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
3112131116
}
3112231117
}
31118+
else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System) {
31119+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
31120+
}
3112331121
const file = getSourceFileOfNode(node);
3112431122
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
3112531123
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
@@ -32141,10 +32139,10 @@ namespace ts {
3214132139
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);
3214232140
diagnostics.add(diagnostic);
3214332141
}
32144-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
32142+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
3214532143
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
3214632144
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
32147-
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);
32145+
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);
3214832146
diagnostics.add(diagnostic);
3214932147
}
3215032148
}
@@ -42807,9 +42805,9 @@ namespace ts {
4280742805
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
4280842806
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));
4280942807
}
42810-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
42808+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
4281142809
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
42812-
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));
42810+
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));
4281342811
}
4281442812
}
4281542813
}
@@ -43573,7 +43571,7 @@ namespace ts {
4357343571

4357443572
function checkGrammarImportCallExpression(node: ImportCall): boolean {
4357543573
if (moduleKind === ModuleKind.ES2015) {
43576-
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);
43574+
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);
4357743575
}
4357843576

4357943577
if (node.typeArguments) {

src/compiler/commandLineParser.ts

+1
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

+4-4
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

+1
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

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -6192,6 +6192,7 @@ namespace ts {
61926192
// module kind).
61936193
ES2015 = 5,
61946194
ES2020 = 6,
6195+
ES2022 = 7,
61956196
ESNext = 99,
61966197

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

src/compiler/utilities.ts

+1
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

+2-2
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

+1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ namespace ts.codefix {
738738
case ModuleKind.System:
739739
case ModuleKind.ES2015:
740740
case ModuleKind.ES2020:
741+
case ModuleKind.ES2022:
741742
case ModuleKind.ESNext:
742743
case ModuleKind.None:
743744
// Fall back to the `import * as ns` style import.

src/testRunner/unittests/config/commandLineParsing.ts

+1-1
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

src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace ts {
184184
file: undefined,
185185
start: 0,
186186
length: 0,
187-
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.",
187+
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext'.",
188188
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
189189
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
190190
}]

tests/baselines/reference/api/tsserverlibrary.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3025,6 +3025,7 @@ declare namespace ts {
30253025
System = 4,
30263026
ES2015 = 5,
30273027
ES2020 = 6,
3028+
ES2022 = 7,
30283029
ESNext = 99,
30293030
Node12 = 100,
30303031
NodeNext = 199

tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3025,6 +3025,7 @@ declare namespace ts {
30253025
System = 4,
30263026
ES2015 = 5,
30273027
ES2020 = 6,
3028+
ES2022 = 7,
30283029
ESNext = 99,
30293030
Node12 = 100,
30303031
NodeNext = 199

tests/baselines/reference/awaitInNonAsyncFunction.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: 'for await'
1212
tests/cases/compiler/awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
1313
tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules.
1414
tests/cases/compiler/awaitInNonAsyncFunction.ts(35,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
15-
tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1432: 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.
16-
tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: 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.
15+
tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1432: 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.
16+
tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: 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.
1717

1818

1919
==== tests/cases/compiler/awaitInNonAsyncFunction.ts (16 errors) ====
@@ -97,7 +97,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level '
9797

9898
for await (const _ of []);
9999
~~~~~
100-
!!! error TS1432: 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.
100+
!!! error TS1432: 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.
101101
await null;
102102
~~~~~
103-
!!! error TS1378: 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.
103+
!!! error TS1378: 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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [a.ts]
2+
declare var dec: any, __decorate: any;
3+
@dec export class A {
4+
}
5+
6+
const o = { a: 1 };
7+
const y = { ...o };
8+
9+
10+
//// [a.js]
11+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
15+
return c > 3 && r && Object.defineProperty(target, key, r), r;
16+
};
17+
let A = class A {
18+
};
19+
A = __decorate([
20+
dec
21+
], A);
22+
export { A };
23+
const o = { a: 1 };
24+
const y = Object.assign({}, o);

0 commit comments

Comments
 (0)