embark/lib/modules/coverage/source_map.js

30 lines
707 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) {
2018-08-10 14:58:18 +00:00
return new SourceMap(this.offset, sourceMap.offset - this.offset);
2018-08-07 19:26:39 +00:00
}
toString() {
var parts = [this.offset, this.length];
if(this.id) parts.push(this.id);
return parts.join(':');
}
}
module.exports = SourceMap;