From 1b2be8e03a548f7fba7b5fd3b1eb024a0af13c4f Mon Sep 17 00:00:00 2001 From: Mourad Kejji Date: Tue, 29 Jan 2019 15:23:21 +0100 Subject: [PATCH] Added support for empty arrays in blocks annotations --- src/parser.js | 4 ++++ test/parser.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/parser.js b/src/parser.js index 2c2f76b..94bd05d 100644 --- a/src/parser.js +++ b/src/parser.js @@ -644,6 +644,10 @@ Parser.prototype.parseStatement = function () { Parser.prototype.readArray = function (endChar) { var result = []; this.token = this.lexer.lex(); // consume start char + if (this.token === endChar) { + this.token = this.lexer.lex(); + return result; + } do { var item = this.parseTopStatement(); if (item !== null) { // ignore diff --git a/test/parser.js b/test/parser.js index 19bbd31..4ebf47d 100644 --- a/test/parser.js +++ b/test/parser.js @@ -332,4 +332,18 @@ describe('Test parser', function () { ast.body[0].kind.should.be.exactly('annotation'); ast.body[0].arguments.length.should.be.exactly(0); }); + + it('test empty array annotation', function () { + var ast = doc.parse([ + '/**', + ' * @SomeArray[]', + ' * @SomeOtherAnnotation', + ' */' + ].join('\n')); + ast.body.length.should.be.exactly(2); + ast.body[0].kind.should.be.exactly('block'); + ast.body[0].options.length.should.be.exactly(1); + ast.body[0].options[0].kind.should.be.exactly('array'); + ast.body[0].options[0].value.length.should.be.exactly(0); + }); });