MCPcopy Create free account
hub / github.com/Snapchat/Valdi / parseSourceMappingUrl

Function parseSourceMappingUrl

valdi/vscode_debugger/src/common/sourceUtils.ts:214–251  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

212}
213
214export function parseSourceMappingUrl(content: string): string | undefined {
215 if (!content) return;
216 const name = 'sourceMappingURL';
217 const length = content.length;
218 const nameLength = name.length;
219
220 let pos = length;
221 let equalSignPos = 0;
222 while (true) {
223 pos = content.lastIndexOf(name, pos);
224 if (pos === -1) return;
225 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name.
226 if (pos < 4) return;
227 pos -= 4;
228 if (content[pos] !== '/') continue;
229 if (content[pos + 1] !== '/') continue;
230 if (content[pos + 2] !== '#' && content[pos + 2] !== '@') continue;
231 if (content[pos + 3] !== ' ' && content[pos + 3] !== '\t') continue;
232 equalSignPos = pos + 4 + nameLength;
233 if (equalSignPos < length && content[equalSignPos] !== '=') continue;
234 break;
235 }
236
237 let sourceMapUrl = content.substring(equalSignPos + 1);
238 const newLine = sourceMapUrl.indexOf('\n');
239 if (newLine !== -1) sourceMapUrl = sourceMapUrl.substring(0, newLine);
240 sourceMapUrl = sourceMapUrl.trim();
241 for (let i = 0; i < sourceMapUrl.length; ++i) {
242 if (
243 sourceMapUrl[i] === '"' ||
244 sourceMapUrl[i] === "'" ||
245 sourceMapUrl[i] === ' ' ||
246 sourceMapUrl[i] === '\t'
247 )
248 return;
249 }
250 return sourceMapUrl;
251}
252
253export async function checkContentHash(
254 absolutePath: string,

Callers 1

createMetadataForFileFunction · 0.90

Calls 4

lastIndexOfMethod · 0.80
substringMethod · 0.80
indexOfMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected