fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 32 lines 752 B view raw
1import type { AnalysisContext } from '@hey-api/codegen-core'; 2 3import type { py } from '../../ts-python'; 4import { PyDsl } from '../base'; 5import type { PyDslContext } from './context'; 6import { ctx } from './context'; 7 8export type LazyThunk<T extends py.Node> = (ctx: PyDslContext) => PyDsl<T>; 9 10export class LazyPyDsl<T extends py.Node = py.Node> extends PyDsl<T> { 11 readonly '~dsl' = 'LazyPyDsl'; 12 13 private _thunk: LazyThunk<T>; 14 15 constructor(thunk: LazyThunk<T>) { 16 super(); 17 this._thunk = thunk; 18 } 19 20 override analyze(ctx: AnalysisContext): void { 21 super.analyze(ctx); 22 ctx.analyze(this.toResult()); 23 } 24 25 toResult(): PyDsl<T> { 26 return this._thunk(ctx); 27 } 28 29 override toAst(): T { 30 return this.toResult().toAst(); 31 } 32}