Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
fix: Allow array indexes in names (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Aug 18, 2017
1 parent 9aed54d commit 1c4a4c7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/doctrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@

function scanIdentifier(last) {
var identifier;
if (!esutils.code.isIdentifierStartES5(source.charCodeAt(index))) {
if (!esutils.code.isIdentifierStartES5(source.charCodeAt(index)) && !source[index].match(/[0-9]/)) {
return null;
}
identifier = advance();
Expand Down Expand Up @@ -294,13 +294,13 @@
return null;
}

if (allowBrackets && source.charCodeAt(index) === 0x5B /* '[' */) {
useBrackets = true;
name = advance();
}

if (!esutils.code.isIdentifierStartES5(source.charCodeAt(index))) {
return null;
if (source.charCodeAt(index) === 0x5B /* '[' */) {
if (allowBrackets) {
useBrackets = true;
name = advance();
} else {
return null;
}
}

name += scanIdentifier(last);
Expand Down
35 changes: 35 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,41 @@ describe('parse', function () {
});
});

it('param with array indexes', function () {
var res = doctrine.parse(
[
"/**",
" * @param {String} user.0",
"*/"
].join('\n'), { unwrap: true });
res.tags.should.have.length(1);
res.tags[0].should.have.property('title', 'param');
res.tags[0].should.have.property('name', 'user.0');
res.tags[0].should.have.property('type');
res.tags[0].type.should.eql({
type: 'NameExpression',
name: 'String'
});
});

it('param with array indexes and descriptions', function () {
var res = doctrine.parse(
[
"/**",
" * @param {String} user.0 The first element",
"*/"
].join('\n'), { unwrap: true });
res.tags.should.have.length(1);
res.tags[0].should.have.property('title', 'param');
res.tags[0].should.have.property('name', 'user.0');
res.tags[0].should.have.property('type');
res.tags[0].should.have.property('description', 'The first element');
res.tags[0].type.should.eql({
type: 'NameExpression',
name: 'String'
});
});

it('arg with properties', function () {
var res = doctrine.parse(
[
Expand Down

0 comments on commit 1c4a4c7

Please sign in to comment.