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

Diff for: src/compiler/checker.ts

+11-13
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) {

Diff for: 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,

Diff for: 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
},

Diff for: 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;

Diff for: 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
}

Diff for: src/compiler/types.ts

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

Diff for: 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:

Diff for: 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();

Diff for: src/services/codefixes/importFixes.ts

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

Diff for: 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

Diff for: 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
}]

Diff for: tests/baselines/reference/api/tsserverlibrary.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,7 @@ declare namespace ts {
30233023
System = 4,
30243024
ES2015 = 5,
30253025
ES2020 = 6,
3026+
ES2022 = 7,
30263027
ESNext = 99,
30273028
Node12 = 100,
30283029
NodeNext = 199

Diff for: tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,7 @@ declare namespace ts {
30233023
System = 4,
30243024
ES2015 = 5,
30253025
ES2020 = 6,
3026+
ES2022 = 7,
30263027
ESNext = 99,
30273028
Node12 = 100,
30283029
NodeNext = 199

Diff for: 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)