v8-to-istanbul
Advanced tools
Comparing version 8.1.0 to 8.1.1
@@ -5,2 +5,10 @@ # Changelog | ||
### [8.1.1](https://github.com/istanbuljs/v8-to-istanbul/compare/v8.1.0...v8.1.1) (2022-01-10) | ||
### Bug Fixes | ||
* handle undefined sourcesContent and null sourcesContent entry ([6c2e2ec](https://github.com/istanbuljs/v8-to-istanbul/commit/6c2e2ecd2aece8b01543f75dfa203744f8a785b9)) | ||
* **perf:** optimize hit counting and source map performance ([3f83226](https://github.com/istanbuljs/v8-to-istanbul/commit/3f83226212e9fd26231bb313b36db4f2d0661970)), closes [#159](https://github.com/istanbuljs/v8-to-istanbul/issues/159) | ||
## [8.1.0](https://www.github.com/istanbuljs/v8-to-istanbul/compare/v8.0.0...v8.1.0) (2021-09-27) | ||
@@ -7,0 +15,0 @@ |
const CovLine = require('./line') | ||
const { sliceRange } = require('./range') | ||
const { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('source-map').SourceMapConsumer | ||
@@ -6,3 +7,3 @@ | ||
constructor (sourceRaw, wrapperLength) { | ||
sourceRaw = sourceRaw.trimEnd() | ||
sourceRaw = sourceRaw ? sourceRaw.trimEnd() : '' | ||
this.lines = [] | ||
@@ -79,5 +80,3 @@ this.eof = sourceRaw.length | ||
offsetToOriginalRelative (sourceMap, startCol, endCol) { | ||
const lines = this.lines.filter((line, i) => { | ||
return startCol <= line.endCol && endCol >= line.startCol | ||
}) | ||
const lines = sliceRange(this.lines, startCol, endCol, true) | ||
if (!lines.length) return {} | ||
@@ -90,2 +89,6 @@ | ||
) | ||
if (!(start && start.source)) { | ||
return {} | ||
} | ||
let end = originalEndPositionFor( | ||
@@ -96,11 +99,6 @@ sourceMap, | ||
) | ||
if (!(start && end)) { | ||
if (!(end && end.source)) { | ||
return {} | ||
} | ||
if (!(start.source && end.source)) { | ||
return {} | ||
} | ||
if (start.source !== end.source) { | ||
@@ -107,0 +105,0 @@ return {} |
const assert = require('assert') | ||
const convertSourceMap = require('convert-source-map') | ||
const util = require('util') | ||
const debuglog = util.debuglog('c8') | ||
const { dirname, isAbsolute, join, resolve } = require('path') | ||
@@ -8,2 +10,3 @@ const { fileURLToPath } = require('url') | ||
const CovSource = require('./source') | ||
const { sliceRange } = require('./range') | ||
const compatError = Error(`requires Node.js ${require('../package.json').engines.node}`) | ||
@@ -55,2 +58,5 @@ let readFile = () => { throw compatError } | ||
this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap) | ||
if (!this.sourceMap.sourcesContent) { | ||
this.sourceMap.sourcesContent = await this.sourcesContentFromSources() | ||
} | ||
this.covSources = this.sourceMap.sourcesContent.map((rawSource, i) => ({ source: new CovSource(rawSource, this.wrapperLength), path: this.sourceMap.sources[i] })) | ||
@@ -88,2 +94,14 @@ this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength) | ||
async sourcesContentFromSources () { | ||
const fileList = this.sourceMap.sources.map(relativePath => { | ||
const realPath = this._resolveSource(this.rawSourceMap, relativePath) | ||
return readFile(realPath, 'utf-8') | ||
.then(result => result) | ||
.catch(err => { | ||
debuglog(`failed to load ${realPath}: ${err.message}`) | ||
}) | ||
}) | ||
return await Promise.all(fileList) | ||
} | ||
destroy () { | ||
@@ -118,18 +136,21 @@ if (this.sourceMap) { | ||
} | ||
const lines = covSource.lines.filter(line => { | ||
// Upstream tooling can provide a block with the functionName | ||
// (empty-report), this will result in a report that has all | ||
// lines zeroed out. | ||
if (block.functionName === '(empty-report)') { | ||
let lines | ||
if (block.functionName === '(empty-report)') { | ||
// (empty-report), this will result in a report that has all lines zeroed out. | ||
lines = covSource.lines.filter((line) => { | ||
line.count = 0 | ||
this.all = true | ||
return true | ||
} | ||
}) | ||
this.all = lines.length > 0 | ||
} else { | ||
lines = sliceRange(covSource.lines, startCol, endCol) | ||
} | ||
if (!lines.length) { | ||
return | ||
} | ||
return startCol < line.endCol && endCol >= line.startCol | ||
}) | ||
const startLineInstance = lines[0] | ||
const endLineInstance = lines[lines.length - 1] | ||
if (block.isBlockCoverage && lines.length) { | ||
if (block.isBlockCoverage) { | ||
this.branches[path] = this.branches[path] || [] | ||
@@ -145,3 +166,3 @@ // record branches. | ||
// if block-level granularity is enabled, we we still create a single | ||
// if block-level granularity is enabled, we still create a single | ||
// CovFunction tracking object for each set of ranges. | ||
@@ -159,3 +180,3 @@ if (block.functionName && i === 0) { | ||
} | ||
} else if (block.functionName && lines.length) { | ||
} else if (block.functionName) { | ||
this.functions[path] = this.functions[path] || [] | ||
@@ -162,0 +183,0 @@ // record functions. |
{ | ||
"name": "v8-to-istanbul", | ||
"version": "8.1.0", | ||
"version": "8.1.1", | ||
"description": "convert from v8 coverage format to istanbul's format", | ||
@@ -33,8 +33,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@types/node": "^14.0.0", | ||
"@types/node": "^16.0.0", | ||
"c8": "^7.2.1", | ||
"semver": "^7.3.2", | ||
"should": "13.2.3", | ||
"standard": "^16.0.0", | ||
"tap": "^15.0.0" | ||
"standard": "^16.0.4", | ||
"tap": "^15.1.6" | ||
}, | ||
@@ -41,0 +41,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43941
12
654