Skip to content

Commit 56f4356

Browse files
committed
extractTypeFailsafe
1 parent a694d37 commit 56f4356

File tree

2 files changed

+67
-48
lines changed

2 files changed

+67
-48
lines changed

example.api.json

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
"brief": "",
4040
"description": ""
4141
},
42+
{
43+
"name": "del",
44+
"type": "MethodDoc",
45+
"scope": "instance",
46+
"brief": "",
47+
"description": ""
48+
},
4249
{
4350
"name": "logRecursive",
4451
"type": "MethodDoc",
@@ -47,7 +54,7 @@
4754
"description": ""
4855
},
4956
{
50-
"name": "splice",
57+
"name": "parse",
5158
"type": "MethodDoc",
5259
"scope": "instance",
5360
"brief": "",
@@ -215,7 +222,7 @@
215222
"description": "<p>Extracts the documentation of the node, if one exists. This also handles the case where the node\nitself is a documentation comment.</p>"
216223
},
217224
{
218-
"name": "extractDefaultValueClosureData",
225+
"name": "extractDataValue",
219226
"type": "FunctionDoc",
220227
"brief": "",
221228
"description": ""
@@ -226,14 +233,26 @@
226233
"brief": "",
227234
"description": ""
228235
},
236+
{
237+
"name": "extractIdentifier",
238+
"type": "FunctionDoc",
239+
"brief": "",
240+
"description": ""
241+
},
229242
{
230243
"name": "extractParams",
231244
"type": "FunctionDoc",
232245
"brief": "",
233246
"description": ""
234247
},
235248
{
236-
"name": "extractType",
249+
"name": "extractSymbol",
250+
"type": "FunctionDoc",
251+
"brief": "",
252+
"description": ""
253+
},
254+
{
255+
"name": "extractTypeFailsafe",
237256
"type": "FunctionDoc",
238257
"brief": "",
239258
"description": ""
@@ -280,12 +299,6 @@
280299
"brief": "",
281300
"description": ""
282301
},
283-
{
284-
"name": "isInstancePropertyAssignment",
285-
"type": "FunctionDoc",
286-
"brief": "",
287-
"description": ""
288-
},
289302
{
290303
"name": "isInterface",
291304
"type": "FunctionDoc",
@@ -329,13 +342,7 @@
329342
"description": ""
330343
},
331344
{
332-
"name": "matchDefaultValueClosure",
333-
"type": "FunctionDoc",
334-
"brief": "",
335-
"description": ""
336-
},
337-
{
338-
"name": "matchIdentifier",
345+
"name": "matchDataTypeClosure",
339346
"type": "FunctionDoc",
340347
"brief": "",
341348
"description": ""
@@ -377,13 +384,7 @@
377384
"description": "<ul>\n<li>Capture Phase: Documentation comments are extracted out of each file and assembled into\na temporary list of partial-doc trees.</li>\n<li>Transform Phase: Each file's partial-doc tree is transformed into docs and assembled in\nmonolithic doc-tree.</li>\n<li>Mod Phase: The &quot;@memberof&quot; tag is handled by moving docs to their final path;\n<this> member docs are moved to the appropriate scope.\nPlugins are allowed access to make any post-transform changes as well. Undocumented entities\nare removed from the doc-tree.</li>\n</ul>"
378385
},
379386
{
380-
"name": "parseAccess",
381-
"type": "FunctionDoc",
382-
"brief": "",
383-
"description": ""
384-
},
385-
{
386-
"name": "parseAuthor",
387+
"name": "parseAbstract",
387388
"type": "FunctionDoc",
388389
"brief": "",
389390
"description": ""
@@ -395,97 +396,97 @@
395396
"description": ""
396397
},
397398
{
398-
"name": "parseDefault",
399+
"name": "parseCopyright",
399400
"type": "FunctionDoc",
400401
"brief": "",
401402
"description": ""
402403
},
403404
{
404-
"name": "parseEnum",
405+
"name": "parseDeprecated",
405406
"type": "FunctionDoc",
406407
"brief": "",
407408
"description": ""
408409
},
409410
{
410-
"name": "parseExample",
411+
"name": "parseEvent",
411412
"type": "FunctionDoc",
412413
"brief": "",
413414
"description": ""
414415
},
415416
{
416-
"name": "parseExtends",
417+
"name": "parseFires",
417418
"type": "FunctionDoc",
418419
"brief": "",
419420
"description": ""
420421
},
421422
{
422-
"name": "parseInner",
423+
"name": "parseImplements",
423424
"type": "FunctionDoc",
424425
"brief": "",
425426
"description": ""
426427
},
427428
{
428-
"name": "parseMember",
429+
"name": "parseInstance",
429430
"type": "FunctionDoc",
430431
"brief": "",
431432
"description": ""
432433
},
433434
{
434-
"name": "parseMixes",
435+
"name": "parseLicense",
435436
"type": "FunctionDoc",
436437
"brief": "",
437438
"description": ""
438439
},
439440
{
440-
"name": "parseName",
441+
"name": "parsePrivate",
441442
"type": "FunctionDoc",
442443
"brief": "",
443444
"description": ""
444445
},
445446
{
446-
"name": "parseParam",
447+
"name": "parseProperty",
447448
"type": "FunctionDoc",
448449
"brief": "",
449450
"description": ""
450451
},
451452
{
452-
"name": "parseProtected",
453+
"name": "parsePublic",
453454
"type": "FunctionDoc",
454455
"brief": "",
455456
"description": ""
456457
},
457458
{
458-
"name": "parseReturn",
459+
"name": "parseScope",
459460
"type": "FunctionDoc",
460461
"brief": "",
461462
"description": ""
462463
},
463464
{
464-
"name": "parseSee",
465+
"name": "parseSince",
465466
"type": "FunctionDoc",
466467
"brief": "",
467468
"description": ""
468469
},
469470
{
470-
"name": "parseStatic",
471+
"name": "parseStepType",
471472
"type": "FunctionDoc",
472473
"brief": "",
473474
"description": ""
474475
},
475476
{
476-
"name": "parseStepType",
477+
"name": "parseTodo",
477478
"type": "FunctionDoc",
478479
"brief": "",
479480
"description": ""
480481
},
481482
{
482-
"name": "parseThrows",
483+
"name": "parseType",
483484
"type": "FunctionDoc",
484485
"brief": "",
485486
"description": ""
486487
},
487488
{
488-
"name": "parseTypedef",
489+
"name": "parseTypedDescription",
489490
"type": "FunctionDoc",
490491
"brief": "",
491492
"description": ""
@@ -566,7 +567,7 @@
566567
"description": ""
567568
},
568569
{
569-
"name": "resolveInit",
570+
"name": "resolveFlowDataType",
570571
"type": "FunctionDoc",
571572
"brief": "",
572573
"description": ""
@@ -578,25 +579,25 @@
578579
"description": ""
579580
},
580581
{
581-
"name": "resolveObject",
582+
"name": "resolveRelated",
582583
"type": "FunctionDoc",
583584
"brief": "",
584-
"description": ""
585+
"description": "<ul>\n<li>\n<p>Resolves all docs listed in the &quot;extends&quot;, &quot;implements&quot;, &quot;mixes&quot;. This prevent redundant\nsearches to extended/implemented/mixed symbols.</p>\n</li>\n<li>\n<p>Replaces the &quot;default&quot; scopes for properties with a good guess. (The @property tag parser puts\n&quot;default&quot; scope on the PropertyDocs it creates)</p>\n</li>\n<li>\n<p>Brings down any methods/properties coming from parent classes &amp; mixins. Adds the implementation\nproperty to methods/properties that come from interfaces.</p>\n</li>\n</ul>"
585586
},
586587
{
587-
"name": "resolveRelated",
588+
"name": "resolveReturn",
588589
"type": "FunctionDoc",
589590
"brief": "",
590-
"description": "<ul>\n<li>\n<p>Resolves all docs listed in the &quot;extends&quot;, &quot;implements&quot;, &quot;mixes&quot;. This prevent redundant\nsearches to extended/implemented/mixed symbols.</p>\n</li>\n<li>\n<p>Replaces the &quot;default&quot; scopes for properties with a good guess. (The @property tag parser puts\n&quot;default&quot; scope on the PropertyDocs it creates)</p>\n</li>\n<li>\n<p>Brings down any methods/properties coming from parent classes &amp; mixins. Adds the implementation\nproperty to methods/properties that come from interfaces.</p>\n</li>\n</ul>"
591+
"description": ""
591592
},
592593
{
593-
"name": "resolveToObject",
594+
"name": "resolveRootObject",
594595
"type": "FunctionDoc",
595596
"brief": "",
596597
"description": ""
597598
},
598599
{
599-
"name": "resolveTSDataType",
600+
"name": "resolveToObject",
600601
"type": "FunctionDoc",
601602
"brief": "",
602603
"description": ""

packages/webdoc-parser/src/symbols-babel/extract-metadata.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,33 @@ export function extractReturns(
215215
node: ClassMethod | ObjectMethod | FunctionDeclaration | FunctionExpression,
216216
): $Shape<Return>[] {
217217
if (node.returnType) {
218-
return [{dataType: extractType(node.returnType)}];
218+
return [{dataType: extractTypeFailsafe(node.returnType)}];
219219
}
220220
if (node.typeAnnotation) {
221-
return [{dataType: extractType(node.typeAnnotation)}];
221+
return [{dataType: extractTypeFailsafe(node.typeAnnotation)}];
222222
}
223223

224224
return [];
225225
}
226226

227+
// Failsafe
228+
export function extractTypeFailsafe(
229+
node: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | any,
230+
): DataType {
231+
if (node.typeAnnotation) {
232+
if (isFlowType(node.typeAnnotation) || mode.current === "flow") {
233+
return resolveFlowDataType(node.typeAnnotation);
234+
}
235+
236+
return resolveTSDataType(node.typeAnnotation);
237+
}
238+
239+
console.error(node);
240+
console.error("Failsafe type extraction found invalid type.");
241+
242+
return createSimpleKeywordType("invalid");
243+
}
244+
227245
// Extract the data-type for a property
228246
export function extractType(
229247
node: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | any,

0 commit comments

Comments
 (0)