Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import attributes #302

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 62 additions & 0 deletions experimental/import-attributes.md
@@ -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

6 changes: 4 additions & 2 deletions stage3/import-assertions.md
@@ -1,5 +1,8 @@
# [Import Assertions][proposal-import-assertions]

> **Warning**
> This proposal has been superseded by [Import Attributes](../experimental/import-attributes.md).

## Imports

### ImportDeclaration
Expand Down Expand Up @@ -56,5 +59,4 @@ extend interface ImportExpression {

The `attributes` property contains an `Expression` when import attributes presents, e.g., `{ assert: { type: "json" } }` in `import(jsonModuleName, { assert: { type: "json" } })`.

[proposal-import-assertions]: https://github.com/tc39/proposal-import-assertions

[proposal-import-assertions]: https://github.com/tc39/proposal-import-attributes/tree/f5ad402cd3d3f82f28b1d1be2bfd567cd26336af