Skip to content

Commit 0838a0e

Browse files
novemberbornbcoe
authored andcommitted
fix: discard more bad source map positions (#255)
1 parent 0a78ad5 commit 0838a0e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/source-map-cache.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function clampPosition (pos) {
4040
}
4141
}
4242

43+
function discardPosition (pos) {
44+
return !pos || !pos.source || pos.line === null || pos.column === null
45+
}
46+
4347
// Maps the coverage location based on the source map. Adapted from getMapping()
4448
// in remap-istanbul:
4549
// <https://github.com/SitePen/remap-istanbul/blob/30b67ad3f24ba7e0da8b8888d5a7c3c8480d48b2/lib/remap.js#L55:L108>.
@@ -51,18 +55,7 @@ function mapLocation (sourceMap, location) {
5155
var end = sourceMap.originalPositionFor(clampedEnd)
5256

5357
/* istanbul ignore if: edge case too hard to test for */
54-
if (!start || !end) {
55-
return null
56-
}
57-
if (!start.source || !end.source || start.source !== end.source) {
58-
return null
59-
}
60-
/* istanbul ignore if: edge case too hard to test for */
61-
if (start.line === null || start.column === null) {
62-
return null
63-
}
64-
/* istanbul ignore if: edge case too hard to test for */
65-
if (end.line === null || end.column === null) {
58+
if (discardPosition(start) || discardPosition(end) || start.source !== end.source) {
6659
return null
6760
}
6861

@@ -72,6 +65,12 @@ function mapLocation (sourceMap, location) {
7265
column: clampedEnd.column,
7366
bias: 2
7467
})
68+
69+
/* istanbul ignore if: edge case too hard to test for */
70+
if (discardPosition(end)) {
71+
return null
72+
}
73+
7574
end.column = end.column - 1
7675
}
7776

0 commit comments

Comments
 (0)