-
-
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.
Ad docs for import attributes (#2780)
* Ad docs for import attributes * Add `deprecatedAssertSyntax` default value * Add to sidebar
- Loading branch information
1 parent
8cb0546
commit ac754a6
Showing
4 changed files
with
88 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
id: babel-plugin-syntax-import-attributes | ||
title: "@babel/plugin-syntax-import-attributes" | ||
sidebar_label: syntax-import-attributes | ||
--- | ||
|
||
> #### Syntax only | ||
> | ||
> This plugin only enables Babel to parse this syntax. Babel does not support transforming this syntax | ||
This plugin enables Babel to parse import attributes: | ||
|
||
```js title="JavaScript" | ||
import foo from "./foo.json" with { type: "json" }; | ||
``` | ||
|
||
## Installation | ||
|
||
```shell npm2yarn | ||
npm install --save-dev @babel/plugin-syntax-import-attributes | ||
``` | ||
|
||
## Usage | ||
|
||
### With a configuration file (Recommended) | ||
|
||
```json title="babel.config.json" | ||
{ | ||
"plugins": ["@babel/plugin-syntax-import-attributes"] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh title="Shell" | ||
babel --plugins @babel/plugin-syntax-import-attributes script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
```js title="JavaScript" | ||
require("@babel/core").transformSync("code", { | ||
plugins: ["@babel/plugin-syntax-import-attributes"] | ||
}); | ||
``` | ||
|
||
## Options | ||
|
||
### `deprecatedAssertSyntax` | ||
|
||
`boolean`, defaults to `false`. | ||
|
||
If enabled, support parsing import attributes using the [deprecated](https://tc39.es/proposal-import-attributes/#sec-deprecated-assert-keyword-for-import-attributes) `assert` keyword: | ||
|
||
```js title="JavaScript" | ||
import foo from "./foo.json" assert { type: "json" }; | ||
``` | ||
|
||
This syntax is only supported in V8-based engines, and its removal from the web is being investigated. |
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