Add error function
This commit is contained in:
parent
1bff218ad1
commit
7c25967e5e
2 changed files with 16 additions and 2 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue