Skip to content

Commit

Permalink
Tests for await using syntax (prettier#14862)
Browse files Browse the repository at this point in the history
* Add tests for `await using`

* Add tests for `await using` from Babel

* Add changelog

* Fix changelog
  • Loading branch information
sosukesuzuki authored and medikoo committed Feb 14, 2024
1 parent 1eb1c11 commit b97feff
Show file tree
Hide file tree
Showing 17 changed files with 753 additions and 2 deletions.
11 changes: 9 additions & 2 deletions changelog_unreleased/javascript/13752.md
@@ -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`
```
Expand Up @@ -849,6 +849,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 @@ -859,6 +863,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
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();
}

0 comments on commit b97feff

Please sign in to comment.