You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
978 B
JavaScript

/**
* espower-location-detector:
* AST source location detection helper for power-assert
*
* https://github.com/twada/espower-location-detector
*
* Copyright (c) 2015-2016 Takuto Wada
* Licensed under the MIT license.
* https://github.com/twada/espower-location-detector/blob/master/LICENSE
*/
'use strict';
var PositionDetector = require('./lib/position-detector');
var SourceAdjuster = require('./lib/source-adjuster');
function EspowerLocationDetector (options) {
this.positionDetector = new PositionDetector(options.sourceMap);
this.sourceAdjuster = new SourceAdjuster(options.sourceRoot, options.path, options.sourceMap);
}
EspowerLocationDetector.prototype.locationFor = function (currentNode) {
var pos = this.positionDetector.positionFor(currentNode);
return {
source: this.sourceAdjuster.relativize(pos.source, pos.mapped),
line: pos.line,
column: pos.column
};
};
module.exports = EspowerLocationDetector;