fork of hey-api/openapi-ts because I need some additional things
1import type { AnalysisContext, Node } from '@hey-api/codegen-core';
2
3import type { py } from '../../ts-python';
4import type { HintFn, HintLines } from '../layout/hint';
5import { HintPyDsl } from '../layout/hint';
6import type { BaseCtor, MixinCtor } from './types';
7
8export interface HintMethods extends Node {
9 $hint<T extends py.Node>(node: T): T;
10 hint(lines?: HintLines, fn?: HintFn): this;
11}
12
13export function HintMixin<T extends py.Node, TBase extends BaseCtor<T>>(Base: TBase) {
14 abstract class Hint extends Base {
15 private _hint?: HintPyDsl;
16
17 override analyze(ctx: AnalysisContext): void {
18 super.analyze(ctx);
19 }
20
21 protected hint(lines?: HintLines, fn?: HintFn): this {
22 this._hint = new HintPyDsl(lines, fn);
23 return this;
24 }
25
26 protected $hint<T extends py.Node>(node: T): T {
27 return this._hint ? this._hint.apply(node) : node;
28 }
29 }
30
31 return Hint as unknown as MixinCtor<TBase, HintMethods>;
32}