Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e17db8f

Browse filesBrowse files
bmeckbengl
authored andcommitted
esm: improve typings and code coverage
PR-URL: #42305 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 08e2d8a commit e17db8f
Copy full SHA for e17db8f

File tree

Expand file treeCollapse file tree

4 files changed

+35
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+35
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/esm/formats.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/formats.js
+4Lines 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(
Collapse file

‎lib/internal/modules/esm/get_format.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/get_format.js
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const protocolHandlers = ObjectAssign(ObjectCreate(null), {
3232
'node:'() { return 'builtin'; },
3333
});
3434

35+
/**
36+
* @param {URL} parsed
37+
* @returns {string | null}
38+
*/
3539
function getDataProtocolModuleFormat(parsed) {
3640
const { 1: mime } = RegExpPrototypeExec(
3741
/^([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/,
@@ -41,6 +45,12 @@ function getDataProtocolModuleFormat(parsed) {
4145
return mimeToFormat(mime);
4246
}
4347

48+
/**
49+
* @param {URL} url
50+
* @param {{parentURL: string}} context
51+
* @param {boolean} ignoreErrors
52+
* @returns {string}
53+
*/
4454
function getFileProtocolModuleFormat(url, context, ignoreErrors) {
4555
const ext = extname(url.pathname);
4656
if (ext === '.js') {
@@ -59,6 +69,11 @@ function getFileProtocolModuleFormat(url, context, ignoreErrors) {
5969
return getLegacyExtensionFormat(ext) ?? null;
6070
}
6171

72+
/**
73+
* @param {URL} url
74+
* @param {{parentURL: string}} context
75+
* @returns {Promise<string> | undefined} only works when enabled
76+
*/
6277
function getHttpProtocolModuleFormat(url, context) {
6378
if (experimentalNetworkImports) {
6479
return PromisePrototypeThen(
@@ -70,13 +85,23 @@ function getHttpProtocolModuleFormat(url, context) {
7085
}
7186
}
7287

88+
/**
89+
* @param {URL | URL['href']} url
90+
* @param {{parentURL: string}} context
91+
* @returns {Promise<string> | string | undefined} only works when enabled
92+
*/
7393
function defaultGetFormatWithoutErrors(url, context) {
7494
const parsed = new URL(url);
7595
if (!ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol))
7696
return null;
7797
return protocolHandlers[parsed.protocol](parsed, context, true);
7898
}
7999

100+
/**
101+
* @param {URL | URL['href']} url
102+
* @param {{parentURL: string}} context
103+
* @returns {Promise<string> | string | undefined} only works when enabled
104+
*/
80105
function defaultGetFormat(url, context) {
81106
const parsed = new URL(url);
82107
return ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol) ?
Collapse file

‎lib/internal/modules/esm/resolve.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js
+1Lines 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;
Collapse file
+5-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.