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

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

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

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

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

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

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

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

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

+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'.",
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

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
@@ -2957,6 +2957,7 @@ declare namespace ts {
29572957
System = 4,
29582958
ES2015 = 5,
29592959
ES2020 = 6,
2960+
ES2022 = 7,
29602961
ESNext = 99
29612962
}
29622963
export enum JsxEmit {

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

+1
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,7 @@ declare namespace ts {
29572957
System = 4,
29582958
ES2015 = 5,
29592959
ES2020 = 6,
2960+
ES2022 = 7,
29602961
ESNext = 99
29612962
}
29622963
export enum JsxEmit {

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' or 'system', 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' or 'system', 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', or 'system', 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', or 'system', 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' or 'system', 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', or 'system', 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' or 'system', 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', or 'system', 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);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
2-
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
3-
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1+
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
2+
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
3+
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
44

55

66
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
@@ -9,16 +9,16 @@ tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports
99
==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ====
1010
import("./0");
1111
~~~~~~~~~~~~~
12-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
12+
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1313
var p1 = import("./0");
1414
~~~~~~~~~~~~~
15-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
15+
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1616
p1.then(zero => {
1717
return zero.foo();
1818
})
1919

2020
function foo() {
2121
const p2 = import("./0");
2222
~~~~~~~~~~~~~
23-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
23+
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
2424
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
2-
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1+
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
2+
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
33

44

55
==== tests/cases/conformance/dynamicImport/foo.ts (0 errors) ====
@@ -9,7 +9,7 @@ tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic impo
99
async function foo() {
1010
return await import((await import("./foo")).default);
1111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
12+
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1313
~~~~~~~~~~~~~~~
14-
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
14+
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
1515
}

0 commit comments

Comments
 (0)