Skip to content

Commit 48bb87b

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 055d2b8 commit 48bb87b

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

doc/api/esm.md

Lines changed: 7 additions & 10 deletions
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
@@ -631,7 +628,7 @@ separate cache.
631628
632629
## JSON modules
633630
634-
> Stability: 1 - Experimental
631+
> Stability: 2 - Stable
635632
636633
JSON files can be referenced by `import`:
637634
@@ -1101,7 +1098,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
11011098
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
11021099
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
11031100
[Import Attributes]: #import-attributes
1104-
[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes
1101+
[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with
11051102
[JSON modules]: #json-modules
11061103
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
11071104
[Module customization hooks]: module.md#customization-hooks

lib/internal/modules/esm/translators.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ translators.set('builtin', function builtinStrategy(url) {
365365

366366
// Strategy for loading a JSON file
367367
translators.set('json', function jsonStrategy(url, source) {
368-
emitExperimentalWarning('Importing JSON modules');
369368
assertBufferSource(source, true, 'load');
370369
debug(`Loading JSONModule ${url}`);
371370
const pathname = StringPrototypeStartsWith(url, 'file:') ?

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

Lines changed: 2 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy