| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6cf8dd9 commit 92734d4
54 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,5 +8,7 @@ tools/lint-md/lint-md.mjs | |||
| 8 | 8 | benchmark/tmp | |
| 9 | 9 | benchmark/fixtures | |
| 10 | 10 | doc/**/*.js | |
| 11 | + doc/changelogs/CHANGELOG_v1*.md | ||
| 12 | + !doc/changelogs/CHANGELOG_v18.md | ||
| 11 | 13 | !doc/api_assets/*.js | |
| 12 | 14 | !.eslintrc.js | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ const hacks = [ | |||
| 18 | 18 | 'eslint-plugin-jsdoc', | |
| 19 | 19 | 'eslint-plugin-markdown', | |
| 20 | 20 | '@babel/eslint-parser', | |
| 21 | - '@babel/plugin-syntax-import-assertions', | ||
| 21 | + '@babel/plugin-syntax-import-attributes', | ||
| 22 | 22 | ]; | |
| 23 | 23 | Module._findPath = (request, paths, isMain) => { | |
| 24 | 24 | const r = ModuleFindPath(request, paths, isMain); | |
@@ -44,7 +44,10 @@ module.exports = { | |||
| 44 | 44 | parserOptions: { | |
| 45 | 45 | babelOptions: { | |
| 46 | 46 | plugins: [ | |
| 47 | - Module._findPath('@babel/plugin-syntax-import-assertions'), | ||
| 47 | + [ | ||
| 48 | + Module._findPath('@babel/plugin-syntax-import-attributes'), | ||
| 49 | + { deprecatedAssertSyntax: true }, | ||
| 50 | + ], | ||
| 48 | 51 | ], | |
| 49 | 52 | }, | |
| 50 | 53 | requireConfigFile: false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1762,7 +1762,8 @@ added: | |||
| 1762 | 1762 | - v16.14.0 | |
| 1763 | 1763 | --> | |
| 1764 | 1764 | ||
| 1765 | - An import assertion has failed, preventing the specified module to be imported. | ||
| 1765 | + An import `type` attribute was provided, but the specified module is of a | ||
| 1766 | + different type. | ||
| 1766 | 1767 | ||
| 1767 | 1768 | <a id="ERR_IMPORT_ASSERTION_TYPE_MISSING"></a> | |
| 1768 | 1769 | ||
@@ -1774,7 +1775,7 @@ added: | |||
| 1774 | 1775 | - v16.14.0 | |
| 1775 | 1776 | --> | |
| 1776 | 1777 | ||
| 1777 | - An import assertion is missing, preventing the specified module to be imported. | ||
| 1778 | + An import attribute is missing, preventing the specified module to be imported. | ||
| 1778 | 1779 | ||
| 1779 | 1780 | <a id="ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED"></a> | |
| 1780 | 1781 | ||
@@ -1786,7 +1787,17 @@ added: | |||
| 1786 | 1787 | - v16.14.0 | |
| 1787 | 1788 | --> | |
| 1788 | 1789 | ||
| 1789 | - An import assertion is not supported by this version of Node.js. | ||
| 1790 | + An import attribute is not supported by this version of Node.js. | ||
| 1791 | + | ||
| 1792 | + <a id="ERR_IMPORT_ATTRIBUTE_UNSUPPORTED"></a> | ||
| 1793 | + | ||
| 1794 | + ### `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` | ||
| 1795 | + | ||
| 1796 | + <!-- YAML | ||
| 1797 | + added: REPLACEME | ||
| 1798 | + --> | ||
| 1799 | + | ||
| 1800 | + An import attribute is not supported by this version of Node.js. | ||
| 1790 | 1801 | ||
| 1791 | 1802 | <a id="ERR_INCOMPATIBLE_OPTION_PAIR"></a> | |
| 1792 | 1803 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ changes: | |||
| 18 | 18 | - v17.1.0 | |
| 19 | 19 | - v16.14.0 | |
| 20 | 20 | pr-url: https://github.com/nodejs/node/pull/40250 | |
| 21 | - description: Add support for import assertions. | ||
| 21 | + description: Add experimental support for import assertions. | ||
| 22 | 22 | - version: | |
| 23 | 23 | - v17.0.0 | |
| 24 | 24 | - v16.12.0 | |
@@ -234,17 +234,28 @@ absolute URL strings. | |||
| 234 | 234 | import fs from 'node:fs/promises'; | |
| 235 | 235 | ``` | |
| 236 | 236 | ||
| 237 | - ## Import assertions | ||
| 237 | + <a id="import-assertions"></a> | ||
| 238 | + | ||
| 239 | + ## Import attributes | ||
| 238 | 240 | ||
| 239 | 241 | <!-- YAML | |
| 240 | 242 | added: | |
| 241 | 243 | - v17.1.0 | |
| 242 | 244 | - v16.14.0 | |
| 245 | + changes: | ||
| 246 | + - version: REPLACEME | ||
| 247 | + pr-url: https://github.com/nodejs/node/pull/50140 | ||
| 248 | + description: Switch from Import Assertions to Import Attributes. | ||
| 243 | 249 | --> | |
| 244 | 250 | ||
| 245 | - > Stability: 1 - Experimental | ||
| 251 | + > Stability: 1.1 - Active development | ||
| 252 | + | ||
| 253 | + > 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. | ||
| 246 | 257 | ||
| 247 | - The [Import Assertions proposal][] adds an inline syntax for module import | ||
| 258 | + The [Import Attributes proposal][] adds an inline syntax for module import | ||
| 248 | 259 | statements to pass on more information alongside the module specifier. | |
| 249 | 260 | ||
| 250 | 261 | ```js | |
@@ -254,10 +265,10 @@ const { default: barData } = | |||
| 254 | 265 | await import('./bar.json', { assert: { type: 'json' } }); | |
| 255 | 266 | ``` | |
| 256 | 267 | ||
| 257 | - Node.js supports the following `type` values, for which the assertion is | ||
| 268 | + Node.js supports the following `type` values, for which the attribute is | ||
| 258 | 269 | mandatory: | |
| 259 | 270 | ||
| 260 | - | Assertion `type` | Needed for | | ||
| 271 | + | Attribute `type` | Needed for | | ||
| 261 | 272 | | ---------------- | ---------------- | | |
| 262 | 273 | | `'json'` | [JSON modules][] | | |
| 263 | 274 | ||
@@ -547,7 +558,7 @@ JSON files can be referenced by `import`: | |||
| 547 | 558 | import packageConfig from './package.json' assert { type: 'json' }; | |
| 548 | 559 | ``` | |
| 549 | 560 | ||
| 550 | - The `assert { type: 'json' }` syntax is mandatory; see [Import Assertions][]. | ||
| 561 | + The `assert { type: 'json' }` syntax is mandatory; see [Import Attributes][]. | ||
| 551 | 562 | ||
| 552 | 563 | The imported JSON only exposes a `default` export. There is no support for named | |
| 553 | 564 | exports. A cache entry is created in the CommonJS cache to avoid duplication. | |
@@ -1076,8 +1087,8 @@ success! | |||
| 1076 | 1087 | [Determining module system]: packages.md#determining-module-system | |
| 1077 | 1088 | [Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import | |
| 1078 | 1089 | [ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration | |
| 1079 | - [Import Assertions]: #import-assertions | ||
| 1080 | - [Import Assertions proposal]: https://github.com/tc39/proposal-import-assertions | ||
| 1090 | + [Import Attributes]: #import-attributes | ||
| 1091 | + [Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes | ||
| 1081 | 1092 | [JSON modules]: #json-modules | |
| 1082 | 1093 | [Module customization hooks]: module.md#customization-hooks | |
| 1083 | 1094 | [Node.js Module Resolution And Loading Algorithm]: #resolution-algorithm-specification | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -456,6 +456,11 @@ register('./path-to-my-hooks.js', { | |||
| 456 | 456 | ||
| 457 | 457 | <!-- YAML | |
| 458 | 458 | changes: | |
| 459 | + - version: REPLACEME | ||
| 460 | + pr-url: https://github.com/nodejs/node/pull/50140 | ||
| 461 | + description: The property `context.importAssertions` is replaced with | ||
| 462 | + `context.importAttributes`. Using the old name is still | ||
| 463 | + supported and will emit an experimental warning. | ||
| 459 | 464 | - version: | |
| 460 | 465 | - v18.6.0 | |
| 461 | 466 | - v16.17.0 | |
@@ -475,8 +480,8 @@ changes: | |||
| 475 | 480 | * `specifier` {string} | |
| 476 | 481 | * `context` {Object} | |
| 477 | 482 | * `conditions` {string\[]} Export conditions of the relevant `package.json` | |
| 478 | - * `importAssertions` {Object} An object whose key-value pairs represent the | ||
| 479 | - assertions for the module to import | ||
| 483 | + * `importAttributes` {Object} An object whose key-value pairs represent the | ||
| 484 | + attributes for the module to import | ||
| 480 | 485 | * `parentURL` {string|undefined} The module importing this one, or undefined | |
| 481 | 486 | if this is the Node.js entry point | |
| 482 | 487 | * `nextResolve` {Function} The subsequent `resolve` hook in the chain, or the | |
@@ -487,7 +492,7 @@ changes: | |||
| 487 | 492 | * `format` {string|null|undefined} A hint to the load hook (it might be | |
| 488 | 493 | ignored) | |
| 489 | 494 | `'builtin' | 'commonjs' | 'json' | 'module' | 'wasm'` | |
| 490 | - * `importAssertions` {Object|undefined} The import assertions to use when | ||
| 495 | + * `importAttributes` {Object|undefined} The import attributes to use when | ||
| 491 | 496 | caching the module (optional; if excluded the input will be used) | |
| 492 | 497 | * `shortCircuit` {undefined|boolean} A signal that this hook intends to | |
| 493 | 498 | terminate the chain of `resolve` hooks. **Default:** `false` | |
@@ -504,10 +509,10 @@ the final `format` value (and it is free to ignore the hint provided by | |||
| 504 | 509 | `resolve`); if `resolve` provides a `format`, a custom `load` hook is required | |
| 505 | 510 | even if only to pass the value to the Node.js default `load` hook. | |
| 506 | 511 | ||
| 507 | - Import type assertions are part of the cache key for saving loaded modules into | ||
| 512 | + Import type attributes are part of the cache key for saving loaded modules into | ||
| 508 | 513 | the internal module cache. The `resolve` hook is responsible for returning an | |
| 509 | - `importAssertions` object if the module should be cached with different | ||
| 510 | - assertions than were present in the source code. | ||
| 514 | + `importAttributes` object if the module should be cached with different | ||
| 515 | + attributes than were present in the source code. | ||
| 511 | 516 | ||
| 512 | 517 | The `conditions` property in `context` is an array of conditions for | |
| 513 | 518 | [package exports conditions][Conditional exports] that apply to this resolution | |
@@ -570,7 +575,7 @@ changes: | |||
| 570 | 575 | * `conditions` {string\[]} Export conditions of the relevant `package.json` | |
| 571 | 576 | * `format` {string|null|undefined} The format optionally supplied by the | |
| 572 | 577 | `resolve` hook chain | |
| 573 | - * `importAssertions` {Object} | ||
| 578 | + * `importAttributes` {Object} | ||
| 574 | 579 | * `nextLoad` {Function} The subsequent `load` hook in the chain, or the | |
| 575 | 580 | Node.js default `load` hook after the last user-supplied `load` hook | |
| 576 | 581 | * `specifier` {string} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1177,12 +1177,17 @@ E('ERR_HTTP_SOCKET_ENCODING', | |||
| 1177 | 1177 | E('ERR_HTTP_TRAILER_INVALID', | |
| 1178 | 1178 | 'Trailers are invalid with this transfer encoding', Error); | |
| 1179 | 1179 | E('ERR_ILLEGAL_CONSTRUCTOR', 'Illegal constructor', TypeError); | |
| 1180 | + // TODO(aduh95): change the error to mention import attributes instead of import assertions. | ||
| 1180 | 1181 | E('ERR_IMPORT_ASSERTION_TYPE_FAILED', | |
| 1181 | 1182 | 'Module "%s" is not of type "%s"', TypeError); | |
| 1183 | + // TODO(aduh95): change the error to mention import attributes instead of import assertions. | ||
| 1182 | 1184 | E('ERR_IMPORT_ASSERTION_TYPE_MISSING', | |
| 1183 | - 'Module "%s" needs an import assertion of type "%s"', TypeError); | ||
| 1185 | + 'Module "%s" needs an import attribute of type "%s"', TypeError); | ||
| 1186 | + // TODO(aduh95): change the error to mention import attributes instead of import assertions. | ||
| 1184 | 1187 | E('ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED', | |
| 1185 | - 'Import assertion type "%s" is unsupported', TypeError); | ||
| 1188 | + 'Import attribute type "%s" is unsupported', TypeError); | ||
| 1189 | + E('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', | ||
| 1190 | + 'Import attribute "%s" with value "%s" is not supported', TypeError); | ||
| 1186 | 1191 | E('ERR_INCOMPATIBLE_OPTION_PAIR', | |
| 1187 | 1192 | 'Option "%s" cannot be used in combination with option "%s"', TypeError); | |
| 1188 | 1193 | E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1253,10 +1253,10 @@ function wrapSafe(filename, content, cjsModuleInstance) { | |||
| 1253 | 1253 | const script = new Script(wrapper, { | |
| 1254 | 1254 | filename, | |
| 1255 | 1255 | lineOffset: 0, | |
| 1256 | - importModuleDynamically: async (specifier, _, importAssertions) => { | ||
| 1256 | + importModuleDynamically: async (specifier, _, importAttributes) => { | ||
| 1257 | 1257 | const cascadedLoader = getCascadedLoader(); | |
| 1258 | 1258 | return cascadedLoader.import(specifier, normalizeReferrerURL(filename), | |
| 1259 | - importAssertions); | ||
| 1259 | + importAttributes); | ||
| 1260 | 1260 | }, | |
| 1261 | 1261 | }); | |
| 1262 | 1262 | ||
@@ -1279,10 +1279,10 @@ function wrapSafe(filename, content, cjsModuleInstance) { | |||
| 1279 | 1279 | '__dirname', | |
| 1280 | 1280 | ], { | |
| 1281 | 1281 | filename, | |
| 1282 | - importModuleDynamically(specifier, _, importAssertions) { | ||
| 1282 | + importModuleDynamically(specifier, _, importAttributes) { | ||
| 1283 | 1283 | const cascadedLoader = getCascadedLoader(); | |
| 1284 | 1284 | return cascadedLoader.import(specifier, normalizeReferrerURL(filename), | |
| 1285 | - importAssertions); | ||
| 1285 | + importAttributes); | ||
| 1286 | 1286 | }, | |
| 1287 | 1287 | }); | |
| 1288 | 1288 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | ArrayPrototypeFilter, | |
| 5 | 5 | ArrayPrototypeIncludes, | |
| 6 | - ObjectCreate, | ||
| 7 | 6 | ObjectKeys, | |
| 8 | 7 | ObjectValues, | |
| 9 | 8 | ObjectPrototypeHasOwnProperty, | |
@@ -14,16 +13,15 @@ const { | |||
| 14 | 13 | ERR_IMPORT_ASSERTION_TYPE_FAILED, | |
| 15 | 14 | ERR_IMPORT_ASSERTION_TYPE_MISSING, | |
| 16 | 15 | ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED, | |
| 16 | + ERR_IMPORT_ATTRIBUTE_UNSUPPORTED, | ||
| 17 | 17 | } = require('internal/errors').codes; | |
| 18 | 18 | ||
| 19 | 19 | // The HTML spec has an implied default type of `'javascript'`. | |
| 20 | 20 | const kImplicitAssertType = 'javascript'; | |
| 21 | 21 | ||
| 22 | - let alreadyWarned = false; | ||
| 23 | - | ||
| 24 | 22 | /** | |
| 25 | - * Define a map of module formats to import assertion types (the value of | ||
| 26 | - * `type` in `assert { type: 'json' }`). | ||
| 23 | + * Define a map of module formats to import attributes types (the value of | ||
| 24 | + * `type` in `with { type: 'json' }`). | ||
| 27 | 25 | * @type {Map<string, string>} | |
| 28 | 26 | */ | |
| 29 | 27 | const formatTypeMap = { | |
@@ -32,13 +30,13 @@ const formatTypeMap = { | |||
| 32 | 30 | 'commonjs': kImplicitAssertType, | |
| 33 | 31 | 'json': 'json', | |
| 34 | 32 | 'module': kImplicitAssertType, | |
| 35 | - 'wasm': kImplicitAssertType, // It's unclear whether the HTML spec will require an assertion type or not for Wasm; see https://github.com/WebAssembly/esm-integration/issues/42 | ||
| 33 | + 'wasm': kImplicitAssertType, // It's unclear whether the HTML spec will require an attribute type or not for Wasm; see https://github.com/WebAssembly/esm-integration/issues/42 | ||
| 36 | 34 | }; | |
| 37 | 35 | ||
| 38 | 36 | /** | |
| 39 | 37 | * The HTML spec disallows the default type to be explicitly specified | |
| 40 | 38 | * (for now); so `import './file.js'` is okay but | |
| 41 | - * `import './file.js' assert { type: 'javascript' }` throws. | ||
| 39 | + * `import './file.js' with { type: 'javascript' }` throws. | ||
| 42 | 40 | * @type {Array<string, string>} | |
| 43 | 41 | */ | |
| 44 | 42 | const supportedAssertionTypes = ArrayPrototypeFilter( | |
@@ -47,54 +45,50 @@ const supportedAssertionTypes = ArrayPrototypeFilter( | |||
| 47 | 45 | ||
| 48 | 46 | ||
| 49 | 47 | /** | |
| 50 | - * Test a module's import assertions. | ||
| 48 | + * Test a module's import attributes. | ||
| 51 | 49 | * @param {string} url The URL of the imported module, for error reporting. | |
| 52 | 50 | * @param {string} format One of Node's supported translators | |
| 53 | - * @param {Record<string, string>} importAssertions Validations for the | ||
| 51 | + * @param {Record<string, string>} importAttributes Validations for the | ||
| 54 | 52 | * module import. | |
| 55 | 53 | * @returns {true} | |
| 56 | 54 | * @throws {TypeError} If the format and assertion type are incompatible. | |
| 57 | 55 | */ | |
| 58 | - function validateAssertions(url, format, | ||
| 59 | - importAssertions = ObjectCreate(null)) { | ||
| 60 | - const validType = formatTypeMap[format]; | ||
| 61 | - | ||
| 62 | - if (!alreadyWarned && ObjectKeys(importAssertions).length !== 0) { | ||
| 63 | - alreadyWarned = true; | ||
| 64 | - process.emitWarning( | ||
| 65 | - 'Import assertions are not a stable feature of the JavaScript language. ' + | ||
| 66 | - 'Avoid relying on their current behavior and syntax as those might change ' + | ||
| 67 | - 'in a future version of Node.js.', | ||
| 68 | - 'ExperimentalWarning', | ||
| 69 | - ); | ||
| 56 | + function validateAttributes(url, format, | ||
| 57 | + importAttributes = { __proto__: null }) { | ||
| 58 | + const keys = ObjectKeys(importAttributes); | ||
| 59 | + for (let i = 0; i < keys.length; i++) { | ||
| 60 | + if (keys[i] !== 'type') { | ||
| 61 | + throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED(keys[i], importAttributes[keys[i]]); | ||
| 62 | + } | ||
| 70 | 63 | } | |
| 64 | + const validType = formatTypeMap[format]; | ||
| 71 | 65 | ||
| 72 | 66 | switch (validType) { | |
| 73 | 67 | case undefined: | |
| 74 | - // Ignore assertions for module formats we don't recognize, to allow new | ||
| 68 | + // Ignore attributes for module formats we don't recognize, to allow new | ||
| 75 | 69 | // formats in the future. | |
| 76 | 70 | return true; | |
| 77 | 71 | ||
| 78 | 72 | case kImplicitAssertType: | |
| 79 | 73 | // This format doesn't allow an import assertion type, so the property | |
| 80 | - // must not be set on the import assertions object. | ||
| 81 | - if (!ObjectPrototypeHasOwnProperty(importAssertions, 'type')) { | ||
| 74 | + // must not be set on the import attributes object. | ||
| 75 | + if (!ObjectPrototypeHasOwnProperty(importAttributes, 'type')) { | ||
| 82 | 76 | return true; | |
| 83 | 77 | } | |
| 84 | - return handleInvalidType(url, importAssertions.type); | ||
| 78 | + return handleInvalidType(url, importAttributes.type); | ||
| 85 | 79 | ||
| 86 | - case importAssertions.type: | ||
| 80 | + case importAttributes.type: | ||
| 87 | 81 | // The asserted type is the valid type for this format. | |
| 88 | 82 | return true; | |
| 89 | 83 | ||
| 90 | 84 | default: | |
| 91 | 85 | // There is an expected type for this format, but the value of | |
| 92 | - // `importAssertions.type` might not have been it. | ||
| 93 | - if (!ObjectPrototypeHasOwnProperty(importAssertions, 'type')) { | ||
| 86 | + // `importAttributes.type` might not have been it. | ||
| 87 | + if (!ObjectPrototypeHasOwnProperty(importAttributes, 'type')) { | ||
| 94 | 88 | // `type` wasn't specified at all. | |
| 95 | 89 | throw new ERR_IMPORT_ASSERTION_TYPE_MISSING(url, validType); | |
| 96 | 90 | } | |
| 97 | - return handleInvalidType(url, importAssertions.type); | ||
| 91 | + return handleInvalidType(url, importAttributes.type); | ||
| 98 | 92 | } | |
| 99 | 93 | } | |
| 100 | 94 | ||
@@ -119,5 +113,5 @@ function handleInvalidType(url, type) { | |||
| 119 | 113 | ||
| 120 | 114 | module.exports = { | |
| 121 | 115 | kImplicitAssertType, | |
| 122 | - validateAssertions, | ||
| 116 | + validateAttributes, | ||
| 123 | 117 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments