-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
168 lines (148 loc) · 5.39 KB
/
Copy pathtypes.d.ts
File metadata and controls
168 lines (148 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Type definitions for @juspay/rescript-bindgen
// A deterministic TypeScript -> ReScript binding generator.
/** A node in the intermediate representation of a prop/field type. */
export type IRType =
| { kind: 'string' }
| { kind: 'number'; _float?: boolean }
| { kind: 'boolean' }
| { kind: 'reactElement' }
| { kind: 'style' }
| { kind: 'date' }
| { kind: 'domElement' }
| { kind: 'domRef' }
| { kind: 'unit' }
| { kind: 'typeRef'; to: string; _enum?: boolean; _unboxed?: boolean }
| { kind: 'array'; of: IRType }
| { kind: 'dict'; of: IRType }
| { kind: 'callback'; arg: IRType | { kind: 'event'; res: string }; ret: IRType }
/** Complex but real type, widened to a fallback (default `string`). */
| { kind: 'opaque'; text: string }
/** Multi-type union we refuse to bind unsafely — flagged for human review. */
| { kind: 'review'; text: string }
/** unknown / any — upstream type defect, never silently typed. */
| { kind: 'unknown' }
| { kind: 'any' }
export interface EnumDecl {
name: string
members: { as: string; ctor: string }[]
}
export interface RecordDecl {
name: string
fields: { name: string; optional: boolean; type: IRType }[]
}
/** An `@unboxed` untagged-variant declaration (type-safe multi-type props). */
export interface UnboxedDecl {
name: string
members: { ctor: string; type: IRType }[]
}
export interface PropIR {
name: string
optional: boolean
inherited: boolean
type: IRType
/** Resolved TS type string (for reports). */
tsType?: string
/** Original `.d.ts` declaration text (for reports). */
declText?: string
}
export interface ComponentIR {
module: string
import: { from: string; name: string }
kind: 'react-component'
enums: EnumDecl[]
records: RecordDecl[]
unboxed: UnboxedDecl[]
props: PropIR[]
}
/** IR for a standalone function / const-with-call-signature export (generic TS). */
export interface FunctionIR {
module: string
import: { from: string; name: string }
kind: 'function'
enums: EnumDecl[]
records: RecordDecl[]
unboxed: UnboxedDecl[]
/** The classified call signature: params (name + optionality + type) + return type.
* Required params bind positionally; optional ones bind as labeled `~name=?`. */
sig: { params: ParamIR[]; ret: IRType }
}
/** A labeled-argument member (class constructor / method param): name + optionality + type. */
export interface ParamIR {
name: string
optional: boolean
type: IRType
}
/** IR for an exported class (generic TS) — bound as a module with an abstract `type t`. */
export interface ClassIR {
module: string
import: { from: string; name: string }
kind: 'class'
enums: EnumDecl[]
records: RecordDecl[]
unboxed: UnboxedDecl[]
/** This class's abstract type name in the `InstanceTypes` sink — `type t` aliases it. */
sinkName: string
/** First construct signature's params (`@new ... make`), or null if no usable constructor. */
ctor: { params: ParamIR[] } | null
/** Instance methods (`@send`): each a JS name + labeled params + return type. */
methods: { jsName: string; params: ParamIR[]; ret: IRType }[]
/** Data properties / getters (`@get`): each a JS name + its type. */
getters: { jsName: string; type: IRType }[]
}
export interface ExtractOptions {
/** `@module(...)` import name stamped into the binding. */
from?: string
/** Override the component/import name. */
importName?: string
/** Inherited HTML/ARIA props to keep (default: a common allowlist). */
htmlAllowlist?: string[]
}
export interface EmitOptions {
/** ReScript type emitted for DOM refs. */
refType?: string
/** Fallback type for opaque/review props (default `'string'`). */
opaqueFallback?: string
}
export interface ReportItem {
prop: string
kind: 'opaque' | 'review' | 'unknown' | 'any'
tsType?: string
declText?: string
emittedAs?: string
}
export interface Report {
/** Real types widened to a fallback — compile & work, just loosely typed. */
loose: ReportItem[]
/** unknown/any — won't work as typed; fix upstream. */
defects: ReportItem[]
/** Multi-type props that need a hand-written binding. */
review: ReportItem[]
}
/** Extract a single component from a per-component `.d.ts`. */
export function extractComponent(entryFile: string, opts?: ExtractOptions): ComponentIR
/** Extract every exported React component + standalone function from a module's entry `.d.ts`. */
export function extractModule(
entryFile: string,
opts?: ExtractOptions
): {
components: { name: string; ir: ComponentIR }[]
functions: { name: string; ir: FunctionIR }[]
classes: { name: string; ir: ClassIR }[]
skipped: { name: string; reason: string }[]
}
/** Render a ComponentIR to ReScript source. */
export function emit(ir: ComponentIR, options?: EmitOptions): string
/** Render a FunctionIR to a ReScript `@module external` binding. */
export function emitFunction(ir: FunctionIR, options?: EmitOptions): string
/** Render a ClassIR to a ReScript module (abstract `type t` + `@new`/`@send`/`@get`). */
export function emitClass(ir: ClassIR, options?: EmitOptions): string
/** Summarise which props are loose / defective / need review. */
export function report(ir: ComponentIR): Report
/** Resolve a CLI input (file / dir / pkg) to a declaration entry file. */
export function resolveInput(opts: {
file?: string
dir?: string
pkg?: string
install?: boolean
nodeModulesRoots?: string[]
}): { entry: string; from?: string; untyped?: boolean }