diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js index 2813da21dfdc63..31fb3b3e5fe2f1 100644 --- a/lib/internal/source_map/source_map_cache.js +++ b/lib/internal/source_map/source_map_cache.js @@ -205,14 +205,26 @@ function dataFromUrl(sourceURL, sourceMappingURL) { // from. This allows translation from byte offset V8 coverage reports, // to line/column offset Source Map V3. function lineLengths(content) { - // We purposefully keep \r as part of the line-length calculation, in - // cases where there is a \r\n separator, so that this can be taken into - // account in coverage calculations. - return ArrayPrototypeMap(RegExpPrototypeSymbolSplit(/\n|\u2028|\u2029/, content), (line) => { - return line.length; - }); + const contentLength = content.length; + const output = []; + let lineLength = 0 + for (let i = 0; i < contentLength; i++, lineLength++) { + const codePoint = content.codePointAt(i); + + // We purposefully keep \r as part of the line-length calculation, in + // cases where there is a \r\n separator, so that this can be taken into + // account in coverage calculations. + // codepoints for \n, \u2028 and \u2029 + if (codePoint === 10 || codePoint === 0x2028 || codePoint === 0x2029) { + output.push(lineLength); + lineLength = -1; // to not count the matched codePoint such as \n character + } + } + output.push(lineLength); + return output; } + function sourceMapFromFile(mapURL) { try { const fs = require('fs');