refactor: tests for tags

This commit is contained in:
harttle
2016-09-26 21:52:06 +08:00
parent afca74b238
commit ddc17a6b93
27 changed files with 724 additions and 408 deletions
+17 -13
View File
@@ -1,20 +1,24 @@
function TokenizationError(message, input, line, stack) {
this.name = "TokenizationError";
this.message = (message || "");
this.input = input;
this.line = line;
if(stack) this.stack = stack;
}
TokenizationError.prototype = Error.prototype;
const util = require('util');
function ParseError(message, input, line, stack) {
this.name = "ParseError";
this.message = (message || "");
function TokenizationError(message, input, line) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message || "";
this.input = input;
this.line = line;
if(stack) this.stack = stack;
}
ParseError.prototype = Error.prototype;
util.inherits(TokenizationError, Error);
function ParseError(message, input, line) {
Error.captureStackTrace(this, this.constructor);
this.name = "ParseError";
this.message = message || "";
this.input = input;
this.line = line;
}
util.inherits(ParseError, Error);
module.exports = {
TokenizationError, ParseError
+1 -2
View File
@@ -1,5 +1,4 @@
const lexical = require('./lexical.js');
const error = require('./error.js');
const ParseError = require('./error.js').ParseError;
module.exports = function(Tag, Filter) {
@@ -60,7 +59,7 @@ module.exports = function(Tag, Filter) {
return token;
}
} catch (e) {
throw new ParseError(e.message, token.input, token.line, e.stack);
throw new ParseError(e.message, token.input, token.line);
}
}
+2 -3
View File
@@ -1,6 +1,5 @@
const _ = require('lodash');
const lexical = require('./lexical.js');
const error = require('./error.js');
var scope = {
get: function(str) {
@@ -21,7 +20,7 @@ var scope = {
return this;
},
push: function(ctx) {
if (!ctx) error(`trying to push ${ctx} into scopes`);
if (!ctx) throw new Error(`trying to push ${ctx} into scopes`);
return this.scopes.push(ctx);
},
pop: function() {
@@ -31,6 +30,6 @@ var scope = {
exports.factory = function(_ctx) {
var ctx = Object.create(scope);
ctx.scopes = _ctx ? [_ctx] : [];
ctx.scopes = [_ctx || {}];
return ctx;
};