2018-08-20 17:54:44 +00:00
|
|
|
class EmptySourceMap {
|
|
|
|
static createRelativeTo(sourceMapString) {
|
|
|
|
if(sourceMapString == '') return EmptySourceMap;
|
|
|
|
|
|
|
|
return new SourceMap(sourceMapString);
|
|
|
|
}
|
|
|
|
|
|
|
|
static toString() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 19:26:39 +00:00
|
|
|
class SourceMap {
|
2018-08-20 17:54:44 +00:00
|
|
|
constructor(sourceMapStringOrOffset, length, id, jump) {
|
2018-08-07 19:26:39 +00:00
|
|
|
if(typeof sourceMapStringOrOffset == 'string') {
|
2018-08-20 17:54:44 +00:00
|
|
|
let [offset, length, id, jump] = 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);
|
2018-08-20 17:54:44 +00:00
|
|
|
this.jump = jump;
|
2018-08-07 19:26:39 +00:00
|
|
|
} else {
|
|
|
|
this.offset = sourceMapStringOrOffset;
|
|
|
|
this.length = length;
|
|
|
|
this.id = id;
|
2018-08-20 17:54:44 +00:00
|
|
|
this.jump = jump;
|
2018-08-07 19:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 17:54:44 +00:00
|
|
|
createRelativeTo(sourceMapString) {
|
|
|
|
if(sourceMapString == '' || sourceMapString == undefined) return EmptySourceMap;
|
|
|
|
|
|
|
|
let [offset, length, id, jump] = sourceMapString.split(":");
|
|
|
|
|
|
|
|
(offset == '') ? offset = this.offset : offset = parseInt(offset, 10);
|
|
|
|
(id == '' || id == undefined) ? id = this.id : id = parseInt(id, 10);
|
|
|
|
length = parseInt(length, 10);
|
|
|
|
|
|
|
|
return new SourceMap(offset, length, id, jump);
|
|
|
|
}
|
|
|
|
|
2018-08-07 19:26:39 +00:00
|
|
|
subtract(sourceMap) {
|
2018-08-20 17:54:44 +00:00
|
|
|
return new SourceMap(this.offset, sourceMap.offset - this.offset, this.id, this.jump);
|
2018-08-07 19:26:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 17:54:44 +00:00
|
|
|
toString(defaultId) {
|
|
|
|
let parts = [this.offset, this.length];
|
|
|
|
|
|
|
|
if(this.id !== undefined && this.id != '') {
|
|
|
|
parts.push(this.id)
|
|
|
|
} else if(defaultId !== undefined) {
|
|
|
|
parts.push(defaultId);
|
|
|
|
}
|
2018-08-07 19:26:39 +00:00
|
|
|
|
|
|
|
return parts.join(':');
|
|
|
|
}
|
2018-08-20 17:54:44 +00:00
|
|
|
|
|
|
|
static empty() {
|
|
|
|
return EmptySourceMap;
|
|
|
|
}
|
2018-08-07 19:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SourceMap;
|