Skip to content

Commit 030f155

Browse files
nicolo-ribaudomarco-ippolito
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> Backport-PR-URL: #55961
1 parent 3c4262a commit 030f155

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
@@ -262,13 +262,9 @@ changes:
262262
description: Switch from Import Assertions to Import Attributes.
263263
-->
264264

265-
> Stability: 1.1 - Active development
266-
267-
> This feature was previously named "Import assertions", and using the `assert`
268-
> keyword instead of `with`. Any uses in code of the prior `assert` keyword
269-
> should be updated to use `with` instead.
265+
> Stability: 2 - Stable
270266
271-
The [Import Attributes proposal][] adds an inline syntax for module import
267+
[Import attributes][Import Attributes MDN] are an inline syntax for module import
272268
statements to pass on more information alongside the module specifier.
273269

274270
```js
@@ -278,13 +274,14 @@ const { default: barData } =
278274
await import('./bar.json', { with: { type: 'json' } });
279275
```
280276

281-
Node.js supports the following `type` values, for which the attribute is
282-
mandatory:
277+
Node.js only supports the `type` attribute, for which it supports the following values:
283278

284279
| Attribute `type` | Needed for |
285280
| ---------------- | ---------------- |
286281
| `'json'` | [JSON modules][] |
287282

283+
The `type: 'json'` attribute is mandatory when importing JSON modules.
284+
288285
## Built-in modules
289286

290287
[Built-in modules][] provide named exports of their public API. A
@@ -591,7 +588,7 @@ separate cache.
591588
592589
## JSON modules
593590
594-
> Stability: 1 - Experimental
591+
> Stability: 2 - Stable
595592
596593
JSON files can be referenced by `import`:
597594
@@ -1129,7 +1126,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
11291126
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
11301127
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
11311128
[Import Attributes]: #import-attributes
1132-
[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes
1129+
[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
11331130
[JSON modules]: #json-modules
11341131
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
11351132
[Module customization hooks]: module.md#customization-hooks

lib/internal/modules/esm/translators.js

-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ translators.set('builtin', function builtinStrategy(url) {
450450
// Strategy for loading a JSON file
451451
const isWindows = process.platform === 'win32';
452452
translators.set('json', function jsonStrategy(url, source) {
453-
emitExperimentalWarning('Importing JSON modules');
454453
assertBufferSource(source, true, 'load');
455454
debug(`Loading JSONModule ${url}`);
456455
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)