MCPcopy Create free account
hub / github.com/effect-app/libs / extractJSDocsSync

Function extractJSDocsSync

repos/effect/packages/tools/jsdocs/src/Jsdocs.ts:3259–3338  ·  view source on GitHub ↗
(options: ExtractJSDocsOptions)

Source from the content-addressed store, hash-verified

3257}
3258
3259function parseSourceFileDocs(
3260 cwd: string,
3261 sourceFile: ts.SourceFile,
3262 checker: ts.TypeChecker,
3263 entry: ProgramCacheEntry
3264): { readonly parsed: ParsedJSDocFile; readonly diagnostics: ReadonlyArray<JSDocModelDiagnostic> } {
3265 const diagnostics: Array<JSDocModelDiagnostic> = []
3266 const declarations: Array<ParsedRootDeclaration> = []
3267 const namespaces: Array<ParsedNamespace> = []
3268 const linkContext = { checker, entry, cwd }
3269 const checkedFunctionOverloads = new Set<string>()
3270 const moduleJSDoc = sourceFileTopLevelJSDoc(sourceFile)
3271 const parsedModuleJSDoc = moduleJSDoc === undefined
3272 ? undefined
3273 : parseModuleJSDocTs(sourceFile, moduleJSDoc, diagnostics, linkContext)
3274
3275 for (const statement of sourceFile.statements) {
3276 if (ts.isExportAssignment(statement)) continue
3277 if (ts.isExportDeclaration(statement)) {
3278 if (statement.exportClause === undefined) continue
3279 if (ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 0) {
3280 diagnostics.push({
3281 ...diagnostic("empty-export", "Empty export declarations are not allowed"),
3282 range: nodeRange(statement)
3283 })
3284 }
3285 if (ts.isNamedExports(statement.exportClause)) {
3286 for (const specifier of statement.exportClause.elements) {
3287 const documented = parseDocumentedTs(specifier, "declaration", diagnostics, true, linkContext)
3288 if (documented === undefined) continue
3289 declarations.push({
3290 name: specifier.name.text,
3291 bucket: statement.isTypeOnly || specifier.isTypeOnly ? "type" : "value",
3292 signature: exportSpecifierSignature(
3293 specifier.name.text,
3294 statement.isTypeOnly || specifier.isTypeOnly ? "type" : "value",
3295 specifier,
3296 checker,
3297 cwd
3298 ),
3299 range: nodeRange(specifier),
3300 description: documented.core.description,
3301 examples: documented.core.examples,
3302 tags: documented.tags as ParsedDeclarationTags,
3303 members: []
3304 })
3305 }
3306 }
3307 continue
3308 }
3309 if (!hasExportModifier(statement) || hasDefaultModifier(statement)) continue
3310 if (ts.isModuleDeclaration(statement)) {
3311 const namespace = parseNamespaceTs(statement, diagnostics, linkContext)
3312 if (namespace !== undefined) namespaces.push(namespace)
3313 continue
3314 }
3315 if (ts.isEnumDeclaration(statement)) {
3316 diagnostics.push({ ...diagnostic("enum", "Enums are not allowed"), range: nodeRange(statement) })

Callers 3

jsdocs.test.tsFile · 0.90
bin.tsFile · 0.90
extractJSDocsFunction · 0.85

Calls 12

normalizeFileFunction · 0.85
hashSourceFunction · 0.85
diagnosticFunction · 0.85
parseSourceFileDocsFunction · 0.85
resolveJSDocImportsFunction · 0.85
computeJSDocInputHashFunction · 0.85
pushMethod · 0.80
getProgramFunction · 0.70
mapMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…