You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
59 lines
1.4 KiB
3 years ago
|
var SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||
|
|
||
|
function inputSourceMapTracker() {
|
||
|
var maps = {};
|
||
|
|
||
|
return {
|
||
|
all: all.bind(null, maps),
|
||
|
isTracking: isTracking.bind(null, maps),
|
||
|
originalPositionFor: originalPositionFor.bind(null, maps),
|
||
|
track: track.bind(null, maps)
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function all(maps) {
|
||
|
return maps;
|
||
|
}
|
||
|
|
||
|
function isTracking(maps, source) {
|
||
|
return source in maps;
|
||
|
}
|
||
|
|
||
|
function originalPositionFor(maps, metadata, range, selectorFallbacks) {
|
||
|
var line = metadata[0];
|
||
|
var column = metadata[1];
|
||
|
var source = metadata[2];
|
||
|
var position = {
|
||
|
line: line,
|
||
|
column: column + range
|
||
|
};
|
||
|
var originalPosition;
|
||
|
|
||
|
while (!originalPosition && position.column > column) {
|
||
|
position.column--;
|
||
|
originalPosition = maps[source].originalPositionFor(position);
|
||
|
}
|
||
|
|
||
|
if (!originalPosition || originalPosition.column < 0) {
|
||
|
return metadata;
|
||
|
}
|
||
|
|
||
|
if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) {
|
||
|
return originalPositionFor(maps, [line - 1, column, source], range, selectorFallbacks - 1);
|
||
|
}
|
||
|
|
||
|
return originalPosition.line !== null ?
|
||
|
toMetadata(originalPosition) :
|
||
|
metadata;
|
||
|
}
|
||
|
|
||
|
function toMetadata(asHash) {
|
||
|
return [asHash.line, asHash.column, asHash.source];
|
||
|
}
|
||
|
|
||
|
function track(maps, source, data) {
|
||
|
maps[source] = new SourceMapConsumer(data);
|
||
|
}
|
||
|
|
||
|
module.exports = inputSourceMapTracker;
|