jsxpression 0.1.0
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/LICENSE +21 -0
- package/README.md +368 -0
- package/lib/analyze/analysis-error.d.ts.map +1 -0
- package/lib/analyze/analysis-report.d.ts +33 -0
- package/lib/analyze/analysis-report.d.ts.map +1 -0
- package/lib/analyze/analysis-report.js +194 -0
- package/lib/analyze/analysis-report.js.map +1 -0
- package/lib/analyze/analyze.d.ts.map +1 -0
- package/lib/analyze/analyze.test.d.ts.map +1 -0
- package/lib/analyze/analyze.test.js +765 -0
- package/lib/analyze/analyze.test.js.map +1 -0
- package/lib/analyze/data/analyze.d.ts.map +1 -0
- package/lib/analyze/data/data-access.d.ts.map +1 -0
- package/lib/analyze/data/index.d.ts.map +1 -0
- package/lib/analyze/data/method-calls.d.ts.map +1 -0
- package/lib/analyze/data/utils.d.ts.map +1 -0
- package/lib/analyze/index.d.ts.map +1 -0
- package/lib/analyze/jsx/analyze.d.ts.map +1 -0
- package/lib/analyze/jsx/element-attributes.d.ts.map +1 -0
- package/lib/analyze/jsx/element-attributes.js +89 -0
- package/lib/analyze/jsx/element-attributes.js.map +1 -0
- package/lib/analyze/jsx/element-children.d.ts.map +1 -0
- package/lib/analyze/jsx/element-tags.d.ts.map +1 -0
- package/lib/analyze/jsx/index.d.ts.map +1 -0
- package/lib/analyze/security/analyze.d.ts.map +1 -0
- package/lib/analyze/security/call-expressions.d.ts.map +1 -0
- package/lib/analyze/security/declarations.d.ts.map +1 -0
- package/lib/analyze/security/expressions.d.ts.map +1 -0
- package/lib/analyze/security/identifiers.d.ts.map +1 -0
- package/lib/analyze/security/index.d.ts.map +1 -0
- package/lib/analyze/security/member-access.d.ts.map +1 -0
- package/lib/builtins.d.ts +50 -0
- package/lib/builtins.d.ts.map +1 -0
- package/lib/builtins.js +1065 -0
- package/lib/builtins.js.map +1 -0
- package/lib/codegen/builtin-types.d.ts +11 -0
- package/lib/codegen/builtin-types.d.ts.map +1 -0
- package/lib/codegen/builtin-types.js +151 -0
- package/lib/codegen/builtin-types.js.map +1 -0
- package/lib/codegen/builtins/builtin-types.d.ts +2 -0
- package/lib/codegen/builtins/builtin-types.d.ts.map +1 -0
- package/lib/codegen/builtins/builtin-types.js +143 -0
- package/lib/codegen/builtins/builtin-types.js.map +1 -0
- package/lib/codegen/builtins/index.d.ts +2 -0
- package/lib/codegen/builtins/index.d.ts.map +1 -0
- package/lib/codegen/builtins/index.js +6 -0
- package/lib/codegen/builtins/index.js.map +1 -0
- package/lib/codegen/declare-types.d.ts +20 -0
- package/lib/codegen/declare-types.d.ts.map +1 -0
- package/lib/codegen/declare-types.js +299 -0
- package/lib/codegen/declare-types.js.map +1 -0
- package/lib/codegen/generate-typescript-definitions.d.ts +31 -0
- package/lib/codegen/generate-typescript-definitions.d.ts.map +1 -0
- package/lib/codegen/generate-typescript-definitions.js +37 -0
- package/lib/codegen/generate-typescript-definitions.js.map +1 -0
- package/lib/codegen/generate-typescript-definitions.test.d.ts +2 -0
- package/lib/codegen/generate-typescript-definitions.test.d.ts.map +1 -0
- package/lib/codegen/generate-typescript-definitions.test.js +587 -0
- package/lib/codegen/generate-typescript-definitions.test.js.map +1 -0
- package/lib/codegen/index.d.ts +2 -0
- package/lib/codegen/index.d.ts.map +1 -0
- package/lib/codegen/index.js +6 -0
- package/lib/codegen/index.js.map +1 -0
- package/lib/codegen/schema/component-types.d.ts +3 -0
- package/lib/codegen/schema/component-types.d.ts.map +1 -0
- package/lib/codegen/schema/component-types.js +118 -0
- package/lib/codegen/schema/component-types.js.map +1 -0
- package/lib/codegen/schema/data-types.d.ts +3 -0
- package/lib/codegen/schema/data-types.d.ts.map +1 -0
- package/lib/codegen/schema/data-types.js +98 -0
- package/lib/codegen/schema/data-types.js.map +1 -0
- package/lib/codegen/schema/index.d.ts +3 -0
- package/lib/codegen/schema/index.d.ts.map +1 -0
- package/lib/codegen/schema/index.js +8 -0
- package/lib/codegen/schema/index.js.map +1 -0
- package/lib/codegen/schema/utils.d.ts +4 -0
- package/lib/codegen/schema/utils.d.ts.map +1 -0
- package/lib/codegen/schema/utils.js +103 -0
- package/lib/codegen/schema/utils.js.map +1 -0
- package/lib/codegen/schema-to-types.d.ts +14 -0
- package/lib/codegen/schema-to-types.d.ts.map +1 -0
- package/lib/codegen/schema-to-types.js +203 -0
- package/lib/codegen/schema-to-types.js.map +1 -0
- package/lib/compile/compile.d.ts.map +1 -0
- package/lib/compile/compile.js +245 -0
- package/lib/compile/compile.js.map +1 -0
- package/lib/compile/compile.test.d.ts.map +1 -0
- package/lib/compile/compile.test.js +148 -0
- package/lib/compile/compile.test.js.map +1 -0
- package/lib/evaluate/evaluate.d.ts +26 -0
- package/lib/evaluate/evaluate.d.ts.map +1 -0
- package/lib/evaluate/evaluate.js +40 -0
- package/lib/evaluate/evaluation-error.d.ts +4 -0
- package/lib/evaluate/evaluation-error.d.ts.map +1 -0
- package/lib/evaluate/evaluation-error.js +6 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/render.d.ts +58 -0
- package/lib/render.d.ts.map +1 -0
- package/lib/render.js +52 -0
- package/lib/render.test.d.ts.map +1 -0
- package/lib/schema.d.ts +68 -0
- package/lib/schema.d.ts.map +1 -0
- package/lib/schema.js +106 -0
- package/lib/validate.d.ts +41 -0
- package/lib/validate.d.ts.map +1 -0
- package/lib/validate.js +42 -0
- package/package.json +27 -0
- package/src/analyze/analysis-error.ts +26 -0
- package/src/analyze/analysis-report.ts +228 -0
- package/src/analyze/analyze.test.ts +829 -0
- package/src/analyze/analyze.ts +10 -0
- package/src/analyze/data/analyze.ts +15 -0
- package/src/analyze/data/data-access.ts +349 -0
- package/src/analyze/data/index.ts +1 -0
- package/src/analyze/data/method-calls.ts +96 -0
- package/src/analyze/data/utils.ts +329 -0
- package/src/analyze/index.ts +3 -0
- package/src/analyze/jsx/analyze.ts +17 -0
- package/src/analyze/jsx/element-attributes.ts +143 -0
- package/src/analyze/jsx/element-children.ts +97 -0
- package/src/analyze/jsx/element-tags.ts +55 -0
- package/src/analyze/jsx/index.ts +1 -0
- package/src/analyze/security/analyze.ts +21 -0
- package/src/analyze/security/call-expressions.ts +41 -0
- package/src/analyze/security/declarations.ts +67 -0
- package/src/analyze/security/expressions.ts +100 -0
- package/src/analyze/security/identifiers.ts +113 -0
- package/src/analyze/security/index.ts +1 -0
- package/src/analyze/security/member-access.ts +35 -0
- package/src/analyze/utils.ts +118 -0
- package/src/analyze/validation-context.ts +32 -0
- package/src/builtins.ts +1149 -0
- package/src/codegen/builtins/builtin-types.ts +174 -0
- package/src/codegen/builtins/index.ts +1 -0
- package/src/codegen/generate-typescript-definitions.test.ts +676 -0
- package/src/codegen/generate-typescript-definitions.ts +35 -0
- package/src/codegen/index.ts +1 -0
- package/src/codegen/schema/component-types.ts +140 -0
- package/src/codegen/schema/data-types.ts +109 -0
- package/src/codegen/schema/index.ts +2 -0
- package/src/codegen/schema/utils.ts +111 -0
- package/src/compile/compilation-error.ts +37 -0
- package/src/compile/compile.test.ts +180 -0
- package/src/compile/compile.ts +282 -0
- package/src/compile/index.ts +2 -0
- package/src/evaluate/evaluate.test.ts +316 -0
- package/src/evaluate/evaluate.ts +81 -0
- package/src/evaluate/evaluation-error.ts +6 -0
- package/src/evaluate/index.ts +2 -0
- package/src/index.ts +10 -0
- package/src/jsx.ts +161 -0
- package/src/parse/index.ts +2 -0
- package/src/parse/parse-error.ts +14 -0
- package/src/parse/parse.test.ts +99 -0
- package/src/parse/parse.ts +40 -0
- package/src/render.test.ts +425 -0
- package/src/render.ts +75 -0
- package/src/schema.ts +195 -0
- package/src/traverse.test.ts +104 -0
- package/src/traverse.ts +78 -0
- package/src/types.ts +17 -0
- package/src/validate.ts +59 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate TypeScript .d.ts declarations from JSXExpression schema
|
|
3
|
+
* Main public API: declareTypes(schema, options)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Main public API: Generate complete TypeScript declarations for JSXExpression
|
|
7
|
+
* This is the primary function that should be exported from jsxpression
|
|
8
|
+
*/
|
|
9
|
+
export function declareTypes(schema, options = {}) {
|
|
10
|
+
const { includeBuiltins = true, namespace, componentPrefix = "", allowedStringMethods = ["trim", "toUpperCase", "toLowerCase", "split", "replace", "includes"], allowedArrayMethods = ["map", "filter", "join", "length", "slice"], allowedMathMethods = ["round", "floor", "ceil", "max", "min", "abs"], } = options;
|
|
11
|
+
let output = `// Auto-generated TypeScript definitions for JSXExpression\n`;
|
|
12
|
+
output += `// Generated at: ${new Date().toISOString()}\n\n`;
|
|
13
|
+
// Add JSX namespace and types (minimal JSX without React dependency)
|
|
14
|
+
output += `declare global {\n`;
|
|
15
|
+
output += ` namespace JSX {\n`;
|
|
16
|
+
output += ` type Element = {\n`;
|
|
17
|
+
output += ` type: any;\n`;
|
|
18
|
+
output += ` props: any;\n`;
|
|
19
|
+
output += ` key?: string | number | null;\n`;
|
|
20
|
+
output += ` };\n`;
|
|
21
|
+
output += ` type Node = Element | string | number | boolean | null | undefined | Node[];\n`;
|
|
22
|
+
output += ` interface IntrinsicElements {\n`;
|
|
23
|
+
output += ` [elemName: string]: any;\n`;
|
|
24
|
+
output += ` }\n`;
|
|
25
|
+
// Add component interfaces INSIDE declare global (this was key in working version!)
|
|
26
|
+
if (schema.elements) {
|
|
27
|
+
Object.entries(schema.elements).forEach(([elementName, element]) => {
|
|
28
|
+
const interfaceName = `${componentPrefix}${elementName}Props`;
|
|
29
|
+
output += generatePropsInterface(interfaceName, element, " ");
|
|
30
|
+
output += "\n";
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Add global component declarations for direct usage INSIDE declare global
|
|
34
|
+
if (schema.elements) {
|
|
35
|
+
Object.entries(schema.elements).forEach(([elementName, element]) => {
|
|
36
|
+
const interfaceName = `${componentPrefix}${elementName}Props`;
|
|
37
|
+
// Generate JSDoc comment for the component
|
|
38
|
+
const componentComment = generateComponentComment(elementName, element, " ");
|
|
39
|
+
if (componentComment) {
|
|
40
|
+
output += componentComment;
|
|
41
|
+
}
|
|
42
|
+
output += ` const ${elementName}: (props: ${interfaceName}) => JSX.Element;\n\n`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Add builtin types if requested
|
|
46
|
+
if (includeBuiltins) {
|
|
47
|
+
// Math object
|
|
48
|
+
output += ` const Math: {\n`;
|
|
49
|
+
const allMathMethods = {
|
|
50
|
+
abs: "(x: number): number",
|
|
51
|
+
ceil: "(x: number): number",
|
|
52
|
+
floor: "(x: number): number",
|
|
53
|
+
round: "(x: number): number",
|
|
54
|
+
max: "(...values: number[]): number",
|
|
55
|
+
min: "(...values: number[]): number",
|
|
56
|
+
random: "(): number",
|
|
57
|
+
pow: "(x: number, y: number): number",
|
|
58
|
+
sqrt: "(x: number): number",
|
|
59
|
+
sin: "(x: number): number",
|
|
60
|
+
cos: "(x: number): number",
|
|
61
|
+
tan: "(x: number): number",
|
|
62
|
+
PI: "number",
|
|
63
|
+
E: "number",
|
|
64
|
+
};
|
|
65
|
+
Object.entries(allMathMethods).forEach(([method, signature]) => {
|
|
66
|
+
if (allowedMathMethods.includes(method)) {
|
|
67
|
+
output += ` ${method}: ${signature};\n`;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
output += ` };\n\n`;
|
|
71
|
+
// Utility functions
|
|
72
|
+
output += ` // Utility functions\n`;
|
|
73
|
+
output += ` function formatCurrency(value: number, currency?: string): string;\n`;
|
|
74
|
+
output += ` function formatDate(date: Date | string | number, format?: string): string;\n`;
|
|
75
|
+
output += ` function formatNumber(value: number, decimals?: number): string;\n`;
|
|
76
|
+
output += ` function sum(values: number[]): number;\n`;
|
|
77
|
+
output += ` function average(values: number[]): number;\n`;
|
|
78
|
+
output += ` function count(values: any[]): number;\n`;
|
|
79
|
+
output += ` function conditional(condition: boolean, trueValue: any, falseValue?: any): any;\n`;
|
|
80
|
+
output += ` function coalesce(...values: any[]): any;\n`;
|
|
81
|
+
output += ` function format(template: string, ...args: any[]): string;\n\n`;
|
|
82
|
+
}
|
|
83
|
+
// Add data object declaration if schema has data
|
|
84
|
+
if (schema.data) {
|
|
85
|
+
output += `\n // Data object for JSX expressions\n`;
|
|
86
|
+
output += ` const data: {\n`;
|
|
87
|
+
Object.entries(schema.data).forEach(([dataKey, dataSchema]) => {
|
|
88
|
+
const type = mapSchemaTypeToTypeScript(dataSchema);
|
|
89
|
+
const comment = generatePropComment(dataSchema, " ");
|
|
90
|
+
if (comment) {
|
|
91
|
+
output += comment;
|
|
92
|
+
}
|
|
93
|
+
// Handle multi-line types (nested objects) with proper indentation
|
|
94
|
+
const indentedType = type.includes("\n") ? type.replace(/\n/g, "\n ").replace(/\n {6}$/, "\n ") : type;
|
|
95
|
+
output += ` ${dataKey}: ${indentedType};\n`;
|
|
96
|
+
});
|
|
97
|
+
output += ` };\n`;
|
|
98
|
+
}
|
|
99
|
+
// Add prototype interfaces if builtins are included
|
|
100
|
+
if (includeBuiltins) {
|
|
101
|
+
// String interface with selective methods
|
|
102
|
+
output += ` interface String {\n`;
|
|
103
|
+
const allStringMethods = {
|
|
104
|
+
charAt: "(index: number): string",
|
|
105
|
+
charCodeAt: "(index: number): number",
|
|
106
|
+
concat: "(...strings: string[]): string",
|
|
107
|
+
endsWith: "(searchString: string, length?: number): boolean",
|
|
108
|
+
includes: "(searchString: string, position?: number): boolean",
|
|
109
|
+
indexOf: "(searchString: string, position?: number): number",
|
|
110
|
+
lastIndexOf: "(searchString: string, position?: number): number",
|
|
111
|
+
slice: "(start?: number, end?: number): string",
|
|
112
|
+
split: "(separator?: string | RegExp, limit?: number): string[]",
|
|
113
|
+
startsWith: "(searchString: string, position?: number): boolean",
|
|
114
|
+
substring: "(start: number, end?: number): string",
|
|
115
|
+
toLowerCase: "(): string",
|
|
116
|
+
toUpperCase: "(): string",
|
|
117
|
+
trim: "(): string",
|
|
118
|
+
trimStart: "(): string",
|
|
119
|
+
trimEnd: "(): string",
|
|
120
|
+
replace: "(searchValue: string | RegExp, replaceValue: string): string",
|
|
121
|
+
replaceAll: "(searchValue: string | RegExp, replaceValue: string): string",
|
|
122
|
+
padStart: "(targetLength: number, padString?: string): string",
|
|
123
|
+
padEnd: "(targetLength: number, padString?: string): string",
|
|
124
|
+
repeat: "(count: number): string",
|
|
125
|
+
length: "number",
|
|
126
|
+
};
|
|
127
|
+
Object.entries(allStringMethods).forEach(([method, signature]) => {
|
|
128
|
+
if (allowedStringMethods.includes(method)) {
|
|
129
|
+
output += ` ${method}: ${signature};\n`;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
output += ` }\n\n`;
|
|
133
|
+
// Array interface with selective methods
|
|
134
|
+
output += ` interface Array<T> {\n`;
|
|
135
|
+
const allArrayMethods = {
|
|
136
|
+
length: "number",
|
|
137
|
+
push: "(...items: T[]): number",
|
|
138
|
+
pop: "(): T | undefined",
|
|
139
|
+
shift: "(): T | undefined",
|
|
140
|
+
unshift: "(...items: T[]): number",
|
|
141
|
+
slice: "(start?: number, end?: number): T[]",
|
|
142
|
+
splice: "(start: number, deleteCount?: number, ...items: T[]): T[]",
|
|
143
|
+
concat: "(...items: (T | T[])[]): T[]",
|
|
144
|
+
join: "(separator?: string): string",
|
|
145
|
+
reverse: "(): T[]",
|
|
146
|
+
sort: "(compareFn?: (a: T, b: T) => number): T[]",
|
|
147
|
+
indexOf: "(searchElement: T, fromIndex?: number): number",
|
|
148
|
+
lastIndexOf: "(searchElement: T, fromIndex?: number): number",
|
|
149
|
+
includes: "(searchElement: T, fromIndex?: number): boolean",
|
|
150
|
+
find: "(predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined",
|
|
151
|
+
findIndex: "(predicate: (value: T, index: number, obj: T[]) => boolean): number",
|
|
152
|
+
filter: "(predicate: (value: T, index: number, array: T[]) => boolean): T[]",
|
|
153
|
+
map: "<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[]",
|
|
154
|
+
forEach: "(callbackfn: (value: T, index: number, array: T[]) => void): void",
|
|
155
|
+
reduce: "<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U",
|
|
156
|
+
some: "(predicate: (value: T, index: number, array: T[]) => boolean): boolean",
|
|
157
|
+
every: "(predicate: (value: T, index: number, array: T[]) => boolean): boolean",
|
|
158
|
+
};
|
|
159
|
+
Object.entries(allArrayMethods).forEach(([method, signature]) => {
|
|
160
|
+
if (allowedArrayMethods.includes(method)) {
|
|
161
|
+
output += ` ${method}: ${signature};\n`;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
output += ` }\n\n`;
|
|
165
|
+
}
|
|
166
|
+
output += `}\n\n`;
|
|
167
|
+
return output;
|
|
168
|
+
}
|
|
169
|
+
// Helper functions
|
|
170
|
+
function generatePropsInterface(interfaceName, element, indent = "") {
|
|
171
|
+
let output = `${indent}interface ${interfaceName} {\n`;
|
|
172
|
+
// Generate props
|
|
173
|
+
Object.entries(element.props || {}).forEach(([propName, prop]) => {
|
|
174
|
+
const optional = prop.required ? "" : "?";
|
|
175
|
+
const type = mapSchemaTypeToTypeScript(prop);
|
|
176
|
+
const comment = generatePropComment(prop, `${indent} `);
|
|
177
|
+
if (comment) {
|
|
178
|
+
output += comment;
|
|
179
|
+
}
|
|
180
|
+
output += `${indent} ${propName}${optional}: ${type};\n`;
|
|
181
|
+
});
|
|
182
|
+
// Add children prop if element can have content
|
|
183
|
+
if (element.content !== false) {
|
|
184
|
+
output += `${indent} children?: JSX.Node;\n`;
|
|
185
|
+
}
|
|
186
|
+
output += `${indent}}\n`;
|
|
187
|
+
return output;
|
|
188
|
+
}
|
|
189
|
+
function generateComponentComment(elementName, element, indent = "") {
|
|
190
|
+
const comments = [];
|
|
191
|
+
// Add component description if available
|
|
192
|
+
if (element.description) {
|
|
193
|
+
comments.push(element.description);
|
|
194
|
+
}
|
|
195
|
+
else if (element.doc) {
|
|
196
|
+
comments.push(element.doc);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Generate a default description
|
|
200
|
+
comments.push(`${elementName} component`);
|
|
201
|
+
}
|
|
202
|
+
// Add prop information summary
|
|
203
|
+
if (element.props && Object.keys(element.props).length > 0) {
|
|
204
|
+
comments.push("");
|
|
205
|
+
const propCount = Object.keys(element.props).length;
|
|
206
|
+
const requiredProps = Object.entries(element.props).filter(([, prop]) => prop.required !== false).length;
|
|
207
|
+
comments.push(`@props ${propCount} props (${requiredProps} required)`);
|
|
208
|
+
}
|
|
209
|
+
// Add examples if available
|
|
210
|
+
if (element.examples && element.examples.length > 0) {
|
|
211
|
+
comments.push("");
|
|
212
|
+
comments.push("@example");
|
|
213
|
+
element.examples.forEach((example) => {
|
|
214
|
+
comments.push(example);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (comments.length === 0) {
|
|
218
|
+
return "";
|
|
219
|
+
}
|
|
220
|
+
if (comments.length === 1 && comments[0] && !comments[0].includes("\n")) {
|
|
221
|
+
return `${indent}/** ${comments[0]} */\n`;
|
|
222
|
+
}
|
|
223
|
+
let output = `${indent}/**\n`;
|
|
224
|
+
comments.forEach((comment) => {
|
|
225
|
+
if (comment === "") {
|
|
226
|
+
output += `${indent} *\n`;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
comment.split("\n").forEach((line) => {
|
|
230
|
+
output += `${indent} * ${line}\n`;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
output += `${indent} */\n`;
|
|
235
|
+
return output;
|
|
236
|
+
}
|
|
237
|
+
function mapSchemaTypeToTypeScript(prop) {
|
|
238
|
+
switch (prop.type) {
|
|
239
|
+
case "string":
|
|
240
|
+
if (prop.enum && Array.isArray(prop.enum)) {
|
|
241
|
+
return prop.enum.map((value) => `"${value}"`).join(" | ");
|
|
242
|
+
}
|
|
243
|
+
return "string";
|
|
244
|
+
case "number":
|
|
245
|
+
if (prop.enum && Array.isArray(prop.enum)) {
|
|
246
|
+
return prop.enum.map((value) => String(value)).join(" | ");
|
|
247
|
+
}
|
|
248
|
+
return "number";
|
|
249
|
+
case "boolean":
|
|
250
|
+
if (prop.enum && Array.isArray(prop.enum)) {
|
|
251
|
+
return prop.enum.map((value) => String(value)).join(" | ");
|
|
252
|
+
}
|
|
253
|
+
return "boolean";
|
|
254
|
+
case "array":
|
|
255
|
+
const itemType = prop.shape ? mapSchemaTypeToTypeScript(prop.shape) : "any";
|
|
256
|
+
return `${itemType}[]`;
|
|
257
|
+
case "object":
|
|
258
|
+
if (prop.shape && typeof prop.shape === "object") {
|
|
259
|
+
let objectType = "{\n";
|
|
260
|
+
Object.entries(prop.shape).forEach(([key, value]) => {
|
|
261
|
+
const nestedType = mapSchemaTypeToTypeScript(value);
|
|
262
|
+
const required = value.required !== false ? "" : "?";
|
|
263
|
+
objectType += ` ${key}${required}: ${nestedType};\n`;
|
|
264
|
+
});
|
|
265
|
+
objectType += " }";
|
|
266
|
+
return objectType;
|
|
267
|
+
}
|
|
268
|
+
return "object";
|
|
269
|
+
case "function":
|
|
270
|
+
return "(...args: any[]) => any";
|
|
271
|
+
default:
|
|
272
|
+
console.warn(`Unknown schema type: ${prop.type}`);
|
|
273
|
+
return "any";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function generatePropComment(prop, indent) {
|
|
277
|
+
const comments = [];
|
|
278
|
+
if (prop.description) {
|
|
279
|
+
comments.push(prop.description);
|
|
280
|
+
}
|
|
281
|
+
if (prop.default !== undefined) {
|
|
282
|
+
comments.push(`@default ${JSON.stringify(prop.default)}`);
|
|
283
|
+
}
|
|
284
|
+
if (prop.type === "enum" && prop.values) {
|
|
285
|
+
comments.push(`@values ${prop.values.map((v) => `"${v}"`).join(", ")}`);
|
|
286
|
+
}
|
|
287
|
+
if (comments.length === 0) {
|
|
288
|
+
return "";
|
|
289
|
+
}
|
|
290
|
+
if (comments.length === 1) {
|
|
291
|
+
return `${indent}/** ${comments[0]} */\n`;
|
|
292
|
+
}
|
|
293
|
+
let output = `${indent}/**\n`;
|
|
294
|
+
comments.forEach((comment) => {
|
|
295
|
+
output += `${indent} * ${comment}\n`;
|
|
296
|
+
});
|
|
297
|
+
output += `${indent} */\n`;
|
|
298
|
+
return output;
|
|
299
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declare-types.js","sourceRoot":"","sources":["../../src/codegen/declare-types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAoBH,oCAqLC;AAzLD;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAc,EAAE,UAA+B,EAAE;IAC5E,MAAM,EACJ,eAAe,GAAG,IAAI,EACtB,SAAS,EACT,eAAe,GAAG,EAAE,EACpB,oBAAoB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,EAC7F,mBAAmB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,EAClE,kBAAkB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GACrE,GAAG,OAAO,CAAC;IAEZ,IAAI,MAAM,GAAG,8DAA8D,CAAC;IAC5E,MAAM,IAAI,oBAAoB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7D,qEAAqE;IACrE,MAAM,IAAI,oBAAoB,CAAC;IAC/B,MAAM,IAAI,qBAAqB,CAAC;IAChC,MAAM,IAAI,wBAAwB,CAAC;IACnC,MAAM,IAAI,oBAAoB,CAAC;IAC/B,MAAM,IAAI,qBAAqB,CAAC;IAChC,MAAM,IAAI,uCAAuC,CAAC;IAClD,MAAM,IAAI,UAAU,CAAC;IACrB,MAAM,IAAI,oFAAoF,CAAC;IAC/F,MAAM,IAAI,qCAAqC,CAAC;IAChD,MAAM,IAAI,kCA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|
1
|
+
import { Schema } from "../schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates TypeScript definitions from a JSXExpression schema.
|
|
4
|
+
*
|
|
5
|
+
* The generated definitions enable code editors to provide:
|
|
6
|
+
* - IntelliSense autocomplete for components and data properties
|
|
7
|
+
* - Type checking for JSX expressions
|
|
8
|
+
* - Hover documentation from schema descriptions
|
|
9
|
+
*
|
|
10
|
+
* @param schema - Schema defining allowed data properties, JSX elements, and their types
|
|
11
|
+
* @returns Complete TypeScript definition file as a string
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const schema = {
|
|
16
|
+
* elements: {
|
|
17
|
+
* Button: {
|
|
18
|
+
* props: { size: { type: "string", enum: ["sm", "md", "lg"] } }
|
|
19
|
+
* }
|
|
20
|
+
* },
|
|
21
|
+
* data: {
|
|
22
|
+
* user: { type: "object", shape: { name: { type: "string" } } }
|
|
23
|
+
* }
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* const definitions = generateTypeScriptDefinitions(schema);
|
|
27
|
+
* // Use with Monaco, VS Code, or any TypeScript-enabled editor
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateTypeScriptDefinitions(schema: Schema): string;
|
|
31
|
+
//# sourceMappingURL=generate-typescript-definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-typescript-definitions.d.ts","sourceRoot":"","sources":["../../src/codegen/generate-typescript-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTypeScriptDefinitions = generateTypeScriptDefinitions;
|
|
4
|
+
const index_js_1 = require("./builtins/index.js");
|
|
5
|
+
const index_js_2 = require("./schema/index.js");
|
|
6
|
+
/**
|
|
7
|
+
* Generates TypeScript definitions from a JSXExpression schema.
|
|
8
|
+
*
|
|
9
|
+
* The generated definitions enable code editors to provide:
|
|
10
|
+
* - IntelliSense autocomplete for components and data properties
|
|
11
|
+
* - Type checking for JSX expressions
|
|
12
|
+
* - Hover documentation from schema descriptions
|
|
13
|
+
*
|
|
14
|
+
* @param schema - Schema defining allowed data properties, JSX elements, and their types
|
|
15
|
+
* @returns Complete TypeScript definition file as a string
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const schema = {
|
|
20
|
+
* elements: {
|
|
21
|
+
* Button: {
|
|
22
|
+
* props: { size: { type: "string", enum: ["sm", "md", "lg"] } }
|
|
23
|
+
* }
|
|
24
|
+
* },
|
|
25
|
+
* data: {
|
|
26
|
+
* user: { type: "object", shape: { name: { type: "string" } } }
|
|
27
|
+
* }
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* const definitions = generateTypeScriptDefinitions(schema);
|
|
31
|
+
* // Use with Monaco, VS Code, or any TypeScript-enabled editor
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function generateTypeScriptDefinitions(schema) {
|
|
35
|
+
return [(0, index_js_1.declareBuiltinTypes)(), (0, index_js_2.declareComponentTypes)(schema), (0, index_js_2.declareDataTypes)(schema)].join("\n");
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=generate-typescript-definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-typescript-definitions.js","sourceRoot":"","sources":["../../src/codegen/generate-typescript-definitions.ts"],"names":[],"mappings":";;AAgCA,sEAEC;AAjCD,kDAA0D;AAC1D,gDAA4E;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,6BAA6B,CAAC,MAAc;IAC1D,OAAO,CAAC,IAAA,8BAAmB,GAAE,EAAE,IAAA,gCAAqB,EAAC,MAAM,CAAC,EAAE,IAAA,2BAAgB,EAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-typescript-definitions.test.d.ts","sourceRoot":"","sources":["../../src/codegen/generate-typescript-definitions.test.ts"],"names":[],"mappings":""}
|