Socket
Socket
Sign inDemoInstall

v8-to-istanbul

Package Overview
Dependencies
5
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.0.0-candidate.0 to 9.0.0

CHANGELOG.md

4

index.d.ts

@@ -5,3 +5,3 @@ /// <reference types="node" />

import { CoverageMapData } from 'istanbul-lib-coverage'
import { RawSourceMap } from 'source-map'
import { SourceMapInput } from '@jridgewell/trace-mapping'

@@ -15,3 +15,3 @@ declare type Sources =

originalSource: string
sourceMap: { sourcemap: RawSourceMap }
sourceMap: { sourcemap: SourceMapInput }
}

@@ -18,0 +18,0 @@ declare class V8ToIstanbul {

@@ -7,3 +7,2 @@ module.exports = class CovLine {

this.startCol = startCol
this.minCol = startCol + lineStr.length - lineStr.trimStart().length

@@ -15,3 +14,2 @@ // the line length itself does not include the newline characters,

this.endCol = startCol + lineStr.length - newLineLength
this.maxCol = startCol + lineStr.trimEnd().length

@@ -18,0 +16,0 @@ // we start with all lines having been executed, and work

@@ -5,37 +5,32 @@ /**

*/
module.exports.sliceRange = (lines, startCol, endCol) => {
let lower = 0
let upper = lines.length - 1
module.exports.sliceRange = (lines, startCol, endCol, inclusive = false) => {
let start = 0
let end = lines.length
let s
while (lower <= upper) {
s = (lower + upper) >> 1
if (startCol < lines[s].startCol) {
upper = s - 1
} else if (startCol >= lines[s].endCol) {
lower = s + 1
if (inclusive) {
// I consider this a temporary solution until I find an alternaive way to fix the "off by one issue"
--startCol
}
while (start < end) {
let mid = (start + end) >> 1
if (startCol >= lines[mid].endCol) {
start = mid + 1
} else if (endCol < lines[mid].startCol) {
end = mid - 1
} else {
let e = s + 1
while (e < lines.length && endCol > lines[e].startCol) {
++e
end = mid
while (mid >= 0 && startCol < lines[mid].endCol && endCol >= lines[mid].startCol) {
--mid
}
return lines.slice(s, e)
start = mid + 1
break
}
}
if (s >= 0 && lines[s].startCol >= startCol) {
let e = s + 1
while (e < lines.length && endCol > lines[e].startCol) {
++e
}
return lines.slice(s, e)
while (end < lines.length && startCol < lines[end].endCol && endCol >= lines[end].startCol) {
++end
}
return []
}
module.exports.trimRange = (rawSource, range) => {
const slice = rawSource.slice(range.startOffset, range.endOffset)
return {
startOffset: range.startOffset + (slice.length - slice.trimStart().length),
endOffset: range.endOffset - (slice.length - slice.trimEnd().length)
}
return lines.slice(start, end)
}
const CovLine = require('./line')
const { sliceRange } = require('./range')
const { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('source-map').SourceMapConsumer
const { originalPositionFor, generatedPositionFor, GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('@jridgewell/trace-mapping')
module.exports = class CovSource {
constructor (sourceRaw, wrapperLength) {
sourceRaw = sourceRaw.trimEnd()
sourceRaw = sourceRaw ? sourceRaw.trimEnd() : ''
this.lines = []

@@ -79,3 +79,3 @@ this.eof = sourceRaw.length

offsetToOriginalRelative (sourceMap, startCol, endCol) {
const lines = sliceRange(this.lines, startCol, endCol)
const lines = sliceRange(this.lines, startCol, endCol, true)
if (!lines.length) return {}

@@ -106,3 +106,3 @@

if (start.line === end.line && start.column === end.column) {
end = sourceMap.originalPositionFor({
end = originalPositionFor(sourceMap, {
line: lines[lines.length - 1].line,

@@ -173,3 +173,3 @@ column: endCol - lines[lines.length - 1].startCol,

// beforeEndMapping mapping.
const afterEndMapping = sourceMap.generatedPositionFor({
const afterEndMapping = generatedPositionFor(sourceMap, {
source: beforeEndMapping.source,

@@ -187,3 +187,3 @@ line: beforeEndMapping.line,

// the line we gave, so consider the binding to extend to infinity.
sourceMap.originalPositionFor(afterEndMapping).line !==
originalPositionFor(sourceMap, afterEndMapping).line !==
beforeEndMapping.line

@@ -199,7 +199,7 @@ ) {

// Convert the end mapping into the real original position.
return sourceMap.originalPositionFor(afterEndMapping)
return originalPositionFor(sourceMap, afterEndMapping)
}
function originalPositionTryBoth (sourceMap, line, column) {
let original = sourceMap.originalPositionFor({
let original = originalPositionFor(sourceMap, {
line,

@@ -210,3 +210,3 @@ column,

if (original.line === null) {
original = sourceMap.originalPositionFor({
original = originalPositionFor(sourceMap, {
line,

@@ -229,3 +229,3 @@ column,

// l5 l3
const min = sourceMap.originalPositionFor({
const min = originalPositionFor(sourceMap, {
line,

@@ -232,0 +232,0 @@ column: 0,

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,3 +10,3 @@ const { fileURLToPath } = require('url')

const CovSource = require('./source')
const { sliceRange, trimRange } = require('./range')
const { sliceRange } = require('./range')
const compatError = Error(`requires Node.js ${require('../package.json').engines.node}`)

@@ -17,3 +19,3 @@ let readFile = () => { throw compatError }

}
const { SourceMapConsumer } = require('source-map')
const { TraceMap } = require('@jridgewell/trace-mapping')
const isOlderNode10 = /^v10\.(([0-9]\.)|(1[0-5]\.))/u.test(process.version)

@@ -48,3 +50,2 @@ const isNode8 = /^v8\./.test(process.version)

const rawSource = this.sources.source || await readFile(this.path, 'utf8')
this.rawSource = rawSource
this.rawSourceMap = this.sources.sourceMap ||

@@ -58,3 +59,6 @@ // if we find a source-map (either inline, or a .map file) we load

if (this.rawSourceMap.sourcemap.sources.length > 1) {
this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap)
this.sourceMap = new TraceMap(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] }))

@@ -65,3 +69,3 @@ this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength)

this.path = this._resolveSource(this.rawSourceMap, candidatePath || this.path)
this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap)
this.sourceMap = new TraceMap(this.rawSourceMap.sourcemap)

@@ -93,7 +97,16 @@ let originalRawSource

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 () {
if (this.sourceMap) {
this.sourceMap.destroy()
this.sourceMap = undefined
}
this.sourceMap = undefined
}

@@ -123,13 +136,13 @@

}
// (empty-report), this will result in a report that has all
// lines zeroed out.
let lines
if (block.functionName === '(empty-report)') {
this.all = true
covSource.lines.forEach(line => {
// (empty-report), this will result in a report that has all lines zeroed out.
lines = covSource.lines.filter((line) => {
line.count = 0
return true
})
this.all = lines.length > 0
} else {
lines = sliceRange(covSource.lines, startCol, endCol)
}
const lines = this.all ? covSource.lines : sliceRange(covSource.lines, startCol, endCol)
if (!lines.length) {

@@ -141,2 +154,3 @@ return

const endLineInstance = lines[lines.length - 1]
if (block.isBlockCoverage) {

@@ -179,7 +193,2 @@ this.branches[path] = this.branches[path] || []

const {
startCol: minCol,
endCol: maxCol
} = this._maybeRemapStartColEndCol(trimRange(this.rawSource, range))
// record the lines (we record these as statements, such that we're

@@ -197,3 +206,3 @@ // compatible with Istanbul 2.0).

if (minCol <= line.minCol && maxCol >= line.maxCol && !line.ignore) {
if (startCol <= line.startCol && endCol >= line.endCol && !line.ignore) {
line.count = range.count

@@ -200,0 +209,0 @@ }

{
"name": "v8-to-istanbul",
"version": "9.0.0-candidate.0",
"version": "9.0.0",
"description": "convert from v8 coverage format to istanbul's format",

@@ -28,13 +28,14 @@ "main": "index.js",

"dependencies": {
"@jridgewell/trace-mapping": "^0.3.7",
"@types/istanbul-lib-coverage": "^2.0.1",
"convert-source-map": "^1.6.0",
"source-map": "^0.7.3"
"convert-source-map": "^1.6.0"
},
"devDependencies": {
"@types/node": "^14.0.0",
"@types/node": "^16.0.0",
"c8": "^7.2.1",
"semver": "^7.3.2",
"should": "13.2.3",
"source-map": "^0.7.3",
"standard": "^16.0.4",
"tap": "^15.0.10"
"tap": "^16.0.0"
},

@@ -41,0 +42,0 @@ "engines": {

@@ -16,3 +16,3 @@ # v8-to-istanbul

const converter = v8toIstanbul('./path-to-instrumented-file.js')
await converter.load() // this is required due to the async source-map dependency.
await converter.load() // this is required due to async file reading.
// provide an array of coverage information in v8 format.

@@ -19,0 +19,0 @@ converter.applyCoverage([

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc