|
| 1 | +diff --git a/CHANGELOG.md b/CHANGELOG.md |
| 2 | +deleted file mode 100644 |
| 3 | +index 4f7e3bc8d1bba4feb51044ff9eb77b41f972f957..0000000000000000000000000000000000000000 |
| 4 | +diff --git a/index.d.ts b/index.d.ts |
| 5 | +index ee7b286844f2bf96357218166e26e1c338f774cf..657531b7c75f43e9a4e957dd1f10797e44da5bb1 100644 |
| 6 | +--- a/index.d.ts |
| 7 | ++++ b/index.d.ts |
| 8 | +@@ -1,5 +1,7 @@ |
| 9 | + /// <reference types="node" /> |
| 10 | + |
| 11 | ++// Patch applied: https://github.com/istanbuljs/v8-to-istanbul/pull/244 |
| 12 | ++ |
| 13 | + import { Profiler } from 'inspector' |
| 14 | + import { CoverageMapData } from 'istanbul-lib-coverage' |
| 15 | + import { SourceMapInput } from '@jridgewell/trace-mapping' |
| 16 | +@@ -20,6 +22,6 @@ declare class V8ToIstanbul { |
| 17 | + toIstanbul(): CoverageMapData |
| 18 | + } |
| 19 | + |
| 20 | +-declare function v8ToIstanbul(scriptPath: string, wrapperLength?: number, sources?: Sources, excludePath?: (path: string) => boolean): V8ToIstanbul |
| 21 | ++declare function v8ToIstanbul(scriptPath: string, wrapperLength?: number, sources?: Sources, excludePath?: (path: string) => boolean, excludeEmptyLines?: boolean): V8ToIstanbul |
| 22 | + |
| 23 | + export = v8ToIstanbul |
| 24 | +diff --git a/index.js b/index.js |
| 25 | +index 4db27a7d84324d0e6605c5506e3eee5665ddfeb0..7bfb839634b1e3c54efedc3c270d82edc4167a64 100644 |
| 26 | +--- a/index.js |
| 27 | ++++ b/index.js |
| 28 | +@@ -1,5 +1,6 @@ |
| 29 | ++// Patch applied: https://github.com/istanbuljs/v8-to-istanbul/pull/244 |
| 30 | + const V8ToIstanbul = require('./lib/v8-to-istanbul') |
| 31 | + |
| 32 | +-module.exports = function (path, wrapperLength, sources, excludePath) { |
| 33 | +- return new V8ToIstanbul(path, wrapperLength, sources, excludePath) |
| 34 | ++module.exports = function (path, wrapperLength, sources, excludePath, excludeEmptyLines) { |
| 35 | ++ return new V8ToIstanbul(path, wrapperLength, sources, excludePath, excludeEmptyLines) |
| 36 | + } |
| 37 | +diff --git a/lib/source.js b/lib/source.js |
| 38 | +index d8ebc215f6ad83d472abafe976935acfe5c61b04..021fd2aed1f73ebb4adc449ce6e96f2d89c295a5 100644 |
| 39 | +--- a/lib/source.js |
| 40 | ++++ b/lib/source.js |
| 41 | +@@ -1,23 +1,32 @@ |
| 42 | ++// Patch applied: https://github.com/istanbuljs/v8-to-istanbul/pull/244 |
| 43 | + const CovLine = require('./line') |
| 44 | + const { sliceRange } = require('./range') |
| 45 | +-const { originalPositionFor, generatedPositionFor, GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('@jridgewell/trace-mapping') |
| 46 | ++const { originalPositionFor, generatedPositionFor, eachMapping, GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('@jridgewell/trace-mapping') |
| 47 | + |
| 48 | + module.exports = class CovSource { |
| 49 | +- constructor (sourceRaw, wrapperLength) { |
| 50 | ++ constructor (sourceRaw, wrapperLength, traceMap) { |
| 51 | + sourceRaw = sourceRaw ? sourceRaw.trimEnd() : '' |
| 52 | + this.lines = [] |
| 53 | + this.eof = sourceRaw.length |
| 54 | + this.shebangLength = getShebangLength(sourceRaw) |
| 55 | + this.wrapperLength = wrapperLength - this.shebangLength |
| 56 | +- this._buildLines(sourceRaw) |
| 57 | ++ this._buildLines(sourceRaw, traceMap) |
| 58 | + } |
| 59 | + |
| 60 | +- _buildLines (source) { |
| 61 | ++ _buildLines (source, traceMap) { |
| 62 | + let position = 0 |
| 63 | + let ignoreCount = 0 |
| 64 | + let ignoreAll = false |
| 65 | ++ const linesToCover = traceMap && this._parseLinesToCover(traceMap) |
| 66 | ++ |
| 67 | + for (const [i, lineStr] of source.split(/(?<=\r?\n)/u).entries()) { |
| 68 | +- const line = new CovLine(i + 1, position, lineStr) |
| 69 | ++ const lineNumber = i + 1 |
| 70 | ++ const line = new CovLine(lineNumber, position, lineStr) |
| 71 | ++ |
| 72 | ++ if (linesToCover && !linesToCover.has(lineNumber)) { |
| 73 | ++ line.ignore = true |
| 74 | ++ } |
| 75 | ++ |
| 76 | + if (ignoreCount > 0) { |
| 77 | + line.ignore = true |
| 78 | + ignoreCount-- |
| 79 | +@@ -125,6 +134,18 @@ module.exports = class CovSource { |
| 80 | + if (this.lines[line - 1] === undefined) return this.eof |
| 81 | + return Math.min(this.lines[line - 1].startCol + relCol, this.lines[line - 1].endCol) |
| 82 | + } |
| 83 | ++ |
| 84 | ++ _parseLinesToCover (traceMap) { |
| 85 | ++ const linesToCover = new Set() |
| 86 | ++ |
| 87 | ++ eachMapping(traceMap, (mapping) => { |
| 88 | ++ if (mapping.originalLine !== null) { |
| 89 | ++ linesToCover.add(mapping.originalLine) |
| 90 | ++ } |
| 91 | ++ }) |
| 92 | ++ |
| 93 | ++ return linesToCover |
| 94 | ++ } |
| 95 | + } |
| 96 | + |
| 97 | + // this implementation is pulled over from istanbul-lib-sourcemap: |
| 98 | +diff --git a/lib/v8-to-istanbul.js b/lib/v8-to-istanbul.js |
| 99 | +index 3616437b00658861dc5a8910c64d1449e9fdf467..c1e0c0ae19984480e408713d1691fa174a7c4c1f 100644 |
| 100 | +--- a/lib/v8-to-istanbul.js |
| 101 | ++++ b/lib/v8-to-istanbul.js |
| 102 | +@@ -1,3 +1,4 @@ |
| 103 | ++// Patch applied: https://github.com/istanbuljs/v8-to-istanbul/pull/244 |
| 104 | + const assert = require('assert') |
| 105 | + const convertSourceMap = require('convert-source-map') |
| 106 | + const util = require('util') |
| 107 | +@@ -25,12 +26,13 @@ const isNode8 = /^v8\./.test(process.version) |
| 108 | + const cjsWrapperLength = isOlderNode10 ? require('module').wrapper[0].length : 0 |
| 109 | + |
| 110 | + module.exports = class V8ToIstanbul { |
| 111 | +- constructor (scriptPath, wrapperLength, sources, excludePath) { |
| 112 | ++ constructor (scriptPath, wrapperLength, sources, excludePath, excludeEmptyLines) { |
| 113 | + assert(typeof scriptPath === 'string', 'scriptPath must be a string') |
| 114 | + assert(!isNode8, 'This module does not support node 8 or lower, please upgrade to node 10') |
| 115 | + this.path = parsePath(scriptPath) |
| 116 | + this.wrapperLength = wrapperLength === undefined ? cjsWrapperLength : wrapperLength |
| 117 | + this.excludePath = excludePath || (() => false) |
| 118 | ++ this.excludeEmptyLines = excludeEmptyLines === true |
| 119 | + this.sources = sources || {} |
| 120 | + this.generatedLines = [] |
| 121 | + this.branches = {} |
| 122 | +@@ -58,8 +60,8 @@ module.exports = class V8ToIstanbul { |
| 123 | + if (!this.sourceMap.sourcesContent) { |
| 124 | + this.sourceMap.sourcesContent = await this.sourcesContentFromSources() |
| 125 | + } |
| 126 | +- this.covSources = this.sourceMap.sourcesContent.map((rawSource, i) => ({ source: new CovSource(rawSource, this.wrapperLength), path: this.sourceMap.sources[i] })) |
| 127 | +- this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength) |
| 128 | ++ this.covSources = this.sourceMap.sourcesContent.map((rawSource, i) => ({ source: new CovSource(rawSource, this.wrapperLength, this.excludeEmptyLines ? this.sourceMap : null), path: this.sourceMap.sources[i] })) |
| 129 | ++ this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength, this.excludeEmptyLines ? this.sourceMap : null) |
| 130 | + } else { |
| 131 | + const candidatePath = this.rawSourceMap.sourcemap.sources.length >= 1 ? this.rawSourceMap.sourcemap.sources[0] : this.rawSourceMap.sourcemap.file |
| 132 | + this.path = this._resolveSource(this.rawSourceMap, candidatePath || this.path) |
| 133 | +@@ -82,8 +84,8 @@ module.exports = class V8ToIstanbul { |
| 134 | + // We fallback to reading the original source from disk. |
| 135 | + originalRawSource = await readFile(this.path, 'utf8') |
| 136 | + } |
| 137 | +- this.covSources = [{ source: new CovSource(originalRawSource, this.wrapperLength), path: this.path }] |
| 138 | +- this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength) |
| 139 | ++ this.covSources = [{ source: new CovSource(originalRawSource, this.wrapperLength, this.excludeEmptyLines ? this.sourceMap : null), path: this.path }] |
| 140 | ++ this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength, this.excludeEmptyLines ? this.sourceMap : null) |
| 141 | + } |
| 142 | + } else { |
| 143 | + this.covSources = [{ source: new CovSource(rawSource, this.wrapperLength), path: this.path }] |
| 144 | +@@ -281,8 +283,10 @@ module.exports = class V8ToIstanbul { |
| 145 | + s: {} |
| 146 | + } |
| 147 | + source.lines.forEach((line, index) => { |
| 148 | +- statements.statementMap[`${index}`] = line.toIstanbul() |
| 149 | +- statements.s[`${index}`] = line.ignore ? 1 : line.count |
| 150 | ++ if (!line.ignore) { |
| 151 | ++ statements.statementMap[`${index}`] = line.toIstanbul() |
| 152 | ++ statements.s[`${index}`] = line.count |
| 153 | ++ } |
| 154 | + }) |
| 155 | + return statements |
| 156 | + } |
0 commit comments