@@ -23,10 +23,12 @@ const { validateString } = require('internal/validators');
23
23
const fs = require ( 'fs' ) ; // Import all of `fs` so that it can be monkey-patched.
24
24
const internalFS = require ( 'internal/fs/utils' ) ;
25
25
const path = require ( 'path' ) ;
26
- const { pathToFileURL, fileURLToPath, URL } = require ( 'internal/url' ) ;
26
+ const { pathToFileURL, fileURLToPath } = require ( 'internal/url' ) ;
27
+ const assert = require ( 'internal/assert' ) ;
27
28
28
29
const { getOptionValue } = require ( 'internal/options' ) ;
29
30
const { setOwnProperty } = require ( 'internal/util' ) ;
31
+ const { inspect } = require ( 'internal/util/inspect' ) ;
30
32
31
33
const {
32
34
privateSymbols : {
@@ -290,29 +292,31 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
290
292
291
293
/**
292
294
* Normalize the referrer name as a URL.
293
- * If it's an absolute path or a file:// it's normalized as a file:// URL.
294
- * Otherwise it's returned as undefined;
295
- * @param {string | null | undefined | false | any } referrerName
295
+ * If it's a string containing an absolute path or a URL it's normalized as
296
+ * a URL string.
297
+ * Otherwise it's returned as undefined.
298
+ * @param {string | null | undefined } referrerName
296
299
* @returns {string | undefined }
297
300
*/
298
301
function normalizeReferrerURL ( referrerName ) {
299
- if ( typeof referrerName !== 'string' ) {
302
+ if ( referrerName === null || referrerName === undefined ) {
300
303
return undefined ;
301
304
}
302
305
303
- if ( StringPrototypeStartsWith ( referrerName , 'file://' ) ) {
304
- return referrerName ;
305
- }
306
+ if ( typeof referrerName === 'string' ) {
307
+ if ( path . isAbsolute ( referrerName ) ) {
308
+ return pathToFileURL ( referrerName ) . href ;
309
+ }
306
310
307
- if ( path . isAbsolute ( referrerName ) ) {
308
- return pathToFileURL ( referrerName ) . href ;
309
- }
311
+ if ( StringPrototypeStartsWith ( referrerName , 'file://' ) ||
312
+ URLCanParse ( referrerName ) ) {
313
+ return referrerName ;
314
+ }
310
315
311
- if ( URLCanParse ( referrerName ) ) {
312
- return new URL ( referrerName ) . href ;
316
+ return undefined ;
313
317
}
314
318
315
- return undefined ;
319
+ assert . fail ( 'Unreachable code reached by ' + inspect ( referrerName ) ) ;
316
320
}
317
321
318
322
module . exports = {
0 commit comments