Skip to content

Commit

Permalink
fix: discard more bad source map positions (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn authored and bcoe committed May 11, 2016
1 parent 0a78ad5 commit 0838a0e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/source-map-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function clampPosition (pos) {
}
}

function discardPosition (pos) {
return !pos || !pos.source || pos.line === null || pos.column === null
}

// Maps the coverage location based on the source map. Adapted from getMapping()
// in remap-istanbul:
// <https://github.com/SitePen/remap-istanbul/blob/30b67ad3f24ba7e0da8b8888d5a7c3c8480d48b2/lib/remap.js#L55:L108>.
Expand All @@ -51,18 +55,7 @@ function mapLocation (sourceMap, location) {
var end = sourceMap.originalPositionFor(clampedEnd)

/* istanbul ignore if: edge case too hard to test for */
if (!start || !end) {
return null
}
if (!start.source || !end.source || start.source !== end.source) {
return null
}
/* istanbul ignore if: edge case too hard to test for */
if (start.line === null || start.column === null) {
return null
}
/* istanbul ignore if: edge case too hard to test for */
if (end.line === null || end.column === null) {
if (discardPosition(start) || discardPosition(end) || start.source !== end.source) {
return null
}

Expand All @@ -72,6 +65,12 @@ function mapLocation (sourceMap, location) {
column: clampedEnd.column,
bias: 2
})

/* istanbul ignore if: edge case too hard to test for */
if (discardPosition(end)) {
return null
}

end.column = end.column - 1
}

Expand Down

0 comments on commit 0838a0e

Please sign in to comment.