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

Method mapCoverageWithSourceMap

lib/internal/test_runner/coverage.js:418–508  ·  view source on GitHub ↗
(coverage)

Source from the content-addressed store, hash-verified

416
417
418 mapCoverageWithSourceMap(coverage) {
419 const { result } = coverage;
420 const sourceMapCache = coverage['source-map-cache'];
421 if (!this.options.sourceMaps || !sourceMapCache) {
422 return result;
423 }
424 const newResult = new SafeMap();
425 for (let i = 0; i < result.length; ++i) {
426 const script = result[i];
427 const { url, functions } = script;
428
429 if (this.shouldSkipFileCoverage(url) || sourceMapCache[url] == null) {
430 newResult.set(url, script);
431 continue;
432 }
433 const { data, lineLengths } = sourceMapCache[url];
434 if (!data) throw new ERR_SOURCE_MAP_CORRUPT(url);
435 let offset = 0;
436 const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => {
437 const coverageLine = new CoverageLine(i + 1, offset, null, length + 1);
438 offset += length + 1;
439 return coverageLine;
440 });
441 for (let j = 0; j < data.sources.length; ++j) {
442 const source = data.sourcesContent?.[j];
443 if (source != null) {
444 this.getLines(data.sources[j], source);
445 }
446 this.markTypeScriptOnlyLines(data.sources[j], source);
447 }
448 const sourceMap = new SourceMap(data, { __proto__: null, lineLengths });
449
450 for (let j = 0; j < functions.length; ++j) {
451 const { ranges, functionName, isBlockCoverage } = functions[j];
452 if (ranges == null) {
453 continue;
454 }
455 let newUrl;
456 const newRanges = [];
457 for (let k = 0; k < ranges.length; ++k) {
458 const { startOffset, endOffset, count } = ranges[k];
459 const { lines } = mapRangeToLines(ranges[k], executedLines);
460
461 let startEntry = sourceMap
462 .findEntry(lines[0].line - 1, MathMax(0, startOffset - lines[0].startOffset));
463 const endEntry = sourceMap
464 .findEntry(lines[lines.length - 1].line - 1, (endOffset - lines[lines.length - 1].startOffset) - 1);
465 if (!startEntry.originalSource && endEntry.originalSource &&
466 lines[0].line === 1 && startOffset === 0 && lines[0].startOffset === 0) {
467 // Edge case when the first line is not mappable
468 const { 2: originalSource, 3: originalLine, 4: originalColumn } = sourceMap[kMappings][0];
469 startEntry = { __proto__: null, originalSource, originalLine, originalColumn };
470 }
471
472 if (!startEntry.originalSource || startEntry.originalSource !== endEntry.originalSource) {
473 // The range is not mappable. Skip it.
474 continue;
475 }

Callers 1

Calls 9

getLinesMethod · 0.95
findEntryMethod · 0.95
entryToOffsetMethod · 0.95
mapRangeToLinesFunction · 0.85
getMethod · 0.65
setMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected