Skip to content

Commit

Permalink
Support TypeScript 5.2 using / await using declaration (#15321)
Browse files Browse the repository at this point in the history
* 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 <lionkay@gmail.com>

* Fix file name typo

* Keep valid file

* Update tests

* Update changelog_unreleased/typescript/15321.md

Co-authored-by: fisker Cheung <lionkay@gmail.com>

* Remove non-existing filenames.

---------

Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
sosukesuzuki and fisker authored Aug 29, 2023
1 parent a73cfa0 commit 1ce97d1
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 221 deletions.
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
24 changes: 8 additions & 16 deletions tests/format/js/explicit-resource-management/jsfmt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ 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",

"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",

// 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ exports[`invalid-for-await-using-binding-of-of.js [flow] format 1`] = `
2 |"
`;

exports[`invalid-for-await-using-binding-of-of.js [typescript] format 1`] = `
"')' expected. (1:24)
> 1 | for await (using of of of);
| ^
2 |"
`;

exports[`invalid-for-using-binding-in.js [babel] format 1`] = `
"For-in loop may not start with 'using' declaration. (1:6)
> 1 | for (using foo in {});
Expand All @@ -35,13 +28,6 @@ exports[`invalid-for-using-binding-in.js [flow] format 1`] = `
2 |"
`;

exports[`invalid-for-using-binding-in.js [typescript] format 1`] = `
"';' expected. (1:12)
> 1 | for (using foo in {});
| ^
2 |"
`;

exports[`invalid-for-using-binding-of-in.js [babel] format 1`] = `
"Unexpected token (1:15)
> 1 | for (using of in []);
Expand All @@ -56,13 +42,6 @@ exports[`invalid-for-using-binding-of-in.js [flow] format 1`] = `
2 |"
`;

exports[`invalid-for-using-binding-of-in.js [typescript] format 1`] = `
"Expression expected. (1:15)
> 1 | for (using of in []);
| ^
2 |"
`;

exports[`invalid-for-using-binding-of-of.js [babel] format 1`] = `
"Unexpected token, expected ")" (1:18)
> 1 | for (using of of of);
Expand All @@ -77,13 +56,6 @@ exports[`invalid-for-using-binding-of-of.js [flow] format 1`] = `
2 |"
`;

exports[`invalid-for-using-binding-of-of.js [typescript] format 1`] = `
"')' expected. (1:18)
> 1 | for (using of of of);
| ^
2 |"
`;

exports[`invalid-using-binding-let.js [babel] format 1`] = `
"'let' is not allowed to be used as a name in 'let' or 'const' declarations. (2:9)
1 | {
Expand All @@ -102,15 +74,6 @@ exports[`invalid-using-binding-let.js [flow] format 1`] = `
4 |"
`;

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

exports[`invalid-using-binding-pattern.js [babel] format 1`] = `
"Unexpected token (2:17)
1 | {
Expand All @@ -130,13 +93,3 @@ exports[`invalid-using-binding-pattern.js [flow] format 1`] = `
4 | for (using { qux } of h());
5 | for (using [ quux ] of i());"
`;
exports[`invalid-using-binding-pattern.js [typescript] format 1`] = `
"Unexpected keyword or identifier. (2:3)
1 | {
> 2 | using { foo } = f();
| ^
3 | using [ bar ] = g();
4 | for (using { qux } of h());
5 | for (using [ quux ] of i());"
`;
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
run_spec(import.meta, ["babel", "flow", "typescript"]);
run_spec(import.meta, [
"babel",
"flow",
// Waiting https://github.com/typescript-eslint/typescript-eslint/issues/7555 and https://github.com/typescript-eslint/typescript-eslint/issues/7554
// "typescript"
]);
Loading

0 comments on commit 1ce97d1

Please sign in to comment.