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

Tests for await using syntax #14862

Merged
Merged
Show file tree
Hide file tree
Changes from all 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: 9 additions & 2 deletions changelog_unreleased/javascript/13752.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#### Add support for "Explicit Resource Management" proposal (#13752 by @fisker)
#### Add support for "Explicit Resource Management" proposal (#13752 by @fisker, #14862 by @sosukesuzuki)

The Stage 2 proposal ["Explicit Resource Management"](https://github.com/tc39/proposal-explicit-resource-management/) is now supported via Babel 7.20.0. Also keep in mind our [policy on non-standardized syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) before using this proposed syntax feature with Prettier.
The Stage 2 proposal ["Explicit Resource Management"](https://github.com/tc39/proposal-explicit-resource-management/) is now supported via Babel [7.20.0](https://babeljs.io/blog/2022/10/27/7.20.0) and [7.22.0](https://babeljs.io/blog/2023/05/26/7.22.0).

Also keep in mind our [policy on non-standardized syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) before using this proposed syntax feature with Prettier.

<!-- prettier-ignore -->
```js
Expand All @@ -9,4 +11,9 @@ The Stage 2 proposal ["Explicit Resource Management"](https://github.com/tc39/pr
using obj = g(); // block-scoped declaration
const r = obj.next();
} // calls finally blocks in `g`

{
await using obj = g(); // block-scoped declaration
const r = obj.next();
} // calls finally blocks in `g`
```
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,10 @@ function * g() {
const r = obj.next();
} // calls finally blocks in \`g\`

{
await using obj = g();
}

=====================================output=====================================
function* g() {
using handle = acquireFileHandle(); // block-scoped critical resource
Expand All @@ -870,6 +874,10 @@ function* g() {
const r = obj.next();
} // calls finally blocks in \`g\`

{
await using obj = g();
}

================================================================================
`;

Expand Down
4 changes: 4 additions & 0 deletions tests/format/js/babel-plugins/explicit-resource-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ function * g() {
using obj = g(); // block-scoped declaration
const r = obj.next();
} // calls finally blocks in `g`

{
await using obj = g();
}