MCPcopy
hub / github.com/webpack/webpack-dev-server / parseURL

Function parseURL

client-src/index.js:124–160  ·  view source on GitHub ↗
(resourceQuery)

Source from the content-addressed store, hash-verified

122 * @returns {ParsedURL} parsed URL
123 */
124const parseURL = (resourceQuery) => {
125 /** @type {ParsedURL} */
126 let result = {};
127
128 if (typeof resourceQuery === "string" && resourceQuery !== "") {
129 const searchParams = resourceQuery.slice(1).split("&");
130
131 for (let i = 0; i < searchParams.length; i++) {
132 const pair = searchParams[i].split("=");
133
134 /** @type {EXPECTED_ANY} */
135 (result)[pair[0]] = decodeURIComponent(pair[1]);
136 }
137 } else {
138 // Else, get the url from the <script> this file was called with.
139 const scriptSource = getCurrentScriptSource();
140
141 let scriptSourceURL;
142
143 try {
144 // The placeholder `baseURL` with `window.location.href`,
145 // is to allow parsing of path-relative or protocol-relative URLs,
146 // and will have no effect if `scriptSource` is a fully valid URL.
147 scriptSourceURL = new URL(scriptSource, self.location.href);
148 } catch (_err) {
149 // URL parsing failed, do nothing.
150 // We will still proceed to see if we can recover using `resourceQuery`
151 }
152
153 if (scriptSourceURL) {
154 result = scriptSourceURL;
155 result.fromCurrentScript = true;
156 }
157 }
158
159 return result;
160};
161
162const parsedResourceQuery = parseURL(__resourceQuery);
163

Callers 2

index.jsFile · 0.85

Calls 1

getCurrentScriptSourceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…