Skip to content

Commit ecbe333

Browse files
committed
improve tests & fix array parsing
1 parent 9861453 commit ecbe333

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/parser.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ Parser.prototype.parseStatement = function () {
586586
}
587587
return {
588588
kind: 'word',
589-
value: this.lexer.text
589+
value: this.lexer.backup.text
590590
};
591591
}
592592

@@ -630,16 +630,6 @@ Parser.prototype.readArray = function (endChar) {
630630
var item = this.parseTopStatement();
631631
if (item !== null) { // ignore
632632
item = this.getJsonValue(item);
633-
if (this.token === '=>') {
634-
this.token = this.lexer.lex(); // eat
635-
item = {
636-
kind: 'key',
637-
name: item,
638-
value: this.getJsonValue(
639-
this.parseTopStatement()
640-
)
641-
};
642-
}
643633
result.push(item);
644634
if (this.token !== ',') {
645635
break;

test/parser.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,33 @@ describe('Test parser', function () {
261261
ast.body[2].kind.should.be.exactly('object');
262262
should.equal(ast.body[2].value, null);
263263
});
264+
265+
it('test getJsonValue', function () {
266+
var ast = doc.parse([
267+
'/**',
268+
' * @object { foo: { bar: false }, "key": [1, 2, 3] }',
269+
' */'
270+
].join('\n'));
271+
ast.body[0].kind.should.be.exactly('object');
272+
ast.body[0].value.should.be.eql({foo: {bar: false}, key: [1, 2, 3]});
273+
});
274+
275+
it('test readArray', function () {
276+
var ast = doc.parse([
277+
'/**',
278+
' * @array [foo => bar, 1, 2, array]',
279+
' */'
280+
].join('\n'));
281+
ast.body[0].kind.should.be.exactly('array');
282+
ast.body[0].value.should.be.eql([
283+
{
284+
kind: 'key',
285+
name: 'foo',
286+
value: 'bar'
287+
},
288+
1,
289+
2,
290+
'array'
291+
]);
292+
});
264293
});

0 commit comments

Comments
 (0)