less-error.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var utils = require("./utils");
  2. var LessError = module.exports = function LessError(e, importManager, currentFilename) {
  3. Error.call(this);
  4. var filename = e.filename || currentFilename;
  5. if (importManager && filename) {
  6. var input = importManager.contents[filename],
  7. loc = utils.getLocation(e.index, input),
  8. line = loc.line,
  9. col = loc.column,
  10. callLine = e.call && utils.getLocation(e.call, input).line,
  11. lines = input.split('\n');
  12. this.type = e.type || 'Syntax';
  13. this.filename = filename;
  14. this.index = e.index;
  15. this.line = typeof line === 'number' ? line + 1 : null;
  16. this.callLine = callLine + 1;
  17. this.callExtract = lines[callLine];
  18. this.column = col;
  19. this.extract = [
  20. lines[line - 1],
  21. lines[line],
  22. lines[line + 1]
  23. ];
  24. }
  25. this.message = e.message;
  26. this.stack = e.stack;
  27. };
  28. if (typeof Object.create === 'undefined') {
  29. var F = function () {};
  30. F.prototype = Error.prototype;
  31. LessError.prototype = new F();
  32. } else {
  33. LessError.prototype = Object.create(Error.prototype);
  34. }
  35. LessError.prototype.constructor = LessError;