Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript 5.2 using / await using declaration #15321

Merged
merged 16 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog_unreleased/typescript/15321.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#### Support TypeScript 5.2 `using` / `await using` declaration (#15321 by @sosukesuzuki)

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)

<!-- prettier-ignore -->
```tsx
{
using foo = new Foo();
await using bar = new Bar();
}
```
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"@iarna/toml": "2.2.5",
"@prettier/is-es5-identifier-name": "0.2.0",
"@prettier/parse-srcset": "3.1.0",
"@typescript-eslint/typescript-estree": "6.4.1",
"@typescript-eslint/visitor-keys": "6.4.1",
"@typescript-eslint/typescript-estree": "6.5.0",
"@typescript-eslint/visitor-keys": "6.5.0",
"acorn": "8.10.0",
"acorn-jsx": "5.3.2",
"angular-estree-parser": "7.0.0",
Expand Down Expand Up @@ -98,7 +98,7 @@
"sdbm": "2.0.0",
"strip-ansi": "7.1.0",
"to-fast-properties": "4.0.0",
"typescript": "5.1.6",
"typescript": "5.2.2",
"unicode-regex": "4.0.0",
"unified": "9.2.2",
"vnopts": "2.0.0",
Expand All @@ -112,7 +112,7 @@
"@types/file-entry-cache": "5.0.2",
"@types/find-cache-dir": "3.2.1",
"@types/jest": "29.5.4",
"@typescript-eslint/eslint-plugin": "6.4.1",
"@typescript-eslint/eslint-plugin": "6.5.0",
"benchmark": "2.1.4",
"browserslist-to-esbuild": "1.2.0",
"c8": "8.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ exports[`for-await-using-of-comments.js [meriyah] format 1`] = `
2 |"
`;

exports[`for-await-using-of-comments.js [typescript] format 1`] = `
"'of' expected. (1:51)
> 1 | /*1*/ for /* 2 */ await /*3*/ ( /*4*/ using /*5*/ fo /*6*/ of /*7*/ of /*8*/) /*9*/;
| ^
2 |"
`;

exports[`for-await-using-of-comments.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -90,10 +83,10 @@ exports[`invalid-duplicate-using-bindings.js [meriyah] format 1`] = `
`;

exports[`invalid-duplicate-using-bindings.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (2:3)
"'using' declarations must be initialized. (2:9)
1 | {
> 2 | using f, f = foo();
| ^
| ^
3 | }
4 | {
5 | using g = foo();"
Expand Down Expand Up @@ -154,13 +147,6 @@ exports[`invalid-script-top-level-using-binding.js [meriyah] format 1`] = `
2 |"
`;

exports[`invalid-script-top-level-using-binding.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (1:1)
> 1 | using x = bar();
| ^
2 |"
`;

exports[`invalid-script-top-level-using-binding.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -216,13 +202,14 @@ exports[`using-declarations.js [meriyah] format 1`] = `
`;

exports[`using-declarations.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (2:3)
1 | {
> 2 | using /* 1 */ a = foo(), /* 2 */ b = foo()
| ^
"'using' declarations may not be initialized in for statement. (5:19)
3 | }
4 |
5 | for(using /* 1 */ a = foo(), /* 2 */ b = foo();;);"
> 5 | for(using /* 1 */ a = foo(), /* 2 */ b = foo();;);
| ^^^^^^^^^
6 |
7 | for(using /* 1 */ foo of bar());
8 |"
`;

exports[`using-declarations.js format 1`] = `
Expand Down Expand Up @@ -364,15 +351,6 @@ exports[`valid-await-using-binding-basic.js [meriyah] format 1`] = `
4 |"
`;

exports[`valid-await-using-binding-basic.js [typescript] format 1`] = `
"';' expected. (2:15)
1 | async function f() {
> 2 | await using basic = getReader();
| ^
3 | }
4 |"
`;

exports[`valid-await-using-binding-basic.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -427,15 +405,6 @@ exports[`valid-await-using-binding-escaped.js [meriyah] format 1`] = `
4 |"
`;

exports[`valid-await-using-binding-escaped.js [typescript] format 1`] = `
"';' expected. (2:15)
1 | async function f() {
> 2 | await using \\u0061b = c;
| ^
3 | }
4 |"
`;

exports[`valid-await-using-binding-escaped.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -490,15 +459,6 @@ exports[`valid-await-using-binding-non-bmp.js [meriyah] format 1`] = `
4 |"
`;

exports[`valid-await-using-binding-non-bmp.js [typescript] format 1`] = `
"';' expected. (2:15)
1 | async function f() {
> 2 | await using 𠮷 = foo();
| ^
3 | }
4 |"
`;

exports[`valid-await-using-binding-non-bmp.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -557,16 +517,6 @@ exports[`valid-await-using-binding-using.js [meriyah] format 1`] = `
5 |"
`;

exports[`valid-await-using-binding-using.js [typescript] format 1`] = `
"';' expected. (2:15)
1 | async function f() {
> 2 | await using using = of;
| ^
3 | for (await using using of of);
4 | }
5 |"
`;

exports[`valid-await-using-binding-using.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -632,14 +582,14 @@ exports[`valid-await-using-comments.js [meriyah] format 1`] = `
`;

exports[`valid-await-using-comments.js [typescript] format 1`] = `
"';' expected. (3:28)
1 | async function f() {
2 | {
> 3 | /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/;
| ^
"'await using' declarations may not be initialized in for statement. (6:42)
4 | }
5 | {
6 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/;"
> 6 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/;
| ^^^^^^^^^^^^^
7 | }
8 | {
9 | /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/;"
`;

exports[`valid-await-using-comments.js format 1`] = `
Expand Down Expand Up @@ -826,10 +776,10 @@ exports[`valid-for-using-declaration.js [meriyah] format 1`] = `
`;

exports[`valid-for-using-declaration.js [typescript] format 1`] = `
"';' expected. (2:20)
"'await using' declarations may not be initialized in for statement. (2:20)
1 | async function f() {
> 2 | for (await using basic = reader();;);
| ^
| ^^^^^^^^^^^^^^^^
3 | }
4 |"
`;
Expand Down Expand Up @@ -1137,15 +1087,6 @@ exports[`valid-using-binding-basic.js [meriyah] format 1`] = `
4 |"
`;

exports[`valid-using-binding-basic.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (2:3)
1 | {
> 2 | using basic = getReader();
| ^
3 | }
4 |"
`;

exports[`valid-using-binding-basic.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -1192,13 +1133,6 @@ exports[`valid-using-binding-escaped.js [meriyah] format 1`] = `
2 |"
`;

exports[`valid-using-binding-escaped.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (1:3)
> 1 | { using \\u0061b = c; }
| ^
2 |"
`;

exports[`valid-using-binding-escaped.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -1243,13 +1177,6 @@ exports[`valid-using-binding-non-bmp.js [meriyah] format 1`] = `
2 |"
`;

exports[`valid-using-binding-non-bmp.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (1:3)
> 1 | { using 𠮷 = foo(); }
| ^
2 |"
`;

exports[`valid-using-binding-non-bmp.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down Expand Up @@ -1306,16 +1233,6 @@ exports[`valid-using-binding-using.js [meriyah] format 1`] = `
5 |"
`;

exports[`valid-using-binding-using.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (2:3)
1 | {
> 2 | using using = of;
| ^
3 | for (using using of of);
4 | }
5 |"
`;

exports[`valid-using-binding-using.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down
29 changes: 13 additions & 16 deletions tests/format/js/explicit-resource-management/jsfmt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
"using-declarations.js",
// "valid-for-await-using-binding-escaped-of-of.js",
// "valid-for-using-binding-escaped-of-of.js",
"invalid-using-declaration-in-for.js",
"valid-module-block-top-level-using-binding.js",
"valid-using-as-identifier-for-await-of.js",
"valid-using-binding-basic.js",
Expand All @@ -25,26 +26,19 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
"valid-module-block-top-level-await-using-binding.js",
],
typescript: [
"for-await-using-of-comments.js",
"invalid-duplicate-using-bindings.js",
"invalid-script-top-level-using-binding.js",
"using-declarations.js",
// "valid-for-await-using-binding-escaped-of-of.js",
// "valid-for-using-binding-escaped-of-of.js",
"valid-module-block-top-level-using-binding.js",
"valid-using-binding-basic.js",
"valid-using-binding-escaped.js",
"valid-using-binding-non-bmp.js",
"valid-using-binding-using.js",
"invalid-using-declaration-in-for.js",

"valid-await-using-binding-basic.js",
"valid-await-using-binding-escaped.js",
"valid-await-using-binding-non-bmp.js",
"valid-await-using-binding-using.js",
// https://github.com/typescript-eslint/typescript-eslint/blob/4f34d0ba34474926ba1eed623704b583a037f886/packages/typescript-estree/src/convert.ts#L1035-L1050
"valid-for-using-declaration.js",
"valid-await-using-comments.js",
"valid-for-lhs-await-as-identifier.js",
"using-declarations.js",
Comment on lines +31 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescript-estree throws for these files (tsc doesn't throw).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ignore edge cases.


// https://github.com/microsoft/TypeScript/issues/55555
"valid-for-using-binding-of-of.js",
"valid-for-using-declaration.js",

// TypeScript does not support module expr
"valid-module-block-top-level-using-binding.js",
"valid-module-block-top-level-await-using-binding.js",
],
espree: [
Expand All @@ -54,6 +48,7 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
"using-declarations.js",
// "valid-for-await-using-binding-escaped-of-of.js",
// "valid-for-using-binding-escaped-of-of.js",
"invalid-using-declaration-in-for.js",
"valid-module-block-top-level-using-binding.js",
"valid-using-binding-basic.js",
"valid-using-binding-escaped.js",
Expand All @@ -77,6 +72,7 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
"using-declarations.js",
// "valid-for-await-using-binding-escaped-of-of.js",
// "valid-for-using-binding-escaped-of-of.js",
"invalid-using-declaration-in-for.js",
"valid-module-block-top-level-using-binding.js",
"valid-using-binding-basic.js",
"valid-using-binding-escaped.js",
Expand All @@ -100,6 +96,7 @@ run_spec(import.meta, ["babel", "flow", "typescript"], {
"using-declarations.js",
// "valid-for-await-using-binding-escaped-of-of.js",
// "valid-for-using-binding-escaped-of-of.js",
"invalid-using-declaration-in-for.js",
"valid-module-block-top-level-using-binding.js",
"valid-using-binding-basic.js",
"valid-using-binding-escaped.js",
Expand Down