@@ -29,35 +29,40 @@ const {
2929
3030const DATA_URL_PATTERN = / ^ [ ^ / ] + \/ [ ^ , ; ] + (?: [ ^ , ] * ?) ( ; b a s e 6 4 ) ? , ( [ \s \S ] * ) $ / ;
3131
32+ /**
33+ * @param {URL } url URL to the module
34+ * @param {ESModuleContext } context used to decorate error messages
35+ * @returns {{ responseURL: string, source: string | BufferView } }
36+ */
3237async function getSource ( url , context ) {
33- const parsed = new URL ( url ) ;
34- let responseURL = url ;
38+ const { protocol , href } = url ;
39+ let responseURL = href ;
3540 let source ;
36- if ( parsed . protocol === 'file:' ) {
37- source = await readFileAsync ( parsed ) ;
38- } else if ( parsed . protocol === 'data:' ) {
39- const match = RegExpPrototypeExec ( DATA_URL_PATTERN , parsed . pathname ) ;
41+ if ( protocol === 'file:' ) {
42+ source = await readFileAsync ( url ) ;
43+ } else if ( protocol === 'data:' ) {
44+ const match = RegExpPrototypeExec ( DATA_URL_PATTERN , url . pathname ) ;
4045 if ( ! match ) {
41- throw new ERR_INVALID_URL ( url ) ;
46+ throw new ERR_INVALID_URL ( responseURL ) ;
4247 }
4348 const { 1 : base64 , 2 : body } = match ;
4449 source = BufferFrom ( decodeURIComponent ( body ) , base64 ? 'base64' : 'utf8' ) ;
4550 } else if ( experimentalNetworkImports && (
46- parsed . protocol === 'https:' ||
47- parsed . protocol === 'http:'
51+ protocol === 'https:' ||
52+ protocol === 'http:'
4853 ) ) {
49- const res = await fetchModule ( parsed , context ) ;
54+ const res = await fetchModule ( url , context ) ;
5055 source = await res . body ;
5156 responseURL = res . resolvedHREF ;
5257 } else {
5358 const supportedSchemes = [ 'file' , 'data' ] ;
5459 if ( experimentalNetworkImports ) {
5560 ArrayPrototypePush ( supportedSchemes , 'http' , 'https' ) ;
5661 }
57- throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( parsed , supportedSchemes ) ;
62+ throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url , supportedSchemes ) ;
5863 }
5964 if ( policy ?. manifest ) {
60- policy . manifest . assertIntegrity ( parsed , source ) ;
65+ policy . manifest . assertIntegrity ( href , source ) ;
6166 }
6267 return { __proto__ : null , responseURL, source } ;
6368}
@@ -91,7 +96,7 @@ async function defaultLoad(url, context) {
9196 ) {
9297 source = null ;
9398 } else if ( source == null ) {
94- ( { responseURL, source } = await getSource ( url , context ) ) ;
99+ ( { responseURL, source } = await getSource ( urlInstance , context ) ) ;
95100 }
96101
97102 return {
0 commit comments