( code: string, policy: ExampleImportPolicy )
| 2415 | ): { readonly files: ReadonlyArray<JSDocModelFile>; readonly added: boolean } { |
| 2416 | const diagnosticsByFile = new Map(files.map((file) => [file.file, [...file.diagnostics]])) |
| 2417 | const resolve = createJSDocApiSeeLinkResolver(apis) |
| 2418 | let added = false |
| 2419 | for (const file of files) { |
| 2420 | if (file.imports === undefined || file.moduleJSDoc === undefined) continue |
| 2421 | const sourceFile = context.sourceFilesByFile.get(file.file) |
| 2422 | const diagnostics = diagnosticsByFile.get(file.file) |
| 2423 | if (sourceFile === undefined || diagnostics === undefined) continue |
| 2424 | for (const tag of moduleSeeTags(file, sourceFile, context)) { |
| 2425 | for (const link of tag.links) { |
| 2426 | const item = unresolvedPublicSeeDiagnostic({ |
| 2427 | ...link, |
| 2428 | resolution: resolve({ moduleName: file.imports.module, namespacePath: [] }, link) |
| 2429 | }) |
| 2430 | if (item === undefined || diagnostics.some((diagnostic) => sameDiagnostic(diagnostic, item))) continue |
| 2431 | diagnostics.push(item) |
| 2432 | added = true |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | if (!added) return { files, added } |
| 2437 | return { |
| 2438 | added, |
| 2439 | files: files.map((file) => ({ |
| 2440 | ...file, |
| 2441 | diagnostics: diagnosticsByFile.get(file.file) ?? file.diagnostics |
| 2442 | })) |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | function buildJSDocApisWithPublicSeeDiagnostics( |
| 2447 | files: ReadonlyArray<JSDocModelFile>, |
| 2448 | context?: { |
| 2449 | readonly sourceFilesByFile: ReadonlyMap<string, ts.SourceFile> |
| 2450 | readonly checker: ts.TypeChecker |
| 2451 | readonly entry: ProgramCacheEntry |
| 2452 | readonly cwd: string |
| 2453 | } |
| 2454 | ): { |
| 2455 | readonly files: ReadonlyArray<JSDocModelFile> |
| 2456 | readonly apis: ReadonlyArray<JSDocApi> |
| 2457 | } { |
| 2458 | let current = files |
| 2459 | for (let index = 0; index < 5; index++) { |
| 2460 | const apis = buildJSDocApis(current) |
| 2461 | const publicSee = appendPublicSeeDiagnostics(current, apis) |
| 2462 | const moduleSee = context === undefined |
| 2463 | ? { files: publicSee.files, added: false } |
| 2464 | : appendModulePublicSeeDiagnostics(publicSee.files, apis, context) |
| 2465 | const next = { files: moduleSee.files, added: publicSee.added || moduleSee.added } |
| 2466 | if (!next.added) return { files: current, apis } |
| 2467 | current = next.files |
| 2468 | } |
| 2469 | return { files: current, apis: buildJSDocApis(current) } |
| 2470 | } |
| 2471 | |
| 2472 | interface ExampleImportPolicy { |
| 2473 | readonly allowedNamedBySource: ReadonlyMap<string, ReadonlySet<string>> |
| 2474 | readonly namespaceModuleBySource: ReadonlyMap<string, { readonly barrelModule: string; readonly name: string }> |
no test coverage detected
searching dependent graphs…