-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into import-attr-docs
- Loading branch information
Showing
51 changed files
with
496 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
id: babel-plugin-proposal-explicit-resource-management | ||
title: "@babel/plugin-proposal-explicit-resource-management" | ||
sidebar_label: explicit-resource-management | ||
--- | ||
|
||
This plugin enables Babel to transform using declarations `using handler = await read();`. | ||
|
||
## Example | ||
|
||
```js title="input.js" | ||
using handlerSync = openSync(); | ||
await using handlerAsync = await openAsync(); | ||
``` | ||
|
||
will be transformed to | ||
|
||
```js title="output.js" | ||
try { | ||
var _stack = []; | ||
var handlerSync = babelHelpers.using(_stack, openSync()); | ||
var handlerAsync = babelHelpers.using(_stack, await openAsync(), true); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
} finally { | ||
await babelHelpers.dispose(_stack, _error, _hasError); | ||
} | ||
``` | ||
|
||
[Try it on the REPL](https://babeljs.io/repl#?build=&builtIns=false&corejs=3.28&spec=false&loose=false&code_lz=K4Zwlgdg5gBAFgQwgEwDYFMBOBlAnhAYxgF4YB7AB3Qj0IAoBKAbgCgEB3BMAFxlEliIUGTAEEQ-IqQ5delauMmMmQA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=react&prettier=false&targets=&externalPlugins=%40babel%2Fplugin-proposal-explicit-resource-management%407.22.0%2C%40babel%2Fplugin-external-helpers%407.18.6&assumptions=%7B%7D). | ||
|
||
## Installation | ||
|
||
```shell npm2yarn | ||
npm install --save-dev @babel/plugin-proposal-explicit-resource-management | ||
``` | ||
|
||
## Usage | ||
|
||
### With a configuration file (Recommended) | ||
|
||
```json title="babel.config.json" | ||
{ | ||
"plugins": ["@babel/plugin-proposal-explicit-resource-management"] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh title="Shell" | ||
babel --plugins @babel/plugin-proposal-explicit-resource-management script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
```js title="JavaScript" | ||
require("@babel/core").transformSync("code", { | ||
plugins: ["@babel/plugin-proposal-explicit-resource-management"] | ||
}); | ||
``` | ||
|
||
## References | ||
|
||
- [Proposal: ECMAScript Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
id: babel-plugin-proposal-import-attributes-to-assertions | ||
title: "@babel/plugin-proposal-import-attributes-to-assertions" | ||
sidebar_label: import-attributes-to-assertions | ||
--- | ||
|
||
:::caution | ||
|
||
This plugin will generate code that is not compatible with the current ECMAScript specification or with any currently proposed addition to it. Only use it when you are shipping native ES modules and you need compatibility exclusively with tools that don't support the Import Attributes syntax (`import pkg from "./package.json" with { type: "json" }`) but support the old Import Assertions syntax (`import pkg from "./package.json" assert { type: "json" }`), such as Chrome 91+ and Node.js 17.2+. | ||
|
||
::: | ||
|
||
## Installation | ||
|
||
```shell npm2yarn | ||
npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions | ||
``` | ||
|
||
## Usage | ||
|
||
### With a configuration file (Recommended) | ||
|
||
```json title="babel.config.json" | ||
{ | ||
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh title="Shell" | ||
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
```js title="JavaScript" | ||
require("@babel/core").transformSync("code", { | ||
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"], | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.