Skip to content

Commit 879679e

Browse files
committed
lib,doc: replace references to import assertions
Use "import attributes" and "type attribute" instead. PR-URL: #52998 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent d87f9af commit 879679e

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

doc/api/module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ changes:
611611
612612
The `load` hook provides a way to define a custom method of determining how a
613613
URL should be interpreted, retrieved, and parsed. It is also in charge of
614-
validating the import assertion.
614+
validating the import attributes.
615615
616616
The final value of `format` must be one of the following:
617617

doc/api/packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ There is the ECMAScript module loader:
148148
`'./startup/index.js'`) must be fully specified.
149149
* It does no extension searching. A file extension must be provided
150150
when the specifier is a relative or absolute file URL.
151-
* It can load JSON modules, but an import assertion is required.
151+
* It can load JSON modules, but an import type attribute is required.
152152
* It accepts only `.js`, `.mjs`, and `.cjs` extensions for JavaScript text
153153
files.
154154
* It can be used to load JavaScript CommonJS modules. Such modules

lib/internal/modules/esm/assert.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
} = require('internal/errors').codes;
1717

1818
// The HTML spec has an implied default type of `'javascript'`.
19-
const kImplicitAssertType = 'javascript';
19+
const kImplicitTypeAttribute = 'javascript';
2020

2121
/**
2222
* Define a map of module formats to import attributes types (the value of
@@ -25,11 +25,11 @@ const kImplicitAssertType = 'javascript';
2525
*/
2626
const formatTypeMap = {
2727
'__proto__': null,
28-
'builtin': kImplicitAssertType,
29-
'commonjs': kImplicitAssertType,
28+
'builtin': kImplicitTypeAttribute,
29+
'commonjs': kImplicitTypeAttribute,
3030
'json': 'json',
31-
'module': kImplicitAssertType,
32-
'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
31+
'module': kImplicitTypeAttribute,
32+
'wasm': kImplicitTypeAttribute, // It's unclear whether the HTML spec will require an type attribute or not for Wasm; see https://github.com/WebAssembly/esm-integration/issues/42
3333
};
3434

3535
/**
@@ -38,9 +38,9 @@ const formatTypeMap = {
3838
* `import './file.js' with { type: 'javascript' }` throws.
3939
* @type {Array<string, string>}
4040
*/
41-
const supportedAssertionTypes = ArrayPrototypeFilter(
41+
const supportedTypeAttributes = ArrayPrototypeFilter(
4242
ObjectValues(formatTypeMap),
43-
(type) => type !== kImplicitAssertType);
43+
(type) => type !== kImplicitTypeAttribute);
4444

4545

4646
/**
@@ -50,7 +50,7 @@ const supportedAssertionTypes = ArrayPrototypeFilter(
5050
* @param {Record<string, string>} importAttributes Validations for the
5151
* module import.
5252
* @returns {true}
53-
* @throws {TypeError} If the format and assertion type are incompatible.
53+
* @throws {TypeError} If the format and type attribute are incompatible.
5454
*/
5555
function validateAttributes(url, format,
5656
importAttributes = { __proto__: null }) {
@@ -68,16 +68,16 @@ function validateAttributes(url, format,
6868
// formats in the future.
6969
return true;
7070

71-
case kImplicitAssertType:
72-
// This format doesn't allow an import assertion type, so the property
71+
case kImplicitTypeAttribute:
72+
// This format doesn't allow an import type attribute, so the property
7373
// must not be set on the import attributes object.
7474
if (!ObjectPrototypeHasOwnProperty(importAttributes, 'type')) {
7575
return true;
7676
}
7777
return handleInvalidType(url, importAttributes.type);
7878

7979
case importAttributes.type:
80-
// The asserted type is the valid type for this format.
80+
// The type attribute is the valid type for this format.
8181
return true;
8282

8383
default:
@@ -92,16 +92,16 @@ function validateAttributes(url, format,
9292
}
9393

9494
/**
95-
* Throw the correct error depending on what's wrong with the type assertion.
95+
* Throw the correct error depending on what's wrong with the type attribute.
9696
* @param {string} url The resolved URL for the module to be imported
97-
* @param {string} type The value of the import assertion `type` property
97+
* @param {string} type The value of the import attributes' `type` property
9898
*/
9999
function handleInvalidType(url, type) {
100100
// `type` might have not been a string.
101101
validateString(type, 'type');
102102

103103
// `type` might not have been one of the types we understand.
104-
if (!ArrayPrototypeIncludes(supportedAssertionTypes, type)) {
104+
if (!ArrayPrototypeIncludes(supportedTypeAttributes, type)) {
105105
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type);
106106
}
107107

@@ -111,6 +111,6 @@ function handleInvalidType(url, type) {
111111

112112

113113
module.exports = {
114-
kImplicitAssertType,
114+
kImplicitTypeAttribute,
115115
validateAttributes,
116116
};

lib/internal/modules/esm/loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const {
3535
compileSourceTextModule,
3636
getDefaultConditions,
3737
} = require('internal/modules/esm/utils');
38-
const { kImplicitAssertType } = require('internal/modules/esm/assert');
38+
const { kImplicitTypeAttribute } = require('internal/modules/esm/assert');
3939
const { canParse } = internalBinding('url');
4040
const { ModuleWrap, kEvaluating, kEvaluated } = internalBinding('module_wrap');
4141
const {
@@ -276,7 +276,7 @@ class ModuleLoader {
276276
*/
277277
importSyncForRequire(mod, filename, source, isMain, parent) {
278278
const url = pathToFileURL(filename).href;
279-
let job = this.loadCache.get(url, kImplicitAssertType);
279+
let job = this.loadCache.get(url, kImplicitTypeAttribute);
280280
// This module job is already created:
281281
// 1. If it was loaded by `require()` before, at this point the instantiation
282282
// is already completed and we can check the whether it is in a cycle
@@ -307,7 +307,7 @@ class ModuleLoader {
307307

308308
const { ModuleJobSync } = require('internal/modules/esm/module_job');
309309
job = new ModuleJobSync(this, url, kEmptyObject, wrap, isMain, inspectBrk);
310-
this.loadCache.set(url, kImplicitAssertType, job);
310+
this.loadCache.set(url, kImplicitTypeAttribute, job);
311311
mod[kRequiredModuleSymbol] = job.module;
312312
return job.runSync().namespace;
313313
}

lib/internal/modules/esm/module_map.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {
88
ObjectKeys,
99
SafeMap,
1010
} = primordials;
11-
const { kImplicitAssertType } = require('internal/modules/esm/assert');
11+
const { kImplicitTypeAttribute } = require('internal/modules/esm/assert');
1212
let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
1313
debug = fn;
1414
});
@@ -88,12 +88,12 @@ class ResolveCache extends SafeMap {
8888
*/
8989
class LoadCache extends SafeMap {
9090
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
91-
get(url, type = kImplicitAssertType) {
91+
get(url, type = kImplicitTypeAttribute) {
9292
validateString(url, 'url');
9393
validateString(type, 'type');
9494
return super.get(url)?.[type];
9595
}
96-
set(url, type = kImplicitAssertType, job) {
96+
set(url, type = kImplicitTypeAttribute, job) {
9797
validateString(url, 'url');
9898
validateString(type, 'type');
9999

@@ -103,18 +103,18 @@ class LoadCache extends SafeMap {
103103
throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob', job);
104104
}
105105
debug(`Storing ${url} (${
106-
type === kImplicitAssertType ? 'implicit type' : type
106+
type === kImplicitTypeAttribute ? 'implicit type' : type
107107
}) in ModuleLoadMap`);
108108
const cachedJobsForUrl = super.get(url) ?? { __proto__: null };
109109
cachedJobsForUrl[type] = job;
110110
return super.set(url, cachedJobsForUrl);
111111
}
112-
has(url, type = kImplicitAssertType) {
112+
has(url, type = kImplicitTypeAttribute) {
113113
validateString(url, 'url');
114114
validateString(type, 'type');
115115
return super.get(url)?.[type] !== undefined;
116116
}
117-
delete(url, type = kImplicitAssertType) {
117+
delete(url, type = kImplicitTypeAttribute) {
118118
const cached = super.get(url);
119119
if (cached) {
120120
cached[type] = undefined;

0 commit comments

Comments
 (0)