embark/lib/modules/coverage/source_map.js

31 lines
732 B
JavaScript
Raw Normal View History

2018-08-07 19:26:39 +00:00
class SourceMap {
constructor(sourceMapStringOrOffset, length, id) {
if(typeof sourceMapStringOrOffset == 'string') {
2018-08-09 20:46:20 +00:00
let [offset, length, id, ..._rest] = sourceMapStringOrOffset.split(":");
2018-08-07 19:26:39 +00:00
this.offset = parseInt(offset, 10);
this.length = parseInt(length, 10);
if(id) this.id = parseInt(id, 10);
} else {
this.offset = sourceMapStringOrOffset;
this.length = length;
this.id = id;
}
}
subtract(sourceMap) {
var length = sourceMap.offset - this.offset;
return new SourceMap(this.offset, length);
}
toString() {
var parts = [this.offset, this.length];
if(this.id) parts.push(this.id);
return parts.join(':');
}
}
module.exports = SourceMap;