Skip to content

Commit

Permalink
fix the backup state reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiriac committed Jan 8, 2017
1 parent cf2eb94 commit ca58ab2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ Lexer.prototype.unlex = function (state) {
if (!state) {
state = this.backup;
}
this.backup = null;
if (state) {
this.offset = state.offset;
this.text = state.text;
this.token = state.token;
this.line = state.line;
if (state.backup) {
this.backup = state.backup;
}
}
this.backup = null;
return this.token;
};

Expand All @@ -103,7 +106,8 @@ Lexer.prototype.state = function () {
offset: this.offset,
text: this.text,
token: this.token,
line: this.line
line: this.line,
backup: this.backup
};
};
/**
Expand Down
1 change: 0 additions & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ Parser.prototype.parseRule = function (rule) {
var result = this.parsers[rule.parser].apply(this, []);
if (result === null) {
this.lexer.unlex(backup);
this.lexer.backup = backup;
if (typeof rule.default !== 'undefined') {
return rule.default;
}
Expand Down
13 changes: 13 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,17 @@ describe('Test parser', function () {
ast.body[0].name.should.be.exactly('var');
ast.body[0].description.should.be.exactly('Foo is Bar');
});

it('test param defaults', function () {
var ast = doc.parse([
'/**',
' * Description',
' * @param String Foo is Bar',
' */'
].join('\n'));
ast.body[0].kind.should.be.exactly('param');
ast.body[0].type.name.should.be.exactly('String');
should.equal(ast.body[0].name, null);
ast.body[0].description.should.be.exactly('Foo is Bar');
});
});

0 comments on commit ca58ab2

Please sign in to comment.