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

esm: mark import attributes and JSON module as stable #55333

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,9 @@ changes:
description: Switch from Import Assertions to Import Attributes.
-->

> Stability: 1.1 - Active development

> This feature was previously named "Import assertions", and using the `assert`
> keyword instead of `with`. Any uses in code of the prior `assert` keyword
> should be updated to use `with` instead.
> Stability: 2 - Stable

The [Import Attributes proposal][] adds an inline syntax for module import
[Import attributes][Import Attributes MDN] are an inline syntax for module import
statements to pass on more information alongside the module specifier.

```js
Expand All @@ -286,13 +282,14 @@ const { default: barData } =
await import('./bar.json', { with: { type: 'json' } });
```

Node.js supports the following `type` values, for which the attribute is
mandatory:
Node.js only supports the `type` attribute, for which it supports the following values:

| Attribute `type` | Needed for |
| ---------------- | ---------------- |
| `'json'` | [JSON modules][] |

The `type: 'json'` attribute is mandatory when importing JSON modules.

## Built-in modules

[Built-in modules][] provide named exports of their public API. A
Expand Down Expand Up @@ -631,7 +628,7 @@ separate cache.

## JSON modules

> Stability: 1 - Experimental
> Stability: 2 - Stable

JSON files can be referenced by `import`:

Expand Down Expand Up @@ -1101,7 +1098,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
[Import Attributes]: #import-attributes
[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes
[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
[JSON modules]: #json-modules
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
[Module customization hooks]: module.md#customization-hooks
Expand Down
1 change: 0 additions & 1 deletion lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ translators.set('builtin', function builtinStrategy(url) {

// Strategy for loading a JSON file
translators.set('json', function jsonStrategy(url, source) {
emitExperimentalWarning('Importing JSON modules');
assertBufferSource(source, true, 'load');
debug(`Loading JSONModule ${url}`);
const pathname = StringPrototypeStartsWith(url, 'file:') ?
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe('ESM: importing JSON', () => {
assert.strictEqual(secret.ofLife, 42);
});

it('should print an experimental warning', async () => {
it('should not print an experimental warning', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
fixtures.path('/es-modules/json-modules.mjs'),
]);

assert.match(stderr, /ExperimentalWarning: Importing JSON modules/);
assert.strictEqual(stderr, '');
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
Comment on lines +19 to 27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this test case can just be removed, because there is no longer any code suggesting that an experimental emitting case.

Expand Down
Loading