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

Commit 4a5823b

Browse files
committed
Merge pull request #132 from tmcw/parse-default-array
Parse array default syntax
2 parents 110f96e + 9e850e7 commit 4a5823b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/doctrine.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,21 @@
337337
}
338338

339339
if (useBrackets) {
340+
341+
340342
// do we have a default value for this?
341343
if (source.charCodeAt(index) === 0x3D /* '=' */) {
342-
343344
// consume the '='' symbol
344345
name += advance();
346+
var bracketDepth = 1;
345347
// scan in the default value
346-
while (index < last && source.charCodeAt(index) !== 0x5D /* ']' */) {
348+
while (index < last) {
349+
if (source.charCodeAt(index) === 0x5B /* '[' */) {
350+
bracketDepth++;
351+
} else if (source.charCodeAt(index) === 0x5D /* ']' */ &&
352+
--bracketDepth === 0) {
353+
break;
354+
}
347355
name += advance();
348356
}
349357
}

test/parse.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,28 @@ describe('optional params', function() {
19211921
});
19221922
});
19231923

1924+
it('default array', function() {
1925+
doctrine.parse(
1926+
["/**", " * @param {String} [val=['foo']] some description", " */"].join('\n'),
1927+
{ unwrap: true, sloppy: true}
1928+
).should.eql({
1929+
"description": "",
1930+
"tags": [{
1931+
"title": "param",
1932+
"description": "some description",
1933+
"type": {
1934+
"type": "OptionalType",
1935+
"expression": {
1936+
"type": "NameExpression",
1937+
"name": "String"
1938+
}
1939+
},
1940+
"name": "val",
1941+
"default": "['foo']"
1942+
}]
1943+
});
1944+
});
1945+
19241946
it('line numbers', function() {
19251947
var res = doctrine.parse(
19261948
[

0 commit comments

Comments
 (0)