|
32 | 32 | Regex,
|
33 | 33 | CanAccessStringByIndex,
|
34 | 34 | typed,
|
35 |
| - jsdoc; |
| 35 | + jsdoc, |
| 36 | + isArray; |
36 | 37 |
|
37 | 38 | // Sync with package.json.
|
38 | 39 | VERSION = '0.0.4-dev';
|
|
48 | 49 | function sliceSource(source, index, last) {
|
49 | 50 | return source.slice(index, last);
|
50 | 51 | }
|
| 52 | + |
| 53 | + isArray = Array.isArray; |
| 54 | + if (!isArray) { |
| 55 | + isArray = function isArray(ary) { |
| 56 | + return Object.prototype.toString.call(ary) === '[object Array]'; |
| 57 | + }; |
| 58 | + } |
51 | 59 |
|
52 | 60 | if (!CanAccessStringByIndex) {
|
53 | 61 | sliceSource = function sliceSource(source, index, last) {
|
|
880 | 888 | expr = {
|
881 | 889 | type: Syntax.ParameterType,
|
882 | 890 | name: expr.name,
|
883 |
| - expression: parseTypeExpression(), |
| 891 | + expression: parseTypeExpression() |
884 | 892 | };
|
885 | 893 | }
|
886 | 894 | if (token === Token.EQUAL) {
|
|
1189 | 1197 | (function (exports) {
|
1190 | 1198 | var index,
|
1191 | 1199 | length,
|
1192 |
| - source; |
| 1200 | + source, |
| 1201 | + recoverable; |
1193 | 1202 |
|
1194 | 1203 | function advance() {
|
1195 | 1204 | var ch = source[index];
|
|
1366 | 1375 | title = scanTitle();
|
1367 | 1376 |
|
1368 | 1377 | // empty title
|
1369 |
| - if (!title) { |
| 1378 | + if (!title && !recoverable) { |
1370 | 1379 | return;
|
1371 | 1380 | }
|
1372 | 1381 |
|
|
1381 | 1390 | // type required titles
|
1382 | 1391 | if (isTypeParameterRequired(title)) {
|
1383 | 1392 | tag.type = parseType(title, last);
|
1384 |
| - if (!tag.type) { |
| 1393 | + if (!tag.type && !recoverable) { |
1385 | 1394 | return;
|
1386 | 1395 | }
|
1387 | 1396 | }
|
1388 | 1397 |
|
1389 | 1398 | // param, property requires name
|
1390 | 1399 | if (title === 'param' || title === 'property') {
|
1391 | 1400 | tag.name = parseName(last);
|
1392 |
| - if (!tag.name) { |
| 1401 | + if (!tag.name && !recoverable) { |
1393 | 1402 | return;
|
1394 | 1403 | }
|
1395 | 1404 | }
|
|
1408 | 1417 | }
|
1409 | 1418 |
|
1410 | 1419 | function parse(comment, options) {
|
1411 |
| - var tags = [], tag, description; |
| 1420 | + var tags = [], tag, description, interestingTags; |
1412 | 1421 |
|
1413 | 1422 | if (options === undefined) {
|
1414 | 1423 | options = {};
|
|
1419 | 1428 | } else {
|
1420 | 1429 | source = comment;
|
1421 | 1430 | }
|
| 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 | + } |
1422 | 1447 |
|
1423 | 1448 | if (!CanAccessStringByIndex) {
|
1424 | 1449 | source = source.split('');
|
1425 | 1450 | }
|
1426 | 1451 |
|
1427 | 1452 | length = source.length;
|
1428 | 1453 | index = 0;
|
| 1454 | + recoverable = options.recoverable; |
1429 | 1455 |
|
1430 | 1456 | description = trim(scanDescription());
|
1431 |
| - |
| 1457 | + |
1432 | 1458 | while (true) {
|
1433 | 1459 | tag = next();
|
1434 | 1460 | if (!tag) {
|
1435 | 1461 | break;
|
1436 | 1462 | }
|
1437 |
| - tags.push(tag); |
| 1463 | + if (!interestingTags || interestingTags.hasOwnProperty(tag.title)) { |
| 1464 | + tags.push(tag); |
| 1465 | + } |
1438 | 1466 | }
|
1439 | 1467 |
|
1440 | 1468 | return {
|
|
0 commit comments