Skip to content

Commit

Permalink
fix: fix undefined line in branches and functions (#139)
Browse files Browse the repository at this point in the history
When bundling this [file](https://github.com/browserify/node-util/blob/master/util.js) with esbuild and getting the v8 coverage with playwright `_branchesToIstanbul` and `_functionsToIstanbul` hanged.

These 2 functions actually should throw an error but it is swallowed for some reason.

This PR just ignores if it can't find the source line for the current branch or function.
  • Loading branch information
hugomrdias committed May 5, 2021
1 parent 2b54bc9 commit f5ed83d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/v8-to-istanbul.js
Expand Up @@ -257,7 +257,8 @@ module.exports = class V8ToIstanbul {
}
this.branches[path] = this.branches[path] || []
this.branches[path].forEach((branch, index) => {
const ignore = source.lines[branch.startLine - 1].ignore
const srcLine = source.lines[branch.startLine - 1]
const ignore = srcLine === undefined ? true : srcLine.ignore
branches.branchMap[`${index}`] = branch.toIstanbul()
branches.b[`${index}`] = [ignore ? 1 : branch.count]
})
Expand All @@ -271,7 +272,8 @@ module.exports = class V8ToIstanbul {
}
this.functions[path] = this.functions[path] || []
this.functions[path].forEach((fn, index) => {
const ignore = source.lines[fn.startLine - 1].ignore
const srcLine = source.lines[fn.startLine - 1]
const ignore = srcLine === undefined ? true : srcLine.ignore
functions.fnMap[`${index}`] = fn.toIstanbul()
functions.f[`${index}`] = ignore ? 1 : fn.count
})
Expand Down

0 comments on commit f5ed83d

Please sign in to comment.