fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 35 lines 982 B view raw
1import type { AnalysisContext, Node } from '@hey-api/codegen-core'; 2 3import type { py } from '../../ts-python'; 4import type { MaybePyDsl } from '../base'; 5import type { BaseCtor, MixinCtor } from './types'; 6 7export type ValueExpr = string | MaybePyDsl<py.Expression>; 8 9export interface ValueMethods extends Node { 10 $value(): py.Expression | undefined; 11 /** Sets the initializer expression (e.g. `= expr`). */ 12 assign(expr: ValueExpr): this; 13} 14 15export function ValueMixin<T extends py.Node, TBase extends BaseCtor<T>>(Base: TBase) { 16 abstract class Value extends Base { 17 protected value?: ValueExpr; 18 19 override analyze(ctx: AnalysisContext): void { 20 super.analyze(ctx); 21 ctx.analyze(this.value); 22 } 23 24 protected assign(expr: ValueExpr): this { 25 this.value = expr; 26 return this; 27 } 28 29 protected $value(): py.Expression | undefined { 30 return this.$node(this.value); 31 } 32 } 33 34 return Value as unknown as MixinCtor<TBase, ValueMethods>; 35}