Skip to content

Commit 9dd828a

Browse files
bmeckdanielleadams
authored andcommitted
esm: improve typings and code coverage
PR-URL: #42305 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent b26a9a6 commit 9dd828a

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

lib/internal/modules/esm/formats.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ if (experimentalWasmModules) {
2929
extensionFormatMap['.wasm'] = legacyExtensionFormatMap['.wasm'] = 'wasm';
3030
}
3131

32+
/**
33+
* @param {string} mime
34+
* @returns {string | null}
35+
*/
3236
function mimeToFormat(mime) {
3337
if (
3438
RegExpPrototypeTest(

lib/internal/modules/esm/get_format.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ function getDataProtocolModuleFormat(parsed) {
4141
return mimeToFormat(mime);
4242
}
4343

44+
/**
45+
* @param {URL} url
46+
* @param {{parentURL: string}} context
47+
* @param {boolean} ignoreErrors
48+
* @returns {string}
49+
*/
4450
function getFileProtocolModuleFormat(url, context, ignoreErrors) {
4551
const ext = extname(url.pathname);
4652
if (ext === '.js') {
@@ -59,6 +65,11 @@ function getFileProtocolModuleFormat(url, context, ignoreErrors) {
5965
return getLegacyExtensionFormat(ext) ?? null;
6066
}
6167

68+
/**
69+
* @param {URL} url
70+
* @param {{parentURL: string}} context
71+
* @returns {Promise<string> | undefined} only works when enabled
72+
*/
6273
function getHttpProtocolModuleFormat(url, context) {
6374
if (experimentalNetworkImports) {
6475
return PromisePrototypeThen(
@@ -70,13 +81,23 @@ function getHttpProtocolModuleFormat(url, context) {
7081
}
7182
}
7283

84+
/**
85+
* @param {URL | URL['href']} url
86+
* @param {{parentURL: string}} context
87+
* @returns {Promise<string> | string | undefined} only works when enabled
88+
*/
7389
function defaultGetFormatWithoutErrors(url, context) {
7490
const parsed = new URL(url);
7591
if (!ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol))
7692
return null;
7793
return protocolHandlers[parsed.protocol](parsed, context, true);
7894
}
7995

96+
/**
97+
* @param {URL | URL['href']} url
98+
* @param {{parentURL: string}} context
99+
* @returns {Promise<string> | string | undefined} only works when enabled
100+
*/
80101
function defaultGetFormat(url, context) {
81102
const parsed = new URL(url);
82103
return ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol) ?

lib/internal/modules/esm/resolve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const DEFAULT_CONDITIONS_SET = new SafeSet(DEFAULT_CONDITIONS);
7979
* @typedef {string | string[] | Record<string, unknown>} Exports
8080
* @typedef {'module' | 'commonjs'} PackageType
8181
* @typedef {{
82+
* pjsonPath: string,
8283
* exports?: ExportConfig;
8384
* name?: string;
8485
* main?: string;
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import '../common/index.mjs';
22
import assert from 'assert';
33
import ok from '../fixtures/es-modules/test-esm-ok.mjs';
4-
import okShebang from './test-esm-shebang.mjs';
4+
import * as okShebangNs from './test-esm-shebang.mjs';
5+
// encode the '.'
6+
import * as okShebangPercentNs from './test-esm-shebang%2emjs';
57

68
assert(ok);
7-
assert(okShebang);
9+
assert(okShebangNs.default);
10+
assert.strict.equal(okShebangNs, okShebangPercentNs);

0 commit comments

Comments
 (0)