Skip to content

Commit

Permalink
esm: avoid accessing lazy getters for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 13, 2023
1 parent 1323992 commit bb4b123
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,22 +949,26 @@ function throwIfInvalidParentURL(parentURL) {
}

function throwIfUnsupportedURLProtocol(url) {
if (url.protocol !== 'file:' && url.protocol !== 'data:' &&
url.protocol !== 'node:') {
// Avoid accessing the `protocol` property due to the lazy getters.
const protocol = url.protocol;
if (protocol !== 'file:' && protocol !== 'data:' &&
protocol !== 'node:') {
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url);
}
}

function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
// Avoid accessing the `protocol` property due to the lazy getters.
const protocol = parsed?.protocol;
if (
parsed &&
parsed.protocol !== 'file:' &&
parsed.protocol !== 'data:' &&
protocol &&
protocol !== 'file:' &&
protocol !== 'data:' &&
(
!experimentalNetworkImports ||
(
parsed.protocol !== 'https:' &&
parsed.protocol !== 'http:'
protocol !== 'https:' &&
protocol !== 'http:'
)
)
) {
Expand Down Expand Up @@ -1021,11 +1025,13 @@ function defaultResolve(specifier, context = {}) {
parsed = new URL(specifier);
}

if (parsed.protocol === 'data:' ||
// Avoid accessing the `protocol` property due to the lazy getters.
const protocol = parsed.protocol;
if (protocol === 'data:' ||
(experimentalNetworkImports &&
(
parsed.protocol === 'https:' ||
parsed.protocol === 'http:'
protocol === 'https:' ||
protocol === 'http:'
)
)
) {
Expand Down

0 comments on commit bb4b123

Please sign in to comment.