MCPcopy Create free account
hub / github.com/arktypeio/arktype / docgenForFile

Function docgenForFile

ark/repo/jsdocGen.ts:540–587  ·  view source on GitHub ↗
(sourceFile: SourceFile)

Source from the content-addressed store, hash-verified

538}
539
540const 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
589const findInheritedDocs = (
590 sourceFile: SourceFile,

Callers 1

jsDocGenFunction · 0.85

Calls 5

extractInheritDocNameFunction · 0.85
findInheritedDocsFunction · 0.85
removeMethod · 0.80
reduceMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected