forked from goofychris/art-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,48 @@ | ||
'use strict'; | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
/** | ||
* 模板错误处理类 | ||
*/ | ||
var TemplateError = function (_Error) { | ||
_inherits(TemplateError, _Error); | ||
|
||
function TemplateError(error) { | ||
_classCallCheck(this, TemplateError); | ||
|
||
var _this = _possibleConstructorReturn(this, _Error.call(this, error)); | ||
|
||
var message = error.message; | ||
|
||
if (TemplateError.debugTypes[error.name]) { | ||
function TemplateError(error) { | ||
var that = Error.call(this, error.message); | ||
that.name = 'TemplateError'; | ||
that.message = debugMessage(error); | ||
|
||
if (error.source) { | ||
message = TemplateError.debug(error); | ||
} | ||
|
||
_this.path = error.path; | ||
} | ||
|
||
_this.name = 'TemplateError'; | ||
_this.message = message; | ||
return _this; | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(that, that.constructor); | ||
} | ||
return that; | ||
}; | ||
|
||
TemplateError.debug = function debug(error) { | ||
var source = error.source, | ||
path = error.path, | ||
line = error.line, | ||
column = error.column; | ||
|
||
TemplateError.prototype = Object.create(Error.prototype); | ||
TemplateError.prototype.constructor = TemplateError; | ||
|
||
var lines = source.split(/\n/); | ||
var start = Math.max(line - 3, 0); | ||
var end = Math.min(lines.length, line + 3); | ||
function debugMessage(_ref) { | ||
var source = _ref.source, | ||
path = _ref.path, | ||
line = _ref.line, | ||
column = _ref.column, | ||
message = _ref.message; | ||
|
||
// Error context | ||
var context = lines.slice(start, end).map(function (code, index) { | ||
var number = index + start + 1; | ||
var left = number === line ? ' >> ' : ' '; | ||
return '' + left + number + '| ' + code; | ||
}).join('\n'); | ||
|
||
// Alter exception message | ||
return (path || 'anonymous') + ':' + line + ':' + column + '\n' + (context + '\n\n') + ('' + error.message); | ||
}; | ||
if (!source) { | ||
return message; | ||
} | ||
|
||
return TemplateError; | ||
}(Error); | ||
var lines = source.split(/\n/); | ||
var start = Math.max(line - 3, 0); | ||
var end = Math.min(lines.length, line + 3); | ||
|
||
; | ||
// Error context | ||
var context = lines.slice(start, end).map(function (code, index) { | ||
var number = index + start + 1; | ||
var left = number === line ? ' >> ' : ' '; | ||
return '' + left + number + '| ' + code; | ||
}).join('\n'); | ||
|
||
TemplateError.debugTypes = { | ||
'RuntimeError': true, | ||
'CompileError': true | ||
}; | ||
// Alter exception message | ||
return (path || 'anonymous') + ':' + line + ':' + column + '\n' + (context + '\n\n') + ('' + message); | ||
} | ||
|
||
module.exports = TemplateError; |
Oops, something went wrong.