cordis-walk.ts 664 B

123456789101112131415
  1. /** Locate the Cordis module merge used by the vendored core API projector. */
  2. import ts from 'typescript'
  3. /** The body of the cordis module merge in `sf`: `declare module 'cordis'`
  4. * (harness packages) or `declare module './context.ts'` (vendor core), or
  5. * null when the file has neither. */
  6. export function cordisModuleBody(sf: ts.SourceFile): ts.ModuleBlock | null {
  7. for (const stmt of sf.statements) {
  8. if (!ts.isModuleDeclaration(stmt) || !ts.isStringLiteral(stmt.name)) continue
  9. if (stmt.name.text !== 'cordis' && stmt.name.text !== './context.ts') continue
  10. if (stmt.body && ts.isModuleBlock(stmt.body)) return stmt.body
  11. }
  12. return null
  13. }