MCPcopy Index your code
hub / github.com/nodejs/node / sourceMapFromDataUrl

Function sourceMapFromDataUrl

lib/internal/source_map/source_map_cache.js:298–319  ·  view source on GitHub ↗
(sourceURL, url)

Source from the content-addressed store, hash-verified

296// data:[<mediatype>][;base64],<data> see:
297// https://tools.ietf.org/html/rfc2397#section-2
298function sourceMapFromDataUrl(sourceURL, url) {
299 const { 0: format, 1: data } = StringPrototypeSplit(url, ',', 2);
300 const splitFormat = StringPrototypeSplit(format, ';');
301 const contentType = splitFormat[0];
302 const base64 = splitFormat[splitFormat.length - 1] === 'base64';
303 if (contentType === 'application/json') {
304 const decodedData = base64 ?
305 Buffer.from(data, 'base64').toString('utf8') : data;
306 try {
307 const parsedData = JSONParse(decodedData);
308 return sourcesToAbsolute(sourceURL, parsedData);
309 } catch (err) {
310 // TODO(legendecas): warn about invalid source map JSON string.
311 // But it could be verbose.
312 debug(err);
313 return null;
314 }
315 } else {
316 debug(`unknown content-type ${contentType}`);
317 return null;
318 }
319}
320
321// If the sources are not absolute URLs after prepending of the "sourceRoot",
322// the sources are resolved relative to the SourceMap (like resolving script

Callers 1

dataFromUrlFunction · 0.85

Calls 4

sourcesToAbsoluteFunction · 0.85
debugFunction · 0.50
toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…