Add error function

This commit is contained in:
Rafael Caricio 2014-09-05 10:28:40 +02:00
parent 1bff218ad1
commit 7c25967e5e
2 changed files with 16 additions and 2 deletions

View file

@ -27,6 +27,14 @@ var GradientParser = module.exports = (function() {
comma: /^,/
};
function error(input, cursor, msg) {
var err = new Error(input + ':' + cursor + ': ' + msg);
err.position = cursor;
err.message = msg;
err.source = input;
throw err;
}
function Constructor(input) {
this.input = input;
this.cursor = 0;
@ -38,7 +46,14 @@ var GradientParser = module.exports = (function() {
if (input) {
this.input = input;
}
return this.listDefinitions();
var ast = this.listDefinitions();
if (this.input) {
error(input, cursor, 'Invalid input not EOF');
}
return ast;
};
def.listDefinitions = function() {

View file

@ -42,7 +42,6 @@ describe('gradient-parser.js', function () {
beforeEach(function() {
var parser = new GradientParser();
ast = parser.parse('linear-gradient(to right bottom, red, blue)');
console.log(ast);
});
it('should get the gradient type', function () {