jsxpression 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analyze/analysis-error.d.ts.map +1 -1
- package/lib/analyze/analysis-error.js +2 -3
- package/lib/analyze/analysis-error.js.map +1 -1
- package/lib/codegen/schema/utils.d.ts.map +1 -1
- package/lib/codegen/schema/utils.js +3 -0
- package/lib/codegen/schema/utils.js.map +1 -1
- package/lib/schema.d.ts +7 -1
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js.map +1 -1
- package/package.json +2 -2
- package/src/analyze/analysis-error.ts +2 -3
- package/src/codegen/generate-typescript-definitions.test.ts +16 -0
- package/src/codegen/schema/utils.ts +3 -0
- package/src/schema.ts +8 -0
- package/lib/analyze/analyze.test.d.ts +0 -2
- package/lib/analyze/analyze.test.d.ts.map +0 -1
- package/lib/analyze/analyze.test.js +0 -763
- package/lib/analyze/analyze.test.js.map +0 -1
- package/lib/analyze/security/member-access.d.ts +0 -6
- package/lib/analyze/security/member-access.d.ts.map +0 -1
- package/lib/analyze/security/member-access.js +0 -21
- package/lib/analyze/security/member-access.js.map +0 -1
- package/lib/codegen/generate-typescript-definitions.test.d.ts +0 -2
- package/lib/codegen/generate-typescript-definitions.test.d.ts.map +0 -1
- package/lib/codegen/generate-typescript-definitions.test.js +0 -649
- package/lib/codegen/generate-typescript-definitions.test.js.map +0 -1
- package/lib/compile/compile.test.d.ts +0 -2
- package/lib/compile/compile.test.d.ts.map +0 -1
- package/lib/compile/compile.test.js +0 -146
- package/lib/compile/compile.test.js.map +0 -1
- package/lib/evaluate/evaluate.test.d.ts +0 -2
- package/lib/evaluate/evaluate.test.d.ts.map +0 -1
- package/lib/evaluate/evaluate.test.js +0 -260
- package/lib/evaluate/evaluate.test.js.map +0 -1
- package/lib/parse/parse.test.d.ts +0 -2
- package/lib/parse/parse.test.d.ts.map +0 -1
- package/lib/parse/parse.test.js +0 -80
- package/lib/parse/parse.test.js.map +0 -1
- package/lib/render.test.d.ts +0 -2
- package/lib/render.test.d.ts.map +0 -1
- package/lib/render.test.js +0 -301
- package/lib/render.test.js.map +0 -1
- package/lib/traverse.test.d.ts +0 -2
- package/lib/traverse.test.d.ts.map +0 -1
- package/lib/traverse.test.js +0 -84
- package/lib/traverse.test.js.map +0 -1
- package/lib/types.d.ts +0 -12
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
|
@@ -1,649 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { generateTypeScriptDefinitions } from "./generate-typescript-definitions.js";
|
|
3
|
-
describe("generateTypeScriptDefinitions", () => {
|
|
4
|
-
describe("basic structure", () => {
|
|
5
|
-
it("should generate valid TypeScript definitions for empty schema", () => {
|
|
6
|
-
const schema = {
|
|
7
|
-
data: {},
|
|
8
|
-
elements: {},
|
|
9
|
-
};
|
|
10
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
11
|
-
expect(result).toContain("declare global");
|
|
12
|
-
expect(result).toContain("namespace JSX");
|
|
13
|
-
expect(result).toContain("export {};");
|
|
14
|
-
});
|
|
15
|
-
it("should include builtin types declarations", () => {
|
|
16
|
-
const schema = {
|
|
17
|
-
data: {},
|
|
18
|
-
elements: {},
|
|
19
|
-
};
|
|
20
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
21
|
-
expect(result).toContain("namespace JSX");
|
|
22
|
-
expect(result).toContain("type Element");
|
|
23
|
-
expect(result).toContain("type Node");
|
|
24
|
-
expect(result).toContain("interface IntrinsicElements");
|
|
25
|
-
expect(result).toContain("Math");
|
|
26
|
-
expect(result).toContain("String");
|
|
27
|
-
expect(result).toContain("Array");
|
|
28
|
-
});
|
|
29
|
-
it("should generate variadic parameters with array types", () => {
|
|
30
|
-
const schema = {
|
|
31
|
-
data: {},
|
|
32
|
-
elements: {},
|
|
33
|
-
};
|
|
34
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
35
|
-
expect(result).toContain("max(...values: number[]): number");
|
|
36
|
-
expect(result).toContain("min(...values: number[]): number");
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("element types generation", () => {
|
|
40
|
-
it("should generate element with string prop", () => {
|
|
41
|
-
const schema = {
|
|
42
|
-
data: {},
|
|
43
|
-
elements: {
|
|
44
|
-
Button: {
|
|
45
|
-
props: {
|
|
46
|
-
label: { type: "string", required: true },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
52
|
-
expect(result).toContain("interface ButtonProps");
|
|
53
|
-
expect(result).toContain("label: string");
|
|
54
|
-
expect(result).toContain("const Button: (props: ButtonProps) => JSX.Element");
|
|
55
|
-
});
|
|
56
|
-
it("should generate element with multiple prop types", () => {
|
|
57
|
-
const schema = {
|
|
58
|
-
data: {},
|
|
59
|
-
elements: {
|
|
60
|
-
Input: {
|
|
61
|
-
props: {
|
|
62
|
-
name: { type: "string", required: true },
|
|
63
|
-
value: { type: "string" },
|
|
64
|
-
maxLength: { type: "number" },
|
|
65
|
-
disabled: { type: "boolean" },
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
71
|
-
expect(result).toContain("interface InputProps");
|
|
72
|
-
expect(result).toContain("name: string");
|
|
73
|
-
expect(result).toContain("value?: string");
|
|
74
|
-
expect(result).toContain("maxLength?: number");
|
|
75
|
-
expect(result).toContain("disabled?: boolean");
|
|
76
|
-
});
|
|
77
|
-
it("should generate element with enum prop", () => {
|
|
78
|
-
const schema = {
|
|
79
|
-
data: {},
|
|
80
|
-
elements: {
|
|
81
|
-
Button: {
|
|
82
|
-
props: {
|
|
83
|
-
size: { type: "string", enum: ["sm", "md", "lg"] },
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
89
|
-
expect(result).toContain("interface ButtonProps");
|
|
90
|
-
expect(result).toContain('size?: "sm" | "md" | "lg"');
|
|
91
|
-
});
|
|
92
|
-
it("should generate element with object prop", () => {
|
|
93
|
-
const schema = {
|
|
94
|
-
data: {},
|
|
95
|
-
elements: {
|
|
96
|
-
Card: {
|
|
97
|
-
props: {
|
|
98
|
-
style: {
|
|
99
|
-
type: "object",
|
|
100
|
-
shape: {
|
|
101
|
-
color: { type: "string" },
|
|
102
|
-
backgroundColor: { type: "string" },
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
110
|
-
expect(result).toContain("interface CardProps");
|
|
111
|
-
expect(result).toContain("style?:");
|
|
112
|
-
expect(result).toContain("color: string");
|
|
113
|
-
expect(result).toContain("backgroundColor: string");
|
|
114
|
-
});
|
|
115
|
-
it("should generate element with array prop", () => {
|
|
116
|
-
const schema = {
|
|
117
|
-
data: {},
|
|
118
|
-
elements: {
|
|
119
|
-
List: {
|
|
120
|
-
props: {
|
|
121
|
-
items: {
|
|
122
|
-
type: "array",
|
|
123
|
-
shape: { type: "string" },
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
130
|
-
expect(result).toContain("interface ListProps");
|
|
131
|
-
expect(result).toContain("items?: string[]");
|
|
132
|
-
});
|
|
133
|
-
it("should generate element with function prop", () => {
|
|
134
|
-
const schema = {
|
|
135
|
-
data: {},
|
|
136
|
-
elements: {
|
|
137
|
-
Button: {
|
|
138
|
-
props: {
|
|
139
|
-
onClick: { type: "function" },
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
145
|
-
expect(result).toContain("interface ButtonProps");
|
|
146
|
-
expect(result).toContain("onClick?: (...args: any[]) => any");
|
|
147
|
-
});
|
|
148
|
-
it("should include children prop by default", () => {
|
|
149
|
-
const schema = {
|
|
150
|
-
data: {},
|
|
151
|
-
elements: {
|
|
152
|
-
Container: {
|
|
153
|
-
props: {},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
158
|
-
expect(result).toContain("interface ContainerProps");
|
|
159
|
-
expect(result).toContain("children?: JSX.Node");
|
|
160
|
-
});
|
|
161
|
-
it("should exclude children prop when content is false", () => {
|
|
162
|
-
const schema = {
|
|
163
|
-
data: {},
|
|
164
|
-
elements: {
|
|
165
|
-
Input: {
|
|
166
|
-
props: {},
|
|
167
|
-
content: false,
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
172
|
-
expect(result).toContain("interface InputProps");
|
|
173
|
-
expect(result).not.toContain("children");
|
|
174
|
-
});
|
|
175
|
-
it("should include element description as JSDoc", () => {
|
|
176
|
-
const schema = {
|
|
177
|
-
data: {},
|
|
178
|
-
elements: {
|
|
179
|
-
Button: {
|
|
180
|
-
description: "A clickable button element",
|
|
181
|
-
props: {
|
|
182
|
-
label: { type: "string", description: "The button text" },
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
188
|
-
expect(result).toContain("A clickable button element");
|
|
189
|
-
expect(result).toContain("The button text");
|
|
190
|
-
});
|
|
191
|
-
it("should generate multiple components", () => {
|
|
192
|
-
const schema = {
|
|
193
|
-
data: {},
|
|
194
|
-
elements: {
|
|
195
|
-
Button: {
|
|
196
|
-
props: { label: { type: "string" } },
|
|
197
|
-
},
|
|
198
|
-
Input: {
|
|
199
|
-
props: { value: { type: "string" } },
|
|
200
|
-
},
|
|
201
|
-
Container: {
|
|
202
|
-
props: {},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
207
|
-
expect(result).toContain("interface ButtonProps");
|
|
208
|
-
expect(result).toContain("interface InputProps");
|
|
209
|
-
expect(result).toContain("interface ContainerProps");
|
|
210
|
-
expect(result).toContain("const Button: (props: ButtonProps) => JSX.Element");
|
|
211
|
-
expect(result).toContain("const Input: (props: InputProps) => JSX.Element");
|
|
212
|
-
expect(result).toContain("const Container: (props: ContainerProps) => JSX.Element");
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
describe("data types generation", () => {
|
|
216
|
-
it("should generate data with string property", () => {
|
|
217
|
-
const schema = {
|
|
218
|
-
data: {
|
|
219
|
-
userName: { type: "string" },
|
|
220
|
-
},
|
|
221
|
-
elements: {},
|
|
222
|
-
};
|
|
223
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
224
|
-
expect(result).toContain("const data:");
|
|
225
|
-
expect(result).toContain("userName: string");
|
|
226
|
-
});
|
|
227
|
-
it("should generate data with multiple property types", () => {
|
|
228
|
-
const schema = {
|
|
229
|
-
data: {
|
|
230
|
-
name: { type: "string" },
|
|
231
|
-
age: { type: "number" },
|
|
232
|
-
active: { type: "boolean" },
|
|
233
|
-
},
|
|
234
|
-
elements: {},
|
|
235
|
-
};
|
|
236
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
237
|
-
expect(result).toContain("const data:");
|
|
238
|
-
expect(result).toContain("name: string");
|
|
239
|
-
expect(result).toContain("age: number");
|
|
240
|
-
expect(result).toContain("active: boolean");
|
|
241
|
-
});
|
|
242
|
-
it("should generate data with object property", () => {
|
|
243
|
-
const schema = {
|
|
244
|
-
data: {
|
|
245
|
-
user: {
|
|
246
|
-
type: "object",
|
|
247
|
-
shape: {
|
|
248
|
-
name: { type: "string" },
|
|
249
|
-
email: { type: "string" },
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
elements: {},
|
|
254
|
-
};
|
|
255
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
256
|
-
expect(result).toContain("const data:");
|
|
257
|
-
expect(result).toContain("user:");
|
|
258
|
-
expect(result).toContain("name: string");
|
|
259
|
-
expect(result).toContain("email: string");
|
|
260
|
-
});
|
|
261
|
-
it("should generate data with nested object properties", () => {
|
|
262
|
-
const schema = {
|
|
263
|
-
data: {
|
|
264
|
-
user: {
|
|
265
|
-
type: "object",
|
|
266
|
-
shape: {
|
|
267
|
-
name: { type: "string" },
|
|
268
|
-
profile: {
|
|
269
|
-
type: "object",
|
|
270
|
-
shape: {
|
|
271
|
-
avatar: { type: "string" },
|
|
272
|
-
bio: { type: "string" },
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
elements: {},
|
|
279
|
-
};
|
|
280
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
281
|
-
expect(result).toContain("const data:");
|
|
282
|
-
expect(result).toContain("user:");
|
|
283
|
-
expect(result).toContain("profile:");
|
|
284
|
-
expect(result).toContain("avatar: string");
|
|
285
|
-
expect(result).toContain("bio: string");
|
|
286
|
-
});
|
|
287
|
-
it("should generate data with array of primitives", () => {
|
|
288
|
-
const schema = {
|
|
289
|
-
data: {
|
|
290
|
-
tags: {
|
|
291
|
-
type: "array",
|
|
292
|
-
shape: { type: "string" },
|
|
293
|
-
},
|
|
294
|
-
scores: {
|
|
295
|
-
type: "array",
|
|
296
|
-
shape: { type: "number" },
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
elements: {},
|
|
300
|
-
};
|
|
301
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
302
|
-
expect(result).toContain("const data:");
|
|
303
|
-
expect(result).toContain("tags: string[]");
|
|
304
|
-
expect(result).toContain("scores: number[]");
|
|
305
|
-
});
|
|
306
|
-
it("should generate data with array of objects", () => {
|
|
307
|
-
const schema = {
|
|
308
|
-
data: {
|
|
309
|
-
users: {
|
|
310
|
-
type: "array",
|
|
311
|
-
shape: {
|
|
312
|
-
type: "object",
|
|
313
|
-
shape: {
|
|
314
|
-
name: { type: "string" },
|
|
315
|
-
age: { type: "number" },
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
elements: {},
|
|
321
|
-
};
|
|
322
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
323
|
-
expect(result).toContain("const data:");
|
|
324
|
-
expect(result).toContain("users:");
|
|
325
|
-
expect(result).toContain("name: string");
|
|
326
|
-
expect(result).toContain("age: number");
|
|
327
|
-
expect(result).toContain("[]");
|
|
328
|
-
});
|
|
329
|
-
it("should include data property descriptions as JSDoc", () => {
|
|
330
|
-
const schema = {
|
|
331
|
-
data: {
|
|
332
|
-
userName: { type: "string", description: "The current user's name" },
|
|
333
|
-
settings: {
|
|
334
|
-
type: "object",
|
|
335
|
-
description: "User preferences",
|
|
336
|
-
shape: {
|
|
337
|
-
theme: { type: "string", description: "UI theme preference" },
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
elements: {},
|
|
342
|
-
};
|
|
343
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
344
|
-
expect(result).toContain("The current user's name");
|
|
345
|
-
expect(result).toContain("User preferences");
|
|
346
|
-
expect(result).toContain("UI theme preference");
|
|
347
|
-
});
|
|
348
|
-
it("should generate data with enum values", () => {
|
|
349
|
-
const schema = {
|
|
350
|
-
data: {
|
|
351
|
-
status: { type: "string", enum: ["pending", "active", "completed"] },
|
|
352
|
-
priority: { type: "number", enum: [1, 2, 3] },
|
|
353
|
-
},
|
|
354
|
-
elements: {},
|
|
355
|
-
};
|
|
356
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
357
|
-
expect(result).toContain("const data:");
|
|
358
|
-
expect(result).toContain('status: "pending" | "active" | "completed"');
|
|
359
|
-
expect(result).toContain("priority: 1 | 2 | 3");
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
describe("combined schema", () => {
|
|
363
|
-
it("should generate definitions for both components and data", () => {
|
|
364
|
-
const schema = {
|
|
365
|
-
data: {
|
|
366
|
-
userName: { type: "string" },
|
|
367
|
-
count: { type: "number" },
|
|
368
|
-
},
|
|
369
|
-
elements: {
|
|
370
|
-
Display: {
|
|
371
|
-
props: {
|
|
372
|
-
text: { type: "string" },
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
Counter: {
|
|
376
|
-
props: {
|
|
377
|
-
value: { type: "number" },
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
383
|
-
expect(result).toContain("const data:");
|
|
384
|
-
expect(result).toContain("userName: string");
|
|
385
|
-
expect(result).toContain("count: number");
|
|
386
|
-
expect(result).toContain("interface DisplayProps");
|
|
387
|
-
expect(result).toContain("interface CounterProps");
|
|
388
|
-
expect(result).toContain("const Display: (props: DisplayProps) => JSX.Element");
|
|
389
|
-
expect(result).toContain("const Counter: (props: CounterProps) => JSX.Element");
|
|
390
|
-
expect(result).toContain("namespace JSX");
|
|
391
|
-
});
|
|
392
|
-
it("should generate union types", () => {
|
|
393
|
-
const schema = {
|
|
394
|
-
data: {
|
|
395
|
-
union: {
|
|
396
|
-
type: "union",
|
|
397
|
-
shape: [
|
|
398
|
-
{
|
|
399
|
-
type: "object",
|
|
400
|
-
shape: {
|
|
401
|
-
id: {
|
|
402
|
-
type: "string",
|
|
403
|
-
enum: ["TypeA"],
|
|
404
|
-
},
|
|
405
|
-
valueA: {
|
|
406
|
-
type: "string"
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
type: "object",
|
|
412
|
-
shape: {
|
|
413
|
-
id: {
|
|
414
|
-
type: "string",
|
|
415
|
-
enum: ["TypeB"],
|
|
416
|
-
},
|
|
417
|
-
valueB: {
|
|
418
|
-
type: "number"
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
]
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
427
|
-
expect(result).toContain(`id: "TypeA";\n valueA: string;\n } | {\n id: "TypeB";\n valueB: number;\n };`);
|
|
428
|
-
});
|
|
429
|
-
it("should generate functions", () => {
|
|
430
|
-
const schema = {
|
|
431
|
-
functions: {
|
|
432
|
-
test: {
|
|
433
|
-
ret: {
|
|
434
|
-
type: "string",
|
|
435
|
-
},
|
|
436
|
-
args: [
|
|
437
|
-
{
|
|
438
|
-
name: "arg1",
|
|
439
|
-
property: {
|
|
440
|
-
type: "number",
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
name: "arg2",
|
|
445
|
-
property: {
|
|
446
|
-
type: "string"
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
]
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
454
|
-
expect(result).toContain(`function test(arg1: number, arg2: string): string;`);
|
|
455
|
-
});
|
|
456
|
-
it("should generate valid TypeScript that can be parsed", () => {
|
|
457
|
-
const schema = {
|
|
458
|
-
data: {
|
|
459
|
-
user: {
|
|
460
|
-
type: "object",
|
|
461
|
-
shape: {
|
|
462
|
-
name: { type: "string" },
|
|
463
|
-
email: { type: "string" },
|
|
464
|
-
settings: {
|
|
465
|
-
type: "object",
|
|
466
|
-
shape: {
|
|
467
|
-
theme: { type: "string", enum: ["light", "dark"] },
|
|
468
|
-
notifications: { type: "boolean" },
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
items: {
|
|
474
|
-
type: "array",
|
|
475
|
-
shape: {
|
|
476
|
-
type: "object",
|
|
477
|
-
shape: {
|
|
478
|
-
id: { type: "number" },
|
|
479
|
-
title: { type: "string" },
|
|
480
|
-
tags: {
|
|
481
|
-
type: "array",
|
|
482
|
-
shape: { type: "string" },
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
},
|
|
487
|
-
},
|
|
488
|
-
elements: {
|
|
489
|
-
Card: {
|
|
490
|
-
description: "A card element for displaying content",
|
|
491
|
-
props: {
|
|
492
|
-
title: { type: "string", required: true, description: "Card title" },
|
|
493
|
-
subtitle: { type: "string", description: "Optional subtitle" },
|
|
494
|
-
variant: { type: "string", enum: ["default", "outlined", "filled"] },
|
|
495
|
-
onClick: { type: "function" },
|
|
496
|
-
},
|
|
497
|
-
},
|
|
498
|
-
List: {
|
|
499
|
-
props: {
|
|
500
|
-
items: {
|
|
501
|
-
type: "array",
|
|
502
|
-
shape: { type: "string" },
|
|
503
|
-
},
|
|
504
|
-
},
|
|
505
|
-
content: false,
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
};
|
|
509
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
510
|
-
expect(result).toContain("declare global");
|
|
511
|
-
expect(result).toContain("export {};");
|
|
512
|
-
expect(result).toContain("const data:");
|
|
513
|
-
expect(result).toContain("user:");
|
|
514
|
-
expect(result).toContain("name: string");
|
|
515
|
-
expect(result).toContain("email: string");
|
|
516
|
-
expect(result).toContain("settings:");
|
|
517
|
-
expect(result).toContain('theme: "light" | "dark"');
|
|
518
|
-
expect(result).toContain("notifications: boolean");
|
|
519
|
-
expect(result).toContain("items:");
|
|
520
|
-
expect(result).toContain("id: number");
|
|
521
|
-
expect(result).toContain("tags: string[]");
|
|
522
|
-
expect(result).toContain("interface CardProps");
|
|
523
|
-
expect(result).toContain("title: string");
|
|
524
|
-
expect(result).toContain("subtitle?: string");
|
|
525
|
-
expect(result).toContain('variant?: "default" | "outlined" | "filled"');
|
|
526
|
-
expect(result).toContain("onClick?: (...args: any[]) => any");
|
|
527
|
-
expect(result).toContain("children?: JSX.Node");
|
|
528
|
-
expect(result).toContain("A card element for displaying content");
|
|
529
|
-
expect(result).toContain("interface ListProps");
|
|
530
|
-
expect(result).toContain("items?: string[]");
|
|
531
|
-
expect(result).not.toMatch(/interface ListProps\s*{[^}]*children/);
|
|
532
|
-
expect(result).toContain("namespace JSX");
|
|
533
|
-
expect(result).toContain("Math");
|
|
534
|
-
expect(result).toContain("const Card: (props: CardProps) => JSX.Element");
|
|
535
|
-
expect(result).toContain("const List: (props: ListProps) => JSX.Element");
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
describe("edge cases", () => {
|
|
539
|
-
it("should handle empty props object", () => {
|
|
540
|
-
const schema = {
|
|
541
|
-
data: {},
|
|
542
|
-
elements: {
|
|
543
|
-
Divider: {
|
|
544
|
-
props: {},
|
|
545
|
-
},
|
|
546
|
-
},
|
|
547
|
-
};
|
|
548
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
549
|
-
expect(result).toContain("interface DividerProps");
|
|
550
|
-
expect(result).toContain("children?: JSX.Node");
|
|
551
|
-
expect(result).toContain("const Divider: (props: DividerProps) => JSX.Element");
|
|
552
|
-
});
|
|
553
|
-
it("should handle element with only required props", () => {
|
|
554
|
-
const schema = {
|
|
555
|
-
data: {},
|
|
556
|
-
elements: {
|
|
557
|
-
Label: {
|
|
558
|
-
props: {
|
|
559
|
-
text: { type: "string", required: true },
|
|
560
|
-
id: { type: "string", required: true },
|
|
561
|
-
},
|
|
562
|
-
},
|
|
563
|
-
},
|
|
564
|
-
};
|
|
565
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
566
|
-
expect(result).toContain("interface LabelProps");
|
|
567
|
-
expect(result).toContain("text: string");
|
|
568
|
-
expect(result).toContain("id: string");
|
|
569
|
-
expect(result).not.toMatch(/text\?:/);
|
|
570
|
-
expect(result).not.toMatch(/id\?:/);
|
|
571
|
-
});
|
|
572
|
-
it("should handle deeply nested object structures", () => {
|
|
573
|
-
const schema = {
|
|
574
|
-
data: {
|
|
575
|
-
config: {
|
|
576
|
-
type: "object",
|
|
577
|
-
shape: {
|
|
578
|
-
level1: {
|
|
579
|
-
type: "object",
|
|
580
|
-
shape: {
|
|
581
|
-
level2: {
|
|
582
|
-
type: "object",
|
|
583
|
-
shape: {
|
|
584
|
-
level3: {
|
|
585
|
-
type: "object",
|
|
586
|
-
shape: {
|
|
587
|
-
value: { type: "string" },
|
|
588
|
-
},
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
},
|
|
595
|
-
},
|
|
596
|
-
},
|
|
597
|
-
elements: {},
|
|
598
|
-
};
|
|
599
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
600
|
-
expect(result).toContain("config:");
|
|
601
|
-
expect(result).toContain("level1:");
|
|
602
|
-
expect(result).toContain("level2:");
|
|
603
|
-
expect(result).toContain("level3:");
|
|
604
|
-
expect(result).toContain("value: string");
|
|
605
|
-
});
|
|
606
|
-
it("should handle array of arrays", () => {
|
|
607
|
-
const schema = {
|
|
608
|
-
data: {
|
|
609
|
-
matrix: {
|
|
610
|
-
type: "array",
|
|
611
|
-
shape: {
|
|
612
|
-
type: "array",
|
|
613
|
-
shape: { type: "number" },
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
|
-
},
|
|
617
|
-
elements: {},
|
|
618
|
-
};
|
|
619
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
620
|
-
expect(result).toContain("matrix: number[][]");
|
|
621
|
-
});
|
|
622
|
-
it("should handle mixed required and optional props", () => {
|
|
623
|
-
const schema = {
|
|
624
|
-
data: {},
|
|
625
|
-
elements: {
|
|
626
|
-
Form: {
|
|
627
|
-
props: {
|
|
628
|
-
id: { type: "string", required: true },
|
|
629
|
-
name: { type: "string", required: true },
|
|
630
|
-
title: { type: "string" },
|
|
631
|
-
description: { type: "string" },
|
|
632
|
-
onSubmit: { type: "function", required: true },
|
|
633
|
-
onCancel: { type: "function" },
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
},
|
|
637
|
-
};
|
|
638
|
-
const result = generateTypeScriptDefinitions(schema);
|
|
639
|
-
expect(result).toContain("interface FormProps");
|
|
640
|
-
expect(result).toContain("id: string");
|
|
641
|
-
expect(result).toContain("name: string");
|
|
642
|
-
expect(result).toContain("title?: string");
|
|
643
|
-
expect(result).toContain("description?: string");
|
|
644
|
-
expect(result).toContain("onSubmit: (...args: any[]) => any");
|
|
645
|
-
expect(result).toContain("onCancel?: (...args: any[]) => any");
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
//# sourceMappingURL=generate-typescript-definitions.test.js.map
|