Skip to content

Commit 1ce97d1

Browse files
sosukesuzukifisker
andauthored
Support TypeScript 5.2 using / await using declaration (#15321)
* Update `@typescript-eslint` packages * Install `typescript` * Tweaks snapshot tests * Tweaks error files * Add tests for `using` with types * Add changelog * Update misc tests * Update snapshots * Revert misc tests and remove `typescript` * Update changelog_unreleased/typescript/15321.md Co-authored-by: fisker Cheung <[email protected]> * Fix file name typo * Keep valid file * Update tests * Update changelog_unreleased/typescript/15321.md Co-authored-by: fisker Cheung <[email protected]> * Remove non-existing filenames. --------- Co-authored-by: fisker Cheung <[email protected]>
1 parent a73cfa0 commit 1ce97d1

File tree

11 files changed

+143
-221
lines changed

11 files changed

+143
-221
lines changed

Diff for: changelog_unreleased/typescript/15321.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#### Support TypeScript 5.2 `using` / `await using` declaration (#15321 by @sosukesuzuki)
2+
3+
Support for the upcoming Explicit Resource Management feature in ECMAScript. [`using` / `await using` declaration](https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management)
4+
5+
<!-- prettier-ignore -->
6+
```tsx
7+
{
8+
using foo = new Foo();
9+
await using bar = new Bar();
10+
}
11+
```

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"@iarna/toml": "2.2.5",
3939
"@prettier/is-es5-identifier-name": "0.2.0",
4040
"@prettier/parse-srcset": "3.1.0",
41-
"@typescript-eslint/typescript-estree": "6.4.1",
42-
"@typescript-eslint/visitor-keys": "6.4.1",
41+
"@typescript-eslint/typescript-estree": "6.5.0",
42+
"@typescript-eslint/visitor-keys": "6.5.0",
4343
"acorn": "8.10.0",
4444
"acorn-jsx": "5.3.2",
4545
"angular-estree-parser": "7.0.0",
@@ -98,7 +98,7 @@
9898
"sdbm": "2.0.0",
9999
"strip-ansi": "7.1.0",
100100
"to-fast-properties": "4.0.0",
101-
"typescript": "5.1.6",
101+
"typescript": "5.2.2",
102102
"unicode-regex": "4.0.0",
103103
"unified": "9.2.2",
104104
"vnopts": "2.0.0",
@@ -112,7 +112,7 @@
112112
"@types/file-entry-cache": "5.0.2",
113113
"@types/find-cache-dir": "3.2.1",
114114
"@types/jest": "29.5.4",
115-
"@typescript-eslint/eslint-plugin": "6.4.1",
115+
"@typescript-eslint/eslint-plugin": "6.5.0",
116116
"benchmark": "2.1.4",
117117
"browserslist-to-esbuild": "1.2.0",
118118
"c8": "8.0.1",

Diff for: tests/format/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap

+16-99
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ exports[`for-await-using-of-comments.js [meriyah] format 1`] = `
2828
2 |"
2929
`;
3030

31-
exports[`for-await-using-of-comments.js [typescript] format 1`] = `
32-
"'of' expected. (1:51)
33-
> 1 | /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/;
34-
| ^
35-
2 |"
36-
`;
37-
3831
exports[`for-await-using-of-comments.js format 1`] = `
3932
====================================options=====================================
4033
parsers: ["babel", "flow", "typescript"]
@@ -90,10 +83,10 @@ exports[`invalid-duplicate-using-bindings.js [meriyah] format 1`] = `
9083
`;
9184
9285
exports[`invalid-duplicate-using-bindings.js [typescript] format 1`] = `
93-
"Unexpected keyword or identifier. (2:3)
86+
"'using' declarations must be initialized. (2:9)
9487
1 | {
9588
> 2 | using f, f = foo();
96-
| ^
89+
| ^
9790
3 | }
9891
4 | {
9992
5 | using g = foo();"
@@ -154,13 +147,6 @@ exports[`invalid-script-top-level-using-binding.js [meriyah] format 1`] = `
154147
2 |"
155148
`;
156149
157-
exports[`invalid-script-top-level-using-binding.js [typescript] format 1`] = `
158-
"Unexpected keyword or identifier. (1:1)
159-
> 1 | using x = bar();
160-
| ^
161-
2 |"
162-
`;
163-
164150
exports[`invalid-script-top-level-using-binding.js format 1`] = `
165151
====================================options=====================================
166152
parsers: ["babel", "flow", "typescript"]
@@ -216,13 +202,14 @@ exports[`using-declarations.js [meriyah] format 1`] = `
216202
`;
217203
218204
exports[`using-declarations.js [typescript] format 1`] = `
219-
"Unexpected keyword or identifier. (2:3)
220-
1 | {
221-
> 2 | using /* 1 */ a = foo(), /* 2 */ b = foo()
222-
| ^
205+
"'using' declarations may not be initialized in for statement. (5:19)
223206
3 | }
224207
4 |
225-
5 | for(using /* 1 */ a = foo(), /* 2 */ b = foo();;);"
208+
> 5 | for(using /* 1 */ a = foo(), /* 2 */ b = foo();;);
209+
| ^^^^^^^^^
210+
6 |
211+
7 | for(using /* 1 */ foo of bar());
212+
8 |"
226213
`;
227214
228215
exports[`using-declarations.js format 1`] = `
@@ -364,15 +351,6 @@ exports[`valid-await-using-binding-basic.js [meriyah] format 1`] = `
364351
4 |"
365352
`;
366353
367-
exports[`valid-await-using-binding-basic.js [typescript] format 1`] = `
368-
"';' expected. (2:15)
369-
1 | async function f() {
370-
> 2 | await using basic = getReader();
371-
| ^
372-
3 | }
373-
4 |"
374-
`;
375-
376354
exports[`valid-await-using-binding-basic.js format 1`] = `
377355
====================================options=====================================
378356
parsers: ["babel", "flow", "typescript"]
@@ -427,15 +405,6 @@ exports[`valid-await-using-binding-escaped.js [meriyah] format 1`] = `
427405
4 |"
428406
`;
429407
430-
exports[`valid-await-using-binding-escaped.js [typescript] format 1`] = `
431-
"';' expected. (2:15)
432-
1 | async function f() {
433-
> 2 | await using \\u0061b = c;
434-
| ^
435-
3 | }
436-
4 |"
437-
`;
438-
439408
exports[`valid-await-using-binding-escaped.js format 1`] = `
440409
====================================options=====================================
441410
parsers: ["babel", "flow", "typescript"]
@@ -490,15 +459,6 @@ exports[`valid-await-using-binding-non-bmp.js [meriyah] format 1`] = `
490459
4 |"
491460
`;
492461
493-
exports[`valid-await-using-binding-non-bmp.js [typescript] format 1`] = `
494-
"';' expected. (2:15)
495-
1 | async function f() {
496-
> 2 | await using 𠮷 = foo();
497-
| ^
498-
3 | }
499-
4 |"
500-
`;
501-
502462
exports[`valid-await-using-binding-non-bmp.js format 1`] = `
503463
====================================options=====================================
504464
parsers: ["babel", "flow", "typescript"]
@@ -557,16 +517,6 @@ exports[`valid-await-using-binding-using.js [meriyah] format 1`] = `
557517
5 |"
558518
`;
559519
560-
exports[`valid-await-using-binding-using.js [typescript] format 1`] = `
561-
"';' expected. (2:15)
562-
1 | async function f() {
563-
> 2 | await using using = of;
564-
| ^
565-
3 | for (await using using of of);
566-
4 | }
567-
5 |"
568-
`;
569-
570520
exports[`valid-await-using-binding-using.js format 1`] = `
571521
====================================options=====================================
572522
parsers: ["babel", "flow", "typescript"]
@@ -632,14 +582,14 @@ exports[`valid-await-using-comments.js [meriyah] format 1`] = `
632582
`;
633583
634584
exports[`valid-await-using-comments.js [typescript] format 1`] = `
635-
"';' expected. (3:28)
636-
1 | async function f() {
637-
2 | {
638-
> 3 | /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/;
639-
| ^
585+
"'await using' declarations may not be initialized in for statement. (6:42)
640586
4 | }
641587
5 | {
642-
6 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/;"
588+
> 6 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/;
589+
| ^^^^^^^^^^^^^
590+
7 | }
591+
8 | {
592+
9 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/;"
643593
`;
644594
645595
exports[`valid-await-using-comments.js format 1`] = `
@@ -826,10 +776,10 @@ exports[`valid-for-using-declaration.js [meriyah] format 1`] = `
826776
`;
827777
828778
exports[`valid-for-using-declaration.js [typescript] format 1`] = `
829-
"';' expected. (2:20)
779+
"'await using' declarations may not be initialized in for statement. (2:20)
830780
1 | async function f() {
831781
> 2 | for (await using basic = reader();;);
832-
| ^
782+
| ^^^^^^^^^^^^^^^^
833783
3 | }
834784
4 |"
835785
`;
@@ -1137,15 +1087,6 @@ exports[`valid-using-binding-basic.js [meriyah] format 1`] = `
11371087
4 |"
11381088
`;
11391089
1140-
exports[`valid-using-binding-basic.js [typescript] format 1`] = `
1141-
"Unexpected keyword or identifier. (2:3)
1142-
1 | {
1143-
> 2 | using basic = getReader();
1144-
| ^
1145-
3 | }
1146-
4 |"
1147-
`;
1148-
11491090
exports[`valid-using-binding-basic.js format 1`] = `
11501091
====================================options=====================================
11511092
parsers: ["babel", "flow", "typescript"]
@@ -1192,13 +1133,6 @@ exports[`valid-using-binding-escaped.js [meriyah] format 1`] = `
11921133
2 |"
11931134
`;
11941135
1195-
exports[`valid-using-binding-escaped.js [typescript] format 1`] = `
1196-
"Unexpected keyword or identifier. (1:3)
1197-
> 1 | { using \\u0061b = c; }
1198-
| ^
1199-
2 |"
1200-
`;
1201-
12021136
exports[`valid-using-binding-escaped.js format 1`] = `
12031137
====================================options=====================================
12041138
parsers: ["babel", "flow", "typescript"]
@@ -1243,13 +1177,6 @@ exports[`valid-using-binding-non-bmp.js [meriyah] format 1`] = `
12431177
2 |"
12441178
`;
12451179
1246-
exports[`valid-using-binding-non-bmp.js [typescript] format 1`] = `
1247-
"Unexpected keyword or identifier. (1:3)
1248-
> 1 | { using 𠮷 = foo(); }
1249-
| ^
1250-
2 |"
1251-
`;
1252-
12531180
exports[`valid-using-binding-non-bmp.js format 1`] = `
12541181
====================================options=====================================
12551182
parsers: ["babel", "flow", "typescript"]
@@ -1306,16 +1233,6 @@ exports[`valid-using-binding-using.js [meriyah] format 1`] = `
13061233
5 |"
13071234
`;
13081235
1309-
exports[`valid-using-binding-using.js [typescript] format 1`] = `
1310-
"Unexpected keyword or identifier. (2:3)
1311-
1 | {
1312-
> 2 | using using = of;
1313-
| ^
1314-
3 | for (using using of of);
1315-
4 | }
1316-
5 |"
1317-
`;
1318-
13191236
exports[`valid-using-binding-using.js format 1`] = `
13201237
====================================options=====================================
13211238
parsers: ["babel", "flow", "typescript"]

Diff for: tests/format/js/explicit-resource-management/jsfmt.spec.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,18 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
2525
"valid-module-block-top-level-await-using-binding.js",
2626
],
2727
typescript: [
28-
"for-await-using-of-comments.js",
2928
"invalid-duplicate-using-bindings.js",
30-
"invalid-script-top-level-using-binding.js",
31-
"using-declarations.js",
32-
// "valid-for-await-using-binding-escaped-of-of.js",
33-
// "valid-for-using-binding-escaped-of-of.js",
34-
"valid-module-block-top-level-using-binding.js",
35-
"valid-using-binding-basic.js",
36-
"valid-using-binding-escaped.js",
37-
"valid-using-binding-non-bmp.js",
38-
"valid-using-binding-using.js",
3929

40-
"valid-await-using-binding-basic.js",
41-
"valid-await-using-binding-escaped.js",
42-
"valid-await-using-binding-non-bmp.js",
43-
"valid-await-using-binding-using.js",
30+
// https://github.com/typescript-eslint/typescript-eslint/blob/4f34d0ba34474926ba1eed623704b583a037f886/packages/typescript-estree/src/convert.ts#L1035-L1050
31+
"valid-for-using-declaration.js",
4432
"valid-await-using-comments.js",
45-
"valid-for-lhs-await-as-identifier.js",
33+
"using-declarations.js",
34+
35+
// https://github.com/microsoft/TypeScript/issues/55555
4636
"valid-for-using-binding-of-of.js",
47-
"valid-for-using-declaration.js",
37+
38+
// TypeScript does not support module expr
39+
"valid-module-block-top-level-using-binding.js",
4840
"valid-module-block-top-level-await-using-binding.js",
4941
],
5042
espree: [

Diff for: tests/format/misc/errors/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap

-47
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ exports[`invalid-for-await-using-binding-of-of.js [flow] format 1`] = `
1414
2 |"
1515
`;
1616

17-
exports[`invalid-for-await-using-binding-of-of.js [typescript] format 1`] = `
18-
"')' expected. (1:24)
19-
> 1 | for await (using of of of);
20-
| ^
21-
2 |"
22-
`;
23-
2417
exports[`invalid-for-using-binding-in.js [babel] format 1`] = `
2518
"For-in loop may not start with 'using' declaration. (1:6)
2619
> 1 | for (using foo in {});
@@ -35,13 +28,6 @@ exports[`invalid-for-using-binding-in.js [flow] format 1`] = `
3528
2 |"
3629
`;
3730

38-
exports[`invalid-for-using-binding-in.js [typescript] format 1`] = `
39-
"';' expected. (1:12)
40-
> 1 | for (using foo in {});
41-
| ^
42-
2 |"
43-
`;
44-
4531
exports[`invalid-for-using-binding-of-in.js [babel] format 1`] = `
4632
"Unexpected token (1:15)
4733
> 1 | for (using of in []);
@@ -56,13 +42,6 @@ exports[`invalid-for-using-binding-of-in.js [flow] format 1`] = `
5642
2 |"
5743
`;
5844

59-
exports[`invalid-for-using-binding-of-in.js [typescript] format 1`] = `
60-
"Expression expected. (1:15)
61-
> 1 | for (using of in []);
62-
| ^
63-
2 |"
64-
`;
65-
6645
exports[`invalid-for-using-binding-of-of.js [babel] format 1`] = `
6746
"Unexpected token, expected ")" (1:18)
6847
> 1 | for (using of of of);
@@ -77,13 +56,6 @@ exports[`invalid-for-using-binding-of-of.js [flow] format 1`] = `
7756
2 |"
7857
`;
7958

80-
exports[`invalid-for-using-binding-of-of.js [typescript] format 1`] = `
81-
"')' expected. (1:18)
82-
> 1 | for (using of of of);
83-
| ^
84-
2 |"
85-
`;
86-
8759
exports[`invalid-using-binding-let.js [babel] format 1`] = `
8860
"'let' is not allowed to be used as a name in 'let' or 'const' declarations. (2:9)
8961
1 | {
@@ -102,15 +74,6 @@ exports[`invalid-using-binding-let.js [flow] format 1`] = `
10274
4 |"
10375
`;
10476

105-
exports[`invalid-using-binding-let.js [typescript] format 1`] = `
106-
"Unexpected keyword or identifier. (2:3)
107-
1 | {
108-
> 2 | using let = h();
109-
| ^
110-
3 | }
111-
4 |"
112-
`;
113-
11477
exports[`invalid-using-binding-pattern.js [babel] format 1`] = `
11578
"Unexpected token (2:17)
11679
1 | {
@@ -130,13 +93,3 @@ exports[`invalid-using-binding-pattern.js [flow] format 1`] = `
13093
4 | for (using { qux } of h());
13194
5 | for (using [ quux ] of i());"
13295
`;
133-
134-
exports[`invalid-using-binding-pattern.js [typescript] format 1`] = `
135-
"Unexpected keyword or identifier. (2:3)
136-
1 | {
137-
> 2 | using { foo } = f();
138-
| ^
139-
3 | using [ bar ] = g();
140-
4 | for (using { qux } of h());
141-
5 | for (using [ quux ] of i());"
142-
`;
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
run_spec(import.meta, ["babel", "flow", "typescript"]);
1+
run_spec(import.meta, [
2+
"babel",
3+
"flow",
4+
// Waiting https://github.com/typescript-eslint/typescript-eslint/issues/7555 and https://github.com/typescript-eslint/typescript-eslint/issues/7554
5+
// "typescript"
6+
]);

0 commit comments

Comments
 (0)