(block: JSDocBlock)
| 1379 | } |
| 1380 | |
| 1381 | function parseModuleExamples(block: JSDocBlock): { |
| 1382 | readonly examples: ReadonlyArray<ParsedExample> |
| 1383 | readonly diagnostics: ReadonlyArray<JSDocDiagnostic> |
| 1384 | } { |
| 1385 | const diagnostics: Array<JSDocDiagnostic> = [] |
| 1386 | const examples: Array<ParsedExample> = [] |
| 1387 | const exampleTitles = new Set<string>() |
| 1388 | const firstTagLine = block.tags[0]?.line ?? block.lines.length |
| 1389 | const lines = block.lines.slice(0, firstTagLine) |
| 1390 | let index = 0 |
| 1391 | while (index < lines.length) { |
| 1392 | const trimmed = lines[index].trim() |
| 1393 | if (trimmed.startsWith("**Example**")) { |
| 1394 | const parsed = parseExample(lines, index) |
| 1395 | diagnostics.push(...parsed.diagnostics) |
| 1396 | if (parsed.example !== undefined) { |
| 1397 | const key = parsed.example.title.trim().toLowerCase() |
| 1398 | if (exampleTitles.has(key)) { |
| 1399 | diagnostics.push(diagnostic("duplicate-example", `Duplicate example title: ${parsed.example.title.trim()}`)) |
| 1400 | } |
| 1401 | exampleTitles.add(key) |
| 1402 | examples.push(parsed.example) |
| 1403 | } |
| 1404 | index = Math.max(parsed.nextIndex, index + 1) |
| 1405 | continue |
| 1406 | } |
| 1407 | if (trimmed.startsWith("```")) { |
| 1408 | diagnostics.push( |
| 1409 | diagnostic("loose-ts-fence", "Code fences in module JSDoc must use **Example** (Title) sections") |
| 1410 | ) |
| 1411 | index++ |
| 1412 | while (index < lines.length && !lines[index].trim().startsWith("```")) index++ |
| 1413 | if (index < lines.length) index++ |
| 1414 | continue |
| 1415 | } |
| 1416 | index++ |
| 1417 | } |
| 1418 | return { examples, diagnostics } |
| 1419 | } |
| 1420 | |
| 1421 | function joinBody(lines: ReadonlyArray<string>): string { |
| 1422 | let start = 0 |
no test coverage detected