* This is only called from the native ImportMetaObjectInitialize function to set up import.meta.resolve * when import.meta.resolve is accessed for the first time in a module. * @param {ModuleLoader} loader The cascaded loader to use. Bound when this function gets passed to native land. * @param {
(loader, moduleURL)
| 908 | * @returns {function(string, URL['href']=): string} The import.meta.resolve function |
| 909 | */ |
| 910 | function createImportMetaResolve(loader, moduleURL) { |
| 911 | /** |
| 912 | * @param {string} specifier The module specifier to resolve. |
| 913 | * @param {URL['href']} [parentURL] Optional parent URL to resolve against. Ignored unless |
| 914 | * `--experimental-import-meta-resolve` is enabled. |
| 915 | * @returns {string} |
| 916 | */ |
| 917 | return function resolve(specifier, parentURL) { |
| 918 | // The second argument is ignored unless --experimental-import-meta-resolve is enabled. |
| 919 | // Even then, if it's not provided, parentURL defaults to the url of the module accessing |
| 920 | // import.meta.resolve. |
| 921 | allowImportMetaResolveParentURL ??= getOptionValue('--experimental-import-meta-resolve'); |
| 922 | parentURL = allowImportMetaResolveParentURL ? (parentURL ?? moduleURL) : moduleURL; |
| 923 | |
| 924 | let url; |
| 925 | try { |
| 926 | ({ url } = loader.resolveSync(parentURL, { specifier, __proto__: null })); |
| 927 | return url; |
| 928 | } catch (error) { |
| 929 | switch (error?.code) { |
| 930 | case 'ERR_UNSUPPORTED_DIR_IMPORT': |
| 931 | case 'ERR_MODULE_NOT_FOUND': |
| 932 | ({ url } = error); |
| 933 | if (url) { |
| 934 | return url; |
| 935 | } |
| 936 | } |
| 937 | throw error; |
| 938 | } |
| 939 | }; |
| 940 | } |
| 941 | |
| 942 | let cascadedLoader; |
| 943 | /** |
nothing calls this directly
no test coverage detected
searching dependent graphs…