@@ -894,16 +894,20 @@ function resolveAsCommonJS(specifier, parentURL) {
894894// TODO(@JakobJingleheimer): de-dupe `specifier` & `parsed`
895895function checkIfDisallowedImport ( specifier , parsed , parsedParentURL ) {
896896 if ( parsedParentURL ) {
897+ // Avoid accessing the `protocol` property due to the lazy getters.
898+ const parentProtocol = parsedParentURL . protocol ;
897899 if (
898- parsedParentURL . protocol === 'http:' ||
899- parsedParentURL . protocol === 'https:'
900+ parentProtocol === 'http:' ||
901+ parentProtocol === 'https:'
900902 ) {
901903 if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
904+ // Avoid accessing the `protocol` property due to the lazy getters.
905+ const parsedProtocol = parsed ?. protocol ;
902906 // data: and blob: disallowed due to allowing file: access via
903907 // indirection
904- if ( parsed &&
905- parsed . protocol !== 'https:' &&
906- parsed . protocol !== 'http:'
908+ if ( parsedProtocol &&
909+ parsedProtocol !== 'https:' &&
910+ parsedProtocol !== 'http:'
907911 ) {
908912 throw new ERR_NETWORK_IMPORT_DISALLOWED (
909913 specifier ,
@@ -944,22 +948,26 @@ function throwIfInvalidParentURL(parentURL) {
944948}
945949
946950function throwIfUnsupportedURLProtocol ( url ) {
947- if ( url . protocol !== 'file:' && url . protocol !== 'data:' &&
948- url . protocol !== 'node:' ) {
951+ // Avoid accessing the `protocol` property due to the lazy getters.
952+ const protocol = url . protocol ;
953+ if ( protocol !== 'file:' && protocol !== 'data:' &&
954+ protocol !== 'node:' ) {
949955 throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url ) ;
950956 }
951957}
952958
953959function throwIfUnsupportedURLScheme ( parsed , experimentalNetworkImports ) {
960+ // Avoid accessing the `protocol` property due to the lazy getters.
961+ const protocol = parsed ?. protocol ;
954962 if (
955- parsed &&
956- parsed . protocol !== 'file:' &&
957- parsed . protocol !== 'data:' &&
963+ protocol &&
964+ protocol !== 'file:' &&
965+ protocol !== 'data:' &&
958966 (
959967 ! experimentalNetworkImports ||
960968 (
961- parsed . protocol !== 'https:' &&
962- parsed . protocol !== 'http:'
969+ protocol !== 'https:' &&
970+ protocol !== 'http:'
963971 )
964972 )
965973 ) {
@@ -1016,11 +1024,13 @@ function defaultResolve(specifier, context = {}) {
10161024 parsed = new URL ( specifier ) ;
10171025 }
10181026
1019- if ( parsed . protocol === 'data:' ||
1027+ // Avoid accessing the `protocol` property due to the lazy getters.
1028+ const protocol = parsed . protocol ;
1029+ if ( protocol === 'data:' ||
10201030 ( experimentalNetworkImports &&
10211031 (
1022- parsed . protocol === 'https:' ||
1023- parsed . protocol === 'http:'
1032+ protocol === 'https:' ||
1033+ protocol === 'http:'
10241034 )
10251035 )
10261036 ) {
0 commit comments