@@ -994,16 +994,20 @@ function resolveAsCommonJS(specifier, parentURL) {
994
994
// TODO(@JakobJingleheimer): de-dupe `specifier` & `parsed`
995
995
function checkIfDisallowedImport ( specifier , parsed , parsedParentURL ) {
996
996
if ( parsedParentURL ) {
997
+ // Avoid accessing the `protocol` property due to the lazy getters.
998
+ const parentProtocol = parsedParentURL . protocol ;
997
999
if (
998
- parsedParentURL . protocol === 'http:' ||
999
- parsedParentURL . protocol === 'https:'
1000
+ parentProtocol === 'http:' ||
1001
+ parentProtocol === 'https:'
1000
1002
) {
1001
1003
if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
1004
+ // Avoid accessing the `protocol` property due to the lazy getters.
1005
+ const parsedProtocol = parsed ?. protocol ;
1002
1006
// data: and blob: disallowed due to allowing file: access via
1003
1007
// indirection
1004
- if ( parsed &&
1005
- parsed . protocol !== 'https:' &&
1006
- parsed . protocol !== 'http:'
1008
+ if ( parsedProtocol &&
1009
+ parsedProtocol !== 'https:' &&
1010
+ parsedProtocol !== 'http:'
1007
1011
) {
1008
1012
throw new ERR_NETWORK_IMPORT_DISALLOWED (
1009
1013
specifier ,
@@ -1033,22 +1037,26 @@ function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {
1033
1037
}
1034
1038
1035
1039
function throwIfUnsupportedURLProtocol ( url ) {
1036
- if ( url . protocol !== 'file:' && url . protocol !== 'data:' &&
1037
- url . protocol !== 'node:' ) {
1040
+ // Avoid accessing the `protocol` property due to the lazy getters.
1041
+ const protocol = url . protocol ;
1042
+ if ( protocol !== 'file:' && protocol !== 'data:' &&
1043
+ protocol !== 'node:' ) {
1038
1044
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url ) ;
1039
1045
}
1040
1046
}
1041
1047
1042
1048
function throwIfUnsupportedURLScheme ( parsed , experimentalNetworkImports ) {
1049
+ // Avoid accessing the `protocol` property due to the lazy getters.
1050
+ const protocol = parsed ?. protocol ;
1043
1051
if (
1044
- parsed &&
1045
- parsed . protocol !== 'file:' &&
1046
- parsed . protocol !== 'data:' &&
1052
+ protocol &&
1053
+ protocol !== 'file:' &&
1054
+ protocol !== 'data:' &&
1047
1055
(
1048
1056
! experimentalNetworkImports ||
1049
1057
(
1050
- parsed . protocol !== 'https:' &&
1051
- parsed . protocol !== 'http:'
1058
+ protocol !== 'https:' &&
1059
+ protocol !== 'http:'
1052
1060
)
1053
1061
)
1054
1062
) {
@@ -1104,11 +1112,13 @@ async function defaultResolve(specifier, context = {}) {
1104
1112
parsed = new URL ( specifier ) ;
1105
1113
}
1106
1114
1107
- if ( parsed . protocol === 'data:' ||
1115
+ // Avoid accessing the `protocol` property due to the lazy getters.
1116
+ const protocol = parsed . protocol ;
1117
+ if ( protocol === 'data:' ||
1108
1118
( experimentalNetworkImports &&
1109
1119
(
1110
- parsed . protocol === 'https:' ||
1111
- parsed . protocol === 'http:'
1120
+ protocol === 'https:' ||
1121
+ protocol === 'http:'
1112
1122
)
1113
1123
)
1114
1124
) {
0 commit comments