From 5991cb0d0c1739cc2067df9a3d26dbe6029c4d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 28 Nov 2022 11:28:46 -0500 Subject: [PATCH] Add await operations docs --- docs/parser.md | 4 +- docs/plugin-proposal-await-operations.md | 60 ++++++++++++++++++++++++ docs/plugin-syntax-await-operations.md | 41 ++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 docs/plugin-proposal-await-operations.md create mode 100644 docs/plugin-syntax-await-operations.md diff --git a/docs/parser.md b/docs/parser.md index 41313c6009..3d0982ccf0 100644 --- a/docs/parser.md +++ b/docs/parser.md @@ -193,6 +193,7 @@ require("@babel/parser").parse("code", { History | Version | Changes | | --- | --- | +| `v7.21.0` | Added `awaitOperations` | | `v7.20.0` | Added `explicitResourceManagement`, `importReflection` | | `v7.17.0` | Added `regexpUnicodeSets`, `destructuringPrivate`, `decoratorAutoAccessors` | | `v7.15.0` | Added `hack` to the `proposal` option of `pipelineOperator`. Moved `topLevelAwait`, `privateIn` to Latest ECMAScript features | @@ -210,6 +211,7 @@ require("@babel/parser").parse("code", { | Name | Code Example | | -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | | `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` | +| `awaitOperations` ([proposal](https://github.com/tc39/proposal-await.ops)) | `await.all promises` | | `decimal` ([proposal](https://github.com/tc39/proposal-decimal)) | `0.3m` | | `decorators` ([proposal](https://github.com/tc39/proposal-decorators))
`decorators-legacy` | `@a class A {}` | | `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` | @@ -220,7 +222,7 @@ require("@babel/parser").parse("code", { | `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` | | `importAssertions` ([proposal](https://github.com/tc39/proposal-import-assertions)) | `import json from "./foo.json" assert { type: "json" };` | | `importReflection` ([proposal])(https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` | -| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` | +| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-module-expressions)) | `let m = module { export let y = 1; };` | | `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` | | `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | a |> b | | `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` | diff --git a/docs/plugin-proposal-await-operations.md b/docs/plugin-proposal-await-operations.md new file mode 100644 index 0000000000..5dd3e149d4 --- /dev/null +++ b/docs/plugin-proposal-await-operations.md @@ -0,0 +1,60 @@ +--- +id: babel-plugin-proposal-await-operations +title: @babel/plugin-proposal-await-operations +sidebar_label: await-operations +--- + +Transforms await operations. + +## Example +```js +await.all promises; +await.allSettled promises; +await.any promises; +await.race promises; +``` + +will be transformed to + +```js +await Promise.all(promises); +await Promise.allSettled(promises); +await Promise.any(promises); +await Promise.race(promises); +``` + +The plugin assumes that the builtin `Promise` is not shadowed or modified. It should work with a spec-compliant `Promise` polyfill. + +## Installation + +```sh +npm install --save-dev @babel/plugin-proposal-await-operations +``` + +## Usage + +### With a configuration file (Recommended) + +```json +{ + "plugins": ["@babel/plugin-proposal-await-operations"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-proposal-await-operations script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transformSync("code", { + plugins: ["@babel/plugin-proposal-await-operations"], +}); +``` + +## References + +- [Proposal: Await Operations](https://github.com/tc39/proposal-await.ops) diff --git a/docs/plugin-syntax-await-operations.md b/docs/plugin-syntax-await-operations.md new file mode 100644 index 0000000000..8f05557570 --- /dev/null +++ b/docs/plugin-syntax-await-operations.md @@ -0,0 +1,41 @@ +--- +id: babel-plugin-syntax-await-operations +title: @babel/plugin-syntax-await-operations +sidebar_label: syntax-await-operations +--- + +> Allow parsing of await operations + +> #### Syntax only +> +> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-await-operations](plugin-proposal-await-operations.md) to _both_ parse and transform this syntax. + +## Installation + +```sh +npm install --save-dev @babel/plugin-syntax-await-operations +``` + +## Usage + +### With a configuration file (Recommended) + +```json +{ + "plugins": ["@babel/plugin-syntax-await-operations"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-syntax-await-operations script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transformSync("code", { + plugins: ["@babel/plugin-syntax-await-operations"], +}); +```