|
7 | 7 | <!-- YAML
|
8 | 8 | added: v8.5.0
|
9 | 9 | changes:
|
| 10 | + - version: REPLACEME |
| 11 | + pr-url: https://github.com/nodejs/node/pull/50140 |
| 12 | + description: Add experimental support for import attributes. |
10 | 13 | - version: v18.19.0
|
11 | 14 | pr-url: https://github.com/nodejs/node/pull/44710
|
12 | 15 | description: Module customization hooks are executed off the main thread.
|
@@ -202,7 +205,7 @@ added: v12.10.0
|
202 | 205 |
|
203 | 206 | ```js
|
204 | 207 | import 'data:text/javascript,console.log("hello!");';
|
205 |
| -import _ from 'data:application/json,"world!"' assert { type: 'json' }; |
| 208 | +import _ from 'data:application/json,"world!"' with { type: 'json' }; |
206 | 209 | ```
|
207 | 210 |
|
208 | 211 | `data:` URLs only resolve [bare specifiers][Terminology] for builtin modules
|
@@ -243,26 +246,25 @@ added:
|
243 | 246 | - v17.1.0
|
244 | 247 | - v16.14.0
|
245 | 248 | changes:
|
246 |
| - - version: v18.19.0 |
| 249 | + - version: REPLACEME |
247 | 250 | pr-url: https://github.com/nodejs/node/pull/50140
|
248 | 251 | description: Switch from Import Assertions to Import Attributes.
|
249 | 252 | -->
|
250 | 253 |
|
251 | 254 | > Stability: 1.1 - Active development
|
252 | 255 |
|
253 | 256 | > This feature was previously named "Import assertions", and using the `assert`
|
254 |
| -> keyword instead of `with`. Because the version of V8 on this release line does |
255 |
| -> not support the `with` keyword, you need to keep using `assert` to support |
256 |
| -> this version of Node.js. |
| 257 | +> keyword instead of `with`. Any uses in code of the prior `assert` keyword |
| 258 | +> should be updated to use `with` instead. |
257 | 259 |
|
258 | 260 | The [Import Attributes proposal][] adds an inline syntax for module import
|
259 | 261 | statements to pass on more information alongside the module specifier.
|
260 | 262 |
|
261 | 263 | ```js
|
262 |
| -import fooData from './foo.json' assert { type: 'json' }; |
| 264 | +import fooData from './foo.json' with { type: 'json' }; |
263 | 265 |
|
264 | 266 | const { default: barData } =
|
265 |
| - await import('./bar.json', { assert: { type: 'json' } }); |
| 267 | + await import('./bar.json', { with: { type: 'json' } }); |
266 | 268 | ```
|
267 | 269 |
|
268 | 270 | Node.js supports the following `type` values, for which the attribute is
|
@@ -555,10 +557,10 @@ separate cache.
|
555 | 557 | JSON files can be referenced by `import`:
|
556 | 558 |
|
557 | 559 | ```js
|
558 |
| -import packageConfig from './package.json' assert { type: 'json' }; |
| 560 | +import packageConfig from './package.json' with { type: 'json' }; |
559 | 561 | ```
|
560 | 562 |
|
561 |
| -The `assert { type: 'json' }` syntax is mandatory; see [Import Attributes][]. |
| 563 | +The `with { type: 'json' }` syntax is mandatory; see [Import Attributes][]. |
562 | 564 |
|
563 | 565 | The imported JSON only exposes a `default` export. There is no support for named
|
564 | 566 | exports. A cache entry is created in the CommonJS cache to avoid duplication.
|
|
0 commit comments