(sourceFile: SourceFile)
| 538 | } |
| 539 | |
| 540 | const docgenForFile = (sourceFile: SourceFile) => { |
| 541 | const path = sourceFile.getFilePath() |
| 542 | |
| 543 | const jsDocNodes = sourceFile.getDescendantsOfKind(SyntaxKind.JSDoc) |
| 544 | |
| 545 | const matchContexts: MatchContext[] = jsDocNodes.flatMap(jsDoc => { |
| 546 | const text = jsDoc.getText() |
| 547 | |
| 548 | const inheritDocsSource = extractInheritDocName(path, text) |
| 549 | |
| 550 | if ( |
| 551 | !inheritDocsSource && |
| 552 | !Object.keys(replacedDecorators).some(k => text.includes(k)) |
| 553 | ) |
| 554 | return [] |
| 555 | |
| 556 | return { |
| 557 | matchedJsDoc: jsDoc, |
| 558 | inheritDocsSource, |
| 559 | updateJsDoc: text => { |
| 560 | const parent = jsDoc.getParent() as JSDocableNode |
| 561 | |
| 562 | // replace the original JSDoc node in the AST with a new one |
| 563 | // created from updatedContents |
| 564 | jsDoc.remove() |
| 565 | parent.addJsDoc(text) |
| 566 | |
| 567 | updateCount++ |
| 568 | } |
| 569 | } |
| 570 | }) |
| 571 | |
| 572 | for (const ctx of matchContexts) { |
| 573 | const inheritedDocs = findInheritedDocs(sourceFile, ctx) |
| 574 | |
| 575 | let updatedContents = ctx.matchedJsDoc.getInnerText() |
| 576 | |
| 577 | if (inheritedDocs) |
| 578 | updatedContents = `${inheritedDocs.originalSummary}\n${inheritedDocs.inheritedDescription}` |
| 579 | |
| 580 | updatedContents = Object.entries(replacedDecorators).reduce( |
| 581 | (contents, [decorator, message]) => contents.replace(decorator, message), |
| 582 | updatedContents |
| 583 | ) |
| 584 | |
| 585 | ctx.updateJsDoc(updatedContents) |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | const findInheritedDocs = ( |
| 590 | sourceFile: SourceFile, |
no test coverage detected