diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-05-07 20:31:57 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-05-11 01:09:05 +0300 |
commit | 4ebb88fea5a9d83f2c4ec566e958d735f1fca138 (patch) | |
tree | d8a8f3d6da5db22c9231014281a2ff8dde892898 /lib | |
parent | 8886b63cf66c29d453fdc1ece2e489dace97ae9d (diff) |
module: add support for `URL` to `import.meta.resolve`
PR-URL: https://github.com/nodejs/node/pull/38587
Refs: https://github.com/nodejs/node/pull/38585
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/modules/esm/loader.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 8b2c89ba130..de9863ed71c 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -13,6 +13,7 @@ const { } = primordials; const { + ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_RETURN_PROPERTY, @@ -20,8 +21,7 @@ const { ERR_INVALID_RETURN_VALUE, ERR_UNKNOWN_MODULE_FORMAT } = require('internal/errors').codes; -const { URL, pathToFileURL } = require('internal/url'); -const { validateString } = require('internal/validators'); +const { URL, pathToFileURL, isURLInstance } = require('internal/url'); const ModuleMap = require('internal/modules/esm/module_map'); const ModuleJob = require('internal/modules/esm/module_job'); @@ -83,8 +83,8 @@ class Loader { async resolve(specifier, parentURL) { const isMain = parentURL === undefined; - if (!isMain) - validateString(parentURL, 'parentURL'); + if (!isMain && typeof parentURL !== 'string' && !isURLInstance(parentURL)) + throw new ERR_INVALID_ARG_TYPE('parentURL', ['string', 'URL'], parentURL); const resolveResponse = await this._resolve( specifier, { parentURL, conditions: DEFAULT_CONDITIONS }, defaultResolve); |