Skip to content

Commit cadc77b

Browse files
committed
module: reduce url invocations in esm/load.js
1 parent 5c27cc2 commit cadc77b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/internal/modules/esm/load.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ const {
2929

3030
const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/;
3131

32-
async function getSource(url, context) {
33-
const parsed = new URL(url);
34-
let responseURL = url;
32+
async function getSource(parsed, context) {
33+
const protocol = parsed.protocol;
34+
let responseURL = parsed.href;
3535
let source;
36-
if (parsed.protocol === 'file:') {
36+
if (protocol === 'file:') {
3737
const { readFile: readFileAsync } = require('internal/fs/promises').exports;
3838
source = await readFileAsync(parsed);
39-
} else if (parsed.protocol === 'data:') {
39+
} else if (protocol === 'data:') {
4040
const match = RegExpPrototypeExec(DATA_URL_PATTERN, parsed.pathname);
4141
if (!match) {
42-
throw new ERR_INVALID_URL(url);
42+
throw new ERR_INVALID_URL(parsed.href);
4343
}
4444
const { 1: base64, 2: body } = match;
4545
source = BufferFrom(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
4646
} else if (experimentalNetworkImports && (
47-
parsed.protocol === 'https:' ||
48-
parsed.protocol === 'http:'
47+
protocol === 'https:' ||
48+
protocol === 'http:'
4949
)) {
5050
const { fetchModule } = require('internal/modules/esm/fetch_module');
5151
const res = await fetchModule(parsed, context);
@@ -93,7 +93,7 @@ async function defaultLoad(url, context = kEmptyObject) {
9393
) {
9494
source = null;
9595
} else if (source == null) {
96-
({ responseURL, source } = await getSource(url, context));
96+
({ responseURL, source } = await getSource(urlInstance, context));
9797
}
9898

9999
return {

0 commit comments

Comments
 (0)