diff --git a/lib/internal/modules/esm/formats.js b/lib/internal/modules/esm/formats.js index 470f679b92ec2a..ce606d95126d8c 100644 --- a/lib/internal/modules/esm/formats.js +++ b/lib/internal/modules/esm/formats.js @@ -26,7 +26,7 @@ if (experimentalWasmModules) { /** * @param {string} mime - * @returns {string | null} + * @returns {string | undefined} */ function mimeToFormat(mime) { if ( @@ -37,7 +37,7 @@ function mimeToFormat(mime) { ) { return 'module'; } if (mime === 'application/json') { return 'json'; } if (experimentalWasmModules && mime === 'application/wasm') { return 'wasm'; } - return null; + return undefined; } /** diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js index cd5c88dce8e021..8a34bf48c12504 100644 --- a/lib/internal/modules/esm/get_format.js +++ b/lib/internal/modules/esm/get_format.js @@ -35,7 +35,7 @@ const protocolHandlers = { /** * @param {URL} parsed - * @returns {string | null} + * @returns {string | undefined} */ function getDataProtocolModuleFormat(parsed) { const { 1: mime } = RegExpPrototypeExec( @@ -115,7 +115,7 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE if (getOptionValue('--experimental-detect-module')) { const format = source ? (containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs') : - null; + undefined; if (format === 'module') { // This module has a .js extension, a package.json with no `type` field, and ESM syntax. // Warn about the missing `type` field so that the user can avoid the performance penalty of detection. @@ -155,7 +155,7 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE } default: { // The user did not pass `--experimental-default-type`. if (getOptionValue('--experimental-detect-module')) { - if (!source) { return null; } + if (!source) { return; } const format = getFormatOfExtensionlessFile(url); if (format === 'module') { return containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs'; @@ -201,7 +201,7 @@ function getHttpProtocolModuleFormat(url, context) { function defaultGetFormatWithoutErrors(url, context) { const protocol = url.protocol; if (!ObjectPrototypeHasOwnProperty(protocolHandlers, protocol)) { - return null; + return; } return protocolHandlers[protocol](url, context, true); } @@ -214,7 +214,7 @@ function defaultGetFormatWithoutErrors(url, context) { function defaultGetFormat(url, context) { const protocol = url.protocol; if (!ObjectPrototypeHasOwnProperty(protocolHandlers, protocol)) { - return null; + return; } return protocolHandlers[protocol](url, context, false); } diff --git a/test/es-module/test-esm-detect-ambiguous.mjs b/test/es-module/test-esm-detect-ambiguous.mjs index 9d5f6f06a1c66b..106d59caf536d9 100644 --- a/test/es-module/test-esm-detect-ambiguous.mjs +++ b/test/es-module/test-esm-detect-ambiguous.mjs @@ -172,7 +172,7 @@ describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALL ]); strictEqual(stderr, ''); - strictEqual(stdout, 'null\nexecuted\n'); + strictEqual(stdout, 'undefined\nexecuted\n'); strictEqual(code, 0); strictEqual(signal, null);