-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add import attributes * Add a warning info to import assertions AST spec
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# [Import Attributes][proposal-import-attributes] | ||
|
||
## Imports | ||
|
||
### ImportDeclaration | ||
|
||
```js | ||
extend interface ImportDeclaration { | ||
attributes: [ ImportAttribute ]; | ||
} | ||
``` | ||
|
||
The `attributes` is non-empty when import attributes present, e.g., `import foo from "./foo.json" with { type: "json" }`. | ||
|
||
Note: While the spec also supports `assert { type: "json" }`, it was considered legacy and thus not covered here. If you want to support the legacy syntax, please use [Import Assertions](../stage3/import-assertions.md) instead. | ||
|
||
### ImportAttribute | ||
|
||
```js | ||
interface ImportAttribute <: Node { | ||
type: "ImportAttribute"; | ||
key: Identifier | Literal; | ||
value: Literal; | ||
} | ||
``` | ||
|
||
An import attribute is an object-like key value pair, e.g. `type: "json"` in `import foo from "./foo.json" with { type: "json" }`. The `value` must be a string literal, that said, `value.value` is always `string`-type. If `key` is a `Literal`, it must be a string literal. | ||
|
||
## Exports | ||
|
||
### ExportNamedDeclaration | ||
|
||
```js | ||
extend interface ExportNamedDeclaration { | ||
attributes: [ ImportAttribute ]; | ||
} | ||
``` | ||
- `attributes` must be an empty array when `source` is `null`. | ||
|
||
### ExportAllDeclaration | ||
|
||
```js | ||
extend interface ExportAllDeclaration { | ||
attributes: [ ImportAttribute ]; | ||
} | ||
``` | ||
- `attributes` must be an empty array when `source` is `null`. | ||
|
||
## Expressions | ||
|
||
### ImportExpression | ||
|
||
```js | ||
extend interface ImportExpression { | ||
attributes: Expression | null; | ||
} | ||
``` | ||
|
||
The `attributes` property contains an `Expression` when import attributes presents, e.g., `{ with: { type: "json" } }` in `import(jsonModuleName, { with: { type: "json" } })`. | ||
|
||
[proposal-import-attributes]: https://github.com/tc39/proposal-import-attributes | ||
|
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