-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
18 changed files
with
150 additions
and
241 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,5 +1,9 @@ | ||
# CHANGELOG | ||
|
||
## v4.9.0 | ||
|
||
1. 增强调试功能:日志输出错误行号以及上下文 | ||
|
||
## v4.8.2 | ||
|
||
1. 修复子模板没有继承父模板编译 options 问题 | ||
|
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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,17 +1,68 @@ | ||
'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; } | ||
|
||
/** | ||
* 模板错误处理类 | ||
*/ | ||
function TemplateError(error) { | ||
var stack = error.stack; | ||
delete error.stack; | ||
this.name = 'TemplateError'; | ||
this.message = JSON.stringify(error, null, 4); | ||
this.stack = stack; | ||
} | ||
|
||
TemplateError.prototype = Object.create(Error.prototype); | ||
TemplateError.prototype.constructor = TemplateError; | ||
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]) { | ||
|
||
if (error.source) { | ||
message = TemplateError.debug(error); | ||
} | ||
|
||
_this.path = error.path; | ||
} | ||
|
||
_this.name = 'TemplateError'; | ||
_this.message = message; | ||
return _this; | ||
} | ||
|
||
TemplateError.debug = function debug(error) { | ||
var source = error.source, | ||
path = error.path, | ||
line = error.line, | ||
column = error.column; | ||
|
||
|
||
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'); | ||
|
||
// Alter exception message | ||
return (path || 'anonymous') + ':' + line + ':' + column + '\n' + (context + '\n\n') + ('' + error.message); | ||
}; | ||
|
||
return TemplateError; | ||
}(Error); | ||
|
||
; | ||
|
||
TemplateError.debugTypes = { | ||
'RuntimeError': true, | ||
'CompileError': true | ||
}; | ||
|
||
module.exports = TemplateError; |
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
Oops, something went wrong.