import type { AnalysisContext } from '@hey-api/codegen-core'; import type { py } from '../../ts-python'; import { PyDsl } from '../base'; import type { PyDslContext } from './context'; import { ctx } from './context'; export type LazyThunk = (ctx: PyDslContext) => PyDsl; export class LazyPyDsl extends PyDsl { readonly '~dsl' = 'LazyPyDsl'; private _thunk: LazyThunk; constructor(thunk: LazyThunk) { super(); this._thunk = thunk; } override analyze(ctx: AnalysisContext): void { super.analyze(ctx); ctx.analyze(this.toResult()); } toResult(): PyDsl { return this._thunk(ctx); } override toAst(): T { return this.toResult().toAst(); } }