Files
less.js/lib/less/less-error.js
2015-01-30 18:28:02 +00:00

43 lines
1.2 KiB
JavaScript

var utils = require("./utils");
var LessError = module.exports = function LessError(e, importManager, currentFilename) {
Error.call(this);
var filename = e.filename || currentFilename;
if (importManager && filename) {
var input = importManager.contents[filename],
loc = utils.getLocation(e.index, input),
line = loc.line,
col = loc.column,
callLine = e.call && utils.getLocation(e.call, input).line,
lines = input.split('\n');
this.type = e.type || 'Syntax';
this.filename = filename;
this.index = e.index;
this.line = typeof line === 'number' ? line + 1 : null;
this.callLine = callLine + 1;
this.callExtract = lines[callLine];
this.column = col;
this.extract = [
lines[line - 1],
lines[line],
lines[line + 1]
];
}
this.message = e.message;
this.stack = e.stack;
};
if (typeof Object.create === 'undefined') {
var F = function () {};
F.prototype = Error.prototype;
LessError.prototype = new F();
} else {
LessError.prototype = Object.create(Error.prototype);
}
LessError.prototype.constructor = LessError;