Skip to content

Commit

Permalink
fix: discard more bad source map positions (#3)
Browse files Browse the repository at this point in the history
Restore code that was introduced in nyc 6.5.0 to handle bad source map locations. This fix was originally introduced into nyc's lib/source-map-cache.js, but when nyc transitioned to using istanbul-lib-source-maps this fix went astray.

see original PR: istanbuljs/nyc#255
  • Loading branch information
sdd authored and bcoe committed Aug 31, 2016
1 parent 8c43f14 commit ed7b27f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/transformer.js
Expand Up @@ -8,13 +8,25 @@ var pathutils = require('./pathutils'),
libCoverage = require('istanbul-lib-coverage'),
MappedCoverage = require('./mapped').MappedCoverage;

function isInvalidPosition (pos) {
return !pos || !pos.line || !pos.column || pos.line < 0 || pos.column < 0;
}

/**
* determines the original position for a given location
* @param {SourceMapConsumer} sourceMap the source map
* @param {Object} location the original location Object
* @returns {Object} the remapped location Object
*/
function getMapping(sourceMap, location, origFile) {

if (!location) {
return null;
}

if (isInvalidPosition(location.start) || isInvalidPosition(location.end)) {
return null;
}

var start = sourceMap.originalPositionFor(location.start),
end = sourceMap.originalPositionFor(location.end);
Expand Down

0 comments on commit ed7b27f

Please sign in to comment.