Skip to content

Commit ac37e55

Browse files
nicolo-ribaudoaduh95
authored andcommittedNov 2, 2024··
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 fce3ab6 commit ac37e55

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed
 

Diff for: ‎doc/api/esm.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,10 @@ changes:
251251
description: Switch from Import Assertions to Import Attributes.
252252
-->
253253

254-
> Stability: 1.1 - Active development
255-
256-
> This feature was previously named "Import assertions", and using the `assert`
257-
> keyword instead of `with`. Any uses in code of the prior `assert` keyword
258-
> should be updated to use `with` instead.
254+
> Stability: 2 - Stable
259255
260-
The [Import Attributes proposal][] adds an inline syntax for module import
261-
statements to pass on more information alongside the module specifier.
256+
[Import attributes][Import Attributes MDN] are an inline syntax for module
257+
import statements to pass on more information alongside the module specifier.
262258

263259
```js
264260
import fooData from './foo.json' with { type: 'json' };
@@ -267,13 +263,15 @@ const { default: barData } =
267263
await import('./bar.json', { with: { type: 'json' } });
268264
```
269265

270-
Node.js supports the following `type` values, for which the attribute is
271-
mandatory:
266+
Node.js only supports the `type` attribute, for which it supports the following
267+
values:
272268

273269
| Attribute `type` | Needed for |
274270
| ---------------- | ---------------- |
275271
| `'json'` | [JSON modules][] |
276272

273+
The `type: 'json'` attribute is mandatory when importing JSON modules.
274+
277275
## Builtin modules
278276

279277
[Core modules][] provide named exports of their public API. A
@@ -552,7 +550,7 @@ separate cache.
552550

553551
## JSON modules
554552

555-
> Stability: 1 - Experimental
553+
> Stability: 2 - Stable
556554

557555
JSON files can be referenced by `import`:
558556

@@ -1090,7 +1088,7 @@ success!
10901088
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
10911089
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
10921090
[Import Attributes]: #import-attributes
1093-
[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes
1091+
[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
10941092
[JSON modules]: #json-modules
10951093
[Module customization hooks]: module.md#customization-hooks
10961094
[Node.js Module Resolution And Loading Algorithm]: #resolution-algorithm-specification

Diff for: ‎lib/internal/modules/esm/translators.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ translators.set('builtin', async function builtinStrategy(url) {
304304
});
305305

306306
// Strategy for loading a JSON file
307-
translators.set('json', async function jsonStrategy(url, source) {
308-
emitExperimentalWarning('Importing JSON modules');
307+
translators.set('json', function jsonStrategy(url, source) {
309308
assertBufferSource(source, true, 'load');
310309
debug(`Loading JSONModule ${url}`);
311310
const pathname = StringPrototypeStartsWith(url, 'file:') ?

Diff for: ‎test/es-module/test-esm-json.mjs

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.