| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1cde4a4 commit 5d75ec4
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | // If user passed `-c` or `--check` arguments to Node, check its syntax | |
| 4 | 4 | // instead of actually running the file. | |
| 5 | 5 | ||
| 6 | + const { URL } = require('internal/url'); | ||
| 6 | 7 | const { | |
| 7 | 8 | prepareMainThreadExecution, | |
| 8 | 9 | markBootstrapComplete, | |
@@ -55,7 +56,7 @@ async function checkSyntax(source, filename) { | |||
| 55 | 56 | const { defaultResolve } = require('internal/modules/esm/resolve'); | |
| 56 | 57 | const { defaultGetFormat } = require('internal/modules/esm/get_format'); | |
| 57 | 58 | const { url } = await defaultResolve(pathToFileURL(filename).toString()); | |
| 58 | - const format = await defaultGetFormat(url); | ||
| 59 | + const format = await defaultGetFormat(new URL(url)); | ||
| 59 | 60 | isModule = format === 'module'; | |
| 60 | 61 | } | |
| 61 | 62 | if (isModule) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ const experimentalNetworkImports = | |||
| 20 | 20 | const experimentalSpecifierResolution = | |
| 21 | 21 | getOptionValue('--experimental-specifier-resolution'); | |
| 22 | 22 | const { getPackageType, getPackageScopeConfig } = require('internal/modules/esm/resolve'); | |
| 23 | - const { URL, fileURLToPath } = require('internal/url'); | ||
| 23 | + const { fileURLToPath } = require('internal/url'); | ||
| 24 | 24 | const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes; | |
| 25 | 25 | ||
| 26 | 26 | const protocolHandlers = { | |
@@ -99,27 +99,29 @@ function getHttpProtocolModuleFormat(url, context) { | |||
| 99 | 99 | } | |
| 100 | 100 | ||
| 101 | 101 | /** | |
| 102 | - * @param {URL | URL['href']} url | ||
| 102 | + * @param {URL} url | ||
| 103 | 103 | * @param {{parentURL: string}} context | |
| 104 | 104 | * @returns {Promise<string> | string | undefined} only works when enabled | |
| 105 | 105 | */ | |
| 106 | 106 | function defaultGetFormatWithoutErrors(url, context) { | |
| 107 | - const parsed = new URL(url); | ||
| 108 | - if (!ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol)) | ||
| 107 | + const protocol = url.protocol; | ||
| 108 | + if (!ObjectPrototypeHasOwnProperty(protocolHandlers, protocol)) { | ||
| 109 | 109 | return null; | |
| 110 | - return protocolHandlers[parsed.protocol](parsed, context, true); | ||
| 110 | + } | ||
| 111 | + return protocolHandlers[protocol](url, context, true); | ||
| 111 | 112 | } | |
| 112 | 113 | ||
| 113 | 114 | /** | |
| 114 | - * @param {URL | URL['href']} url | ||
| 115 | + * @param {URL} url | ||
| 115 | 116 | * @param {{parentURL: string}} context | |
| 116 | 117 | * @returns {Promise<string> | string | undefined} only works when enabled | |
| 117 | 118 | */ | |
| 118 | 119 | function defaultGetFormat(url, context) { | |
| 119 | - const parsed = new URL(url); | ||
| 120 | - return ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol) ? | ||
| 121 | - protocolHandlers[parsed.protocol](parsed, context, false) : | ||
| 122 | - null; | ||
| 120 | + const protocol = url.protocol; | ||
| 121 | + if (!ObjectPrototypeHasOwnProperty(protocolHandlers, protocol)) { | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + return protocolHandlers[protocol](url, context, false); | ||
| 123 | 125 | } | |
| 124 | 126 | ||
| 125 | 127 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,11 +77,11 @@ async function defaultLoad(url, context) { | |||
| 77 | 77 | source, | |
| 78 | 78 | } = context; | |
| 79 | 79 | ||
| 80 | - throwIfUnsupportedURLScheme(new URL(url), experimentalNetworkImports); | ||
| 80 | + const urlInstance = new URL(url); | ||
| 81 | 81 | ||
| 82 | - if (format == null) { | ||
| 83 | - format = await defaultGetFormat(url, context); | ||
| 84 | - } | ||
| 82 | + throwIfUnsupportedURLScheme(urlInstance, experimentalNetworkImports); | ||
| 83 | + | ||
| 84 | + format ??= await defaultGetFormat(urlInstance, context); | ||
| 85 | 85 | ||
| 86 | 86 | validateAssertions(url, format, importAssertions); | |
| 87 | 87 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments