fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/use-query-options 46 lines 1.4 kB view raw
1import type { AnalysisContext, NodeName, Ref } from '@hey-api/codegen-core'; 2import { ref } from '@hey-api/codegen-core'; 3 4import { py } from '../../py-compiler'; 5import { PyDsl } from '../base'; 6import { LayoutMixin } from '../mixins/layout'; 7import { f } from '../utils/factories'; 8 9export type SubscriptExpr = NodeName | PyDsl<py.Expression>; 10export type SubscriptCtor = ( 11 value: SubscriptExpr, 12 ...slices: Array<SubscriptExpr> 13) => SubscriptPyDsl; 14 15const Mixed = LayoutMixin(PyDsl<py.SubscriptExpression>); 16 17export class SubscriptPyDsl extends Mixed { 18 readonly '~dsl' = 'SubscriptPyDsl'; 19 20 protected _slices: Array<Ref<SubscriptExpr>>; 21 protected _value: Ref<SubscriptExpr>; 22 23 constructor(value: SubscriptExpr, ...slices: Array<SubscriptExpr>) { 24 super(); 25 this._slices = slices.map((slice) => ref(slice)); 26 this._value = ref(value); 27 } 28 29 override analyze(ctx: AnalysisContext): void { 30 super.analyze(ctx); 31 ctx.analyze(this._value); 32 for (const slice of this._slices) { 33 ctx.analyze(slice); 34 } 35 } 36 37 override toAst() { 38 const slice = 39 this._slices.length === 1 40 ? this.$node(this._slices[0]!) 41 : py.factory.createSubscriptSlice(this._slices.map((s) => this.$node(s))); 42 return py.factory.createSubscriptExpression(this.$node(this._value), slice); 43 } 44} 45 46f.slice.set((...args) => new SubscriptPyDsl(...args));