Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for top level await parsing (#2115)
* Add docs for top level await parsing * Typo Co-Authored-By: Brian Ng <bng412@gmail.com> * Update docs/plugin-syntax-top-level-await.md Co-Authored-By: Huáng Jùnliàng <jlhwung@gmail.com>
- Loading branch information
1 parent
bb1dc57
commit f7110e3
Showing
2 changed files
with
54 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
id: babel-plugin-syntax-top-level-await | ||
title: @babel/plugin-syntax-top-level-await | ||
sidebar_label: syntax-top-level-await | ||
--- | ||
|
||
> #### Syntax only | ||
> | ||
> This plugin only enables parsing of this feature. Babel doesn't support transforming | ||
> top-level await, but you can use Rollup's `experimentalTopLevelAwait` or webpack@5's | ||
> `experiments.topLevelAwait` options. | ||
```js | ||
const val = await promise; | ||
|
||
export { val }; | ||
``` | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-syntax-top-level-await | ||
``` | ||
|
||
## Usage | ||
|
||
### Via `.babelrc` (Recommended) | ||
|
||
**.babelrc** | ||
|
||
```json | ||
{ | ||
"plugins": ["@babel/plugin-syntax-top-level-await"] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh | ||
babel --plugins @babel/plugin-syntax-top-level-await script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
```javascript | ||
require("@babel/core").transform(code, { | ||
plugins: ["@babel/plugin-syntax-top-level-await"], | ||
}); | ||
``` |