@@ -30,36 +30,36 @@ const {
30
30
const DATA_URL_PATTERN = / ^ [ ^ / ] + \/ [ ^ , ; ] + (?: [ ^ , ] * ?) ( ; b a s e 6 4 ) ? , ( [ \s \S ] * ) $ / ;
31
31
32
32
async function getSource ( url , context ) {
33
- const parsed = new URL ( url ) ;
34
- let responseURL = url ;
33
+ const protocol = url . protocol ;
34
+ let responseURL = url . href ;
35
35
let source ;
36
- if ( parsed . protocol === 'file:' ) {
36
+ if ( protocol === 'file:' ) {
37
37
const { readFile : readFileAsync } = require ( 'internal/fs/promises' ) . exports ;
38
- source = await readFileAsync ( parsed ) ;
39
- } else if ( parsed . protocol === 'data:' ) {
40
- const match = RegExpPrototypeExec ( DATA_URL_PATTERN , parsed . pathname ) ;
38
+ source = await readFileAsync ( url ) ;
39
+ } else if ( protocol === 'data:' ) {
40
+ const match = RegExpPrototypeExec ( DATA_URL_PATTERN , url . pathname ) ;
41
41
if ( ! match ) {
42
- throw new ERR_INVALID_URL ( url ) ;
42
+ throw new ERR_INVALID_URL ( responseURL ) ;
43
43
}
44
44
const { 1 : base64 , 2 : body } = match ;
45
45
source = BufferFrom ( decodeURIComponent ( body ) , base64 ? 'base64' : 'utf8' ) ;
46
46
} else if ( experimentalNetworkImports && (
47
- parsed . protocol === 'https:' ||
48
- parsed . protocol === 'http:'
47
+ protocol === 'https:' ||
48
+ protocol === 'http:'
49
49
) ) {
50
50
const { fetchModule } = require ( 'internal/modules/esm/fetch_module' ) ;
51
- const res = await fetchModule ( parsed , context ) ;
51
+ const res = await fetchModule ( url , context ) ;
52
52
source = await res . body ;
53
53
responseURL = res . resolvedHREF ;
54
54
} else {
55
55
const supportedSchemes = [ 'file' , 'data' ] ;
56
56
if ( experimentalNetworkImports ) {
57
57
ArrayPrototypePush ( supportedSchemes , 'http' , 'https' ) ;
58
58
}
59
- throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( parsed , supportedSchemes ) ;
59
+ throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url , supportedSchemes ) ;
60
60
}
61
61
if ( policy ?. manifest ) {
62
- policy . manifest . assertIntegrity ( parsed , source ) ;
62
+ policy . manifest . assertIntegrity ( url , source ) ;
63
63
}
64
64
return { __proto__ : null , responseURL, source } ;
65
65
}
@@ -93,7 +93,7 @@ async function defaultLoad(url, context = kEmptyObject) {
93
93
) {
94
94
source = null ;
95
95
} else if ( source == null ) {
96
- ( { responseURL, source } = await getSource ( url , context ) ) ;
96
+ ( { responseURL, source } = await getSource ( urlInstance , context ) ) ;
97
97
}
98
98
99
99
return {
0 commit comments