Skip to content

Commit 88d91e8

Browse files
nicolo-ribaudoaduh95
authored andcommitted
esm: mark import attributes and JSON module as stable
The two proposals reached stage 4 at the October 2024 meeting. PR-URL: #55333 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent d5fa767 commit 88d91e8

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

doc/api/esm.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,9 @@ changes:
270270
description: Switch from Import Assertions to Import Attributes.
271271
-->
272272

273-
> Stability: 1.1 - Active development
274-
275-
> This feature was previously named "Import assertions", and using the `assert`
276-
> keyword instead of `with`. Any uses in code of the prior `assert` keyword
277-
> should be updated to use `with` instead.
273+
> Stability: 2 - Stable
278274
279-
The [Import Attributes proposal][] adds an inline syntax for module import
275+
[Import attributes][Import Attributes MDN] are an inline syntax for module import
280276
statements to pass on more information alongside the module specifier.
281277

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

289-
Node.js supports the following `type` values, for which the attribute is
290-
mandatory:
285+
Node.js only supports the `type` attribute, for which it supports the following values:
291286

292287
| Attribute `type` | Needed for |
293288
| ---------------- | ---------------- |
294289
| `'json'` | [JSON modules][] |
295290

291+
The `type: 'json'` attribute is mandatory when importing JSON modules.
292+
296293
## Built-in modules
297294

298295
[Built-in modules][] provide named exports of their public API. A
@@ -609,7 +606,7 @@ separate cache.
609606
610607
## JSON modules
611608
612-
> Stability: 1 - Experimental
609+
> Stability: 2 - Stable
613610
614611
JSON files can be referenced by `import`:
615612
@@ -1079,7 +1076,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
10791076
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
10801077
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
10811078
[Import Attributes]: #import-attributes
1082-
[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes
1079+
[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
10831080
[JSON modules]: #json-modules
10841081
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
10851082
[Module customization hooks]: module.md#customization-hooks

lib/internal/modules/esm/translators.js

-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ translators.set('builtin', function builtinStrategy(url) {
361361

362362
// Strategy for loading a JSON file
363363
translators.set('json', function jsonStrategy(url, source) {
364-
emitExperimentalWarning('Importing JSON modules');
365364
assertBufferSource(source, true, 'load');
366365
debug(`Loading JSONModule ${url}`);
367366
const pathname = StringPrototypeStartsWith(url, 'file:') ?

test/es-module/test-esm-json.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ describe('ESM: importing JSON', () => {
1616
assert.strictEqual(secret.ofLife, 42);
1717
});
1818

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

24-
assert.match(stderr, /ExperimentalWarning: Importing JSON modules/);
24+
assert.strictEqual(stderr, '');
2525
assert.strictEqual(code, 0);
2626
assert.strictEqual(signal, null);
2727
});

0 commit comments

Comments
 (0)