Skip to content
Prev Previous commit
Next Next commit
explicit isMain checks
  • Loading branch information
guybedford committed Feb 12, 2018
commit ebdb3cbcbbee88c06e1dd7b1f6bc95045d2e2f83
3 changes: 2 additions & 1 deletion lib/internal/loader/DefaultResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function resolve(specifier, parentURL) {

let format = extensionFormatMap[ext];
if (!format) {
if (parentURL === undefined)
const isMain = parentURL === undefined;
if (isMain)
format = 'cjs';
else
throw new errors.Error('ERR_UNKNOWN_FILE_EXTENSION', url.pathname);
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class Loader {
}

async resolve(specifier, parentURL) {
if (parentURL !== undefined && typeof parentURL !== 'string')
const isMain = parentURL === undefined;
if (!isMain && typeof parentURL !== 'string')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'parentURL', 'string');

const { url, format } =
Expand Down