| 467 | |
| 468 | // TypeScript 6's namespace, as far as the declarations read one |
| 469 | const typeScriptOf = (native: Native): TypeScript => { |
| 470 | const { sync, ast } = native |
| 471 | const leadingComments = (node: Node) => { |
| 472 | const file = node.getSourceFile() |
| 473 | const text = file.text |
| 474 | return (ast.getLeadingCommentRanges(text, node.pos) ?? []).map(range => ({ |
| 475 | text: text.slice(range.pos + 2, range.end - 2) |
| 476 | })) |
| 477 | } |
| 478 | return { |
| 479 | ...ast, |
| 480 | TypeFlags: sync.TypeFlags, |
| 481 | ObjectFlags: sync.ObjectFlags, |
| 482 | SymbolFlags: sync.SymbolFlags, |
| 483 | ElementFlags: sync.ElementFlags, |
| 484 | ModifierFlags: sync.ModifierFlags, |
| 485 | TypeFormatFlags: sync.TypeFormatFlags, |
| 486 | DiagnosticCategory: sync.DiagnosticCategory, |
| 487 | isParameter: ast.isParameterDeclaration, |
| 488 | isPropertySignature: ast.isPropertySignatureDeclaration, |
| 489 | isMethodSignature: ast.isMethodSignatureDeclaration, |
| 490 | forEachChild: <t>(node: Node, visit: (child: Node) => t | undefined) => |
| 491 | node.forEachChild(visit), |
| 492 | findAncestor: ( |
| 493 | node: Node | undefined, |
| 494 | isMatch: (node: Node) => boolean |
| 495 | ) => { |
| 496 | for (; node; node = node.parent) if (isMatch(node)) return node |
| 497 | }, |
| 498 | getNameOfDeclaration: (node: { name?: Node }) => node.name, |
| 499 | getCheckFlags: (s: ts.Symbol) => (s as unknown as SymbolView).checkFlags, |
| 500 | // a declaration's text is all there is to tell elision from |
| 501 | getSyntheticLeadingComments: leadingComments, |
| 502 | getOriginalNode: (node: Node) => node |
| 503 | } as never |
| 504 | } |
| 505 | |
| 506 | const programOf = ( |
| 507 | project: tsgo.Project, |