Skip to content

Commit a289b56

Browse files
committed
Merge branch 'master' of github.com:Constellation/doctrine
2 parents 8287a3a + b71937b commit a289b56

File tree

3 files changed

+289
-18
lines changed

3 files changed

+289
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

doctrine.js

+37-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
Regex,
3333
CanAccessStringByIndex,
3434
typed,
35-
jsdoc;
35+
jsdoc,
36+
isArray;
3637

3738
// Sync with package.json.
3839
VERSION = '0.0.4-dev';
@@ -48,6 +49,13 @@
4849
function sliceSource(source, index, last) {
4950
return source.slice(index, last);
5051
}
52+
53+
isArray = Array.isArray;
54+
if (!isArray) {
55+
isArray = function isArray(ary) {
56+
return Object.prototype.toString.call(ary) === '[object Array]';
57+
};
58+
}
5159

5260
if (!CanAccessStringByIndex) {
5361
sliceSource = function sliceSource(source, index, last) {
@@ -880,7 +888,7 @@
880888
expr = {
881889
type: Syntax.ParameterType,
882890
name: expr.name,
883-
expression: parseTypeExpression(),
891+
expression: parseTypeExpression()
884892
};
885893
}
886894
if (token === Token.EQUAL) {
@@ -1189,7 +1197,8 @@
11891197
(function (exports) {
11901198
var index,
11911199
length,
1192-
source;
1200+
source,
1201+
recoverable;
11931202

11941203
function advance() {
11951204
var ch = source[index];
@@ -1366,7 +1375,7 @@
13661375
title = scanTitle();
13671376

13681377
// empty title
1369-
if (!title) {
1378+
if (!title && !recoverable) {
13701379
return;
13711380
}
13721381

@@ -1381,15 +1390,15 @@
13811390
// type required titles
13821391
if (isTypeParameterRequired(title)) {
13831392
tag.type = parseType(title, last);
1384-
if (!tag.type) {
1393+
if (!tag.type && !recoverable) {
13851394
return;
13861395
}
13871396
}
13881397

13891398
// param, property requires name
13901399
if (title === 'param' || title === 'property') {
13911400
tag.name = parseName(last);
1392-
if (!tag.name) {
1401+
if (!tag.name && !recoverable) {
13931402
return;
13941403
}
13951404
}
@@ -1408,7 +1417,7 @@
14081417
}
14091418

14101419
function parse(comment, options) {
1411-
var tags = [], tag, description;
1420+
var tags = [], tag, description, interestingTags;
14121421

14131422
if (options === undefined) {
14141423
options = {};
@@ -1419,22 +1428,41 @@
14191428
} else {
14201429
source = comment;
14211430
}
1431+
1432+
// array of relevant tags
1433+
if (options.tags) {
1434+
if (isArray(options.tags)) {
1435+
interestingTags = { };
1436+
for (var i = 0; i < options.tags.length; i++) {
1437+
if (typeof options.tags[i] === 'string') {
1438+
interestingTags[options.tags[i]] = true;
1439+
} else {
1440+
throw new Error('Invalid "tags" parameter: ' + options.tags);
1441+
}
1442+
}
1443+
} else {
1444+
throw new Error('Invalid "tags" parameter: ' + options.tags);
1445+
}
1446+
}
14221447

14231448
if (!CanAccessStringByIndex) {
14241449
source = source.split('');
14251450
}
14261451

14271452
length = source.length;
14281453
index = 0;
1454+
recoverable = options.recoverable;
14291455

14301456
description = trim(scanDescription());
1431-
1457+
14321458
while (true) {
14331459
tag = next();
14341460
if (!tag) {
14351461
break;
14361462
}
1437-
tags.push(tag);
1463+
if (!interestingTags || interestingTags.hasOwnProperty(tag.title)) {
1464+
tags.push(tag);
1465+
}
14381466
}
14391467

14401468
return {

0 commit comments

Comments
 (0)