@zenithbuild/core 1.2.2 → 1.2.3

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.
Files changed (83) hide show
  1. package/README.md +20 -19
  2. package/cli/commands/add.ts +2 -2
  3. package/cli/commands/build.ts +2 -3
  4. package/cli/commands/dev.ts +93 -73
  5. package/cli/commands/index.ts +1 -1
  6. package/cli/commands/preview.ts +1 -1
  7. package/cli/commands/remove.ts +2 -2
  8. package/cli/index.ts +1 -1
  9. package/cli/main.ts +1 -1
  10. package/cli/utils/logger.ts +1 -1
  11. package/cli/utils/plugin-manager.ts +1 -1
  12. package/cli/utils/project.ts +4 -4
  13. package/core/components/ErrorPage.zen +218 -0
  14. package/core/components/index.ts +15 -0
  15. package/core/config.ts +1 -0
  16. package/core/index.ts +29 -0
  17. package/dist/compiler-native-frej59m4.node +0 -0
  18. package/dist/core/compiler-native-frej59m4.node +0 -0
  19. package/dist/core/index.js +6293 -0
  20. package/dist/runtime/lifecycle/index.js +1 -0
  21. package/dist/runtime/reactivity/index.js +1 -0
  22. package/dist/zen-build.js +1 -20118
  23. package/dist/zen-dev.js +1 -20118
  24. package/dist/zen-preview.js +1 -20118
  25. package/dist/zenith.js +1 -20118
  26. package/package.json +11 -20
  27. package/compiler/README.md +0 -380
  28. package/compiler/build-analyzer.ts +0 -122
  29. package/compiler/css/index.ts +0 -317
  30. package/compiler/discovery/componentDiscovery.ts +0 -242
  31. package/compiler/discovery/layouts.ts +0 -70
  32. package/compiler/errors/compilerError.ts +0 -56
  33. package/compiler/finalize/finalizeOutput.ts +0 -192
  34. package/compiler/finalize/generateFinalBundle.ts +0 -82
  35. package/compiler/index.ts +0 -83
  36. package/compiler/ir/types.ts +0 -174
  37. package/compiler/output/types.ts +0 -48
  38. package/compiler/parse/detectMapExpressions.ts +0 -102
  39. package/compiler/parse/importTypes.ts +0 -78
  40. package/compiler/parse/parseImports.ts +0 -309
  41. package/compiler/parse/parseScript.ts +0 -46
  42. package/compiler/parse/parseTemplate.ts +0 -628
  43. package/compiler/parse/parseZenFile.ts +0 -66
  44. package/compiler/parse/scriptAnalysis.ts +0 -91
  45. package/compiler/parse/trackLoopContext.ts +0 -82
  46. package/compiler/runtime/dataExposure.ts +0 -332
  47. package/compiler/runtime/generateDOM.ts +0 -255
  48. package/compiler/runtime/generateHydrationBundle.ts +0 -407
  49. package/compiler/runtime/hydration.ts +0 -309
  50. package/compiler/runtime/navigation.ts +0 -432
  51. package/compiler/runtime/thinRuntime.ts +0 -160
  52. package/compiler/runtime/transformIR.ts +0 -406
  53. package/compiler/runtime/wrapExpression.ts +0 -114
  54. package/compiler/runtime/wrapExpressionWithLoop.ts +0 -97
  55. package/compiler/spa-build.ts +0 -917
  56. package/compiler/ssg-build.ts +0 -486
  57. package/compiler/test/component-stacking.test.ts +0 -365
  58. package/compiler/test/map-lowering.test.ts +0 -130
  59. package/compiler/test/validate-test.ts +0 -104
  60. package/compiler/transform/classifyExpression.ts +0 -444
  61. package/compiler/transform/componentResolver.ts +0 -350
  62. package/compiler/transform/componentScriptTransformer.ts +0 -303
  63. package/compiler/transform/expressionTransformer.ts +0 -385
  64. package/compiler/transform/fragmentLowering.ts +0 -819
  65. package/compiler/transform/generateBindings.ts +0 -68
  66. package/compiler/transform/generateHTML.ts +0 -28
  67. package/compiler/transform/layoutProcessor.ts +0 -132
  68. package/compiler/transform/slotResolver.ts +0 -292
  69. package/compiler/transform/transformNode.ts +0 -314
  70. package/compiler/transform/transformTemplate.ts +0 -38
  71. package/compiler/validate/invariants.ts +0 -292
  72. package/compiler/validate/validateExpressions.ts +0 -168
  73. package/core/config/index.ts +0 -18
  74. package/core/config/loader.ts +0 -69
  75. package/core/config/types.ts +0 -119
  76. package/core/plugins/bridge.ts +0 -193
  77. package/core/plugins/index.ts +0 -7
  78. package/core/plugins/registry.ts +0 -126
  79. package/dist/cli.js +0 -11675
  80. package/runtime/build.ts +0 -17
  81. package/runtime/bundle-generator.ts +0 -1266
  82. package/runtime/client-runtime.ts +0 -891
  83. package/runtime/serve.ts +0 -93
@@ -1,385 +0,0 @@
1
- /**
2
- * Expression JSX Transformer
3
- *
4
- * Transforms JSX-like tags inside Zenith expressions into __zenith.h() calls.
5
- * This allows Zenith to support JSX semantics without a full JSX compiler like Babel.
6
- *
7
- * Handles:
8
- * - Multi-line JSX expressions
9
- * - Nested elements
10
- * - Complex event handlers like onclick={() => fn(item)}
11
- * - Expression attributes {expr}
12
- * - Text interpolation {item.title}
13
- */
14
-
15
- /**
16
- * Find the end of a balanced brace expression
17
- */
18
- function findBalancedBraceEnd(code: string, startIndex: number): number {
19
- let braceCount = 1
20
- let i = startIndex + 1
21
- let inString = false
22
- let stringChar = ''
23
- let inTemplate = false
24
-
25
- while (i < code.length && braceCount > 0) {
26
- const char = code[i]
27
- const prevChar = i > 0 ? code[i - 1] : ''
28
-
29
- // Handle escape sequences
30
- if (prevChar === '\\') {
31
- i++
32
- continue
33
- }
34
-
35
- // Handle string literals
36
- if (!inString && !inTemplate && (char === '"' || char === "'")) {
37
- inString = true
38
- stringChar = char
39
- i++
40
- continue
41
- }
42
-
43
- if (inString && char === stringChar) {
44
- inString = false
45
- stringChar = ''
46
- i++
47
- continue
48
- }
49
-
50
- // Handle template literals
51
- if (!inString && !inTemplate && char === '`') {
52
- inTemplate = true
53
- i++
54
- continue
55
- }
56
-
57
- if (inTemplate && char === '`') {
58
- inTemplate = false
59
- i++
60
- continue
61
- }
62
-
63
- // Count braces only when not in strings
64
- if (!inString && !inTemplate) {
65
- if (char === '{') braceCount++
66
- else if (char === '}') braceCount--
67
- }
68
-
69
- i++
70
- }
71
-
72
- return braceCount === 0 ? i : -1
73
- }
74
-
75
- /**
76
- * Parse JSX attributes using balanced parsing for expression values
77
- */
78
- function parseJSXAttributes(code: string, startIndex: number): {
79
- attrs: string;
80
- endIndex: number;
81
- isSelfClosing: boolean
82
- } {
83
- const attrPairs: string[] = []
84
- let i = startIndex
85
-
86
- // Skip whitespace
87
- while (i < code.length && /\s/.test(code[i]!)) i++
88
-
89
- while (i < code.length) {
90
- const char = code[i]
91
-
92
- // Check for end of opening tag
93
- if (char === '>') {
94
- return { attrs: formatAttrs(attrPairs), endIndex: i + 1, isSelfClosing: false }
95
- }
96
- if (char === '/' && code[i + 1] === '>') {
97
- return { attrs: formatAttrs(attrPairs), endIndex: i + 2, isSelfClosing: true }
98
- }
99
-
100
- // Parse attribute name
101
- const nameMatch = code.slice(i).match(/^([a-zA-Z_][a-zA-Z0-9_-]*)/)
102
- if (!nameMatch) {
103
- i++
104
- continue
105
- }
106
-
107
- const attrName = nameMatch[1]!
108
- i += attrName.length
109
-
110
- // Skip whitespace
111
- while (i < code.length && /\s/.test(code[i]!)) i++
112
-
113
- // Check for value
114
- if (code[i] !== '=') {
115
- attrPairs.push(`"${attrName}": true`)
116
- continue
117
- }
118
-
119
- i++ // Skip '='
120
-
121
- // Skip whitespace
122
- while (i < code.length && /\s/.test(code[i]!)) i++
123
-
124
- // Parse value
125
- if (code[i] === '"' || code[i] === "'") {
126
- const quote = code[i]
127
- let endQuote = i + 1
128
- while (endQuote < code.length && code[endQuote] !== quote) {
129
- if (code[endQuote] === '\\') endQuote++ // Skip escaped chars
130
- endQuote++
131
- }
132
- const value = code.slice(i + 1, endQuote)
133
- attrPairs.push(`"${attrName}": "${value}"`)
134
- i = endQuote + 1
135
- } else if (code[i] === '{') {
136
- // Expression value - find balanced end
137
- const endBrace = findBalancedBraceEnd(code, i)
138
- if (endBrace === -1) {
139
- i++
140
- continue
141
- }
142
- const expr = code.slice(i + 1, endBrace - 1).trim()
143
- attrPairs.push(`"${attrName}": ${expr}`)
144
- i = endBrace
145
- } else {
146
- // Unquoted value (rare in JSX, but support it)
147
- const unquotedMatch = code.slice(i).match(/^([^\s/>]+)/)
148
- if (unquotedMatch) {
149
- attrPairs.push(`"${attrName}": "${unquotedMatch[1]}"`)
150
- i += unquotedMatch[1]!.length
151
- }
152
- }
153
-
154
- // Skip whitespace
155
- while (i < code.length && /\s/.test(code[i]!)) i++
156
- }
157
-
158
- return { attrs: formatAttrs(attrPairs), endIndex: i, isSelfClosing: false }
159
- }
160
-
161
- function formatAttrs(pairs: string[]): string {
162
- return pairs.length > 0 ? `{ ${pairs.join(', ')} }` : 'null'
163
- }
164
-
165
- /**
166
- * Find the matching closing tag for an element
167
- */
168
- function findClosingTag(code: string, startIndex: number, tagName: string): number {
169
- let depth = 1
170
- let i = startIndex
171
- const openPattern = new RegExp(`<${tagName}(?:\\s|>|/>)`, 'i')
172
- const closeTag = `</${tagName}>`
173
-
174
- while (i < code.length && depth > 0) {
175
- // Check for closing tag
176
- if (code.slice(i, i + closeTag.length).toLowerCase() === closeTag.toLowerCase()) {
177
- depth--
178
- if (depth === 0) return i
179
- i += closeTag.length
180
- continue
181
- }
182
-
183
- // Check for opening tag (same name, nested)
184
- const openMatch = code.slice(i).match(openPattern)
185
- if (openMatch && openMatch.index === 0) {
186
- // Check if it's self-closing
187
- const selfClosing = code.slice(i).match(new RegExp(`<${tagName}[^>]*/>`, 'i'))
188
- if (!selfClosing || selfClosing.index !== 0) {
189
- depth++
190
- }
191
- i += openMatch[0].length
192
- continue
193
- }
194
-
195
- i++
196
- }
197
-
198
- return -1
199
- }
200
-
201
- /**
202
- * Parse JSX children content
203
- */
204
- function parseJSXChildren(code: string, startIndex: number, tagName: string): {
205
- children: string;
206
- endIndex: number
207
- } {
208
- const closingIndex = findClosingTag(code, startIndex, tagName)
209
- if (closingIndex === -1) {
210
- return { children: 'null', endIndex: code.length }
211
- }
212
-
213
- const content = code.slice(startIndex, closingIndex)
214
-
215
- if (!content.trim()) {
216
- return { children: 'null', endIndex: closingIndex }
217
- }
218
-
219
- // Transform the children content
220
- const transformedContent = transformChildContent(content)
221
-
222
- return { children: transformedContent, endIndex: closingIndex }
223
- }
224
-
225
- /**
226
- * Transform content that may contain text, expressions, and nested JSX
227
- */
228
- function transformChildContent(content: string): string {
229
- const parts: string[] = []
230
- let i = 0
231
- let currentText = ''
232
-
233
- while (i < content.length) {
234
- const char = content[i]
235
-
236
- // Check for JSX element
237
- if (char === '<' && /[a-zA-Z]/.test(content[i + 1] || '')) {
238
- // Save any accumulated text
239
- if (currentText.trim()) {
240
- parts.push(`"${escapeString(currentText.trim())}"`)
241
- currentText = ''
242
- }
243
-
244
- // Try to parse as JSX element
245
- const parsed = parseJSXElement(content, i)
246
- if (parsed) {
247
- parts.push(parsed.hCall)
248
- i = parsed.endIndex
249
- continue
250
- }
251
- }
252
-
253
- // Check for expression {expr}
254
- if (char === '{') {
255
- const endBrace = findBalancedBraceEnd(content, i)
256
- if (endBrace !== -1) {
257
- // Save any accumulated text
258
- if (currentText.trim()) {
259
- parts.push(`"${escapeString(currentText.trim())}"`)
260
- currentText = ''
261
- }
262
-
263
- // Extract and add expression
264
- const expr = content.slice(i + 1, endBrace - 1).trim()
265
- if (expr) {
266
- // Transform any JSX inside the expression
267
- const transformedExpr = transformExpressionJSX(expr)
268
- parts.push(transformedExpr)
269
- }
270
- i = endBrace
271
- continue
272
- }
273
- }
274
-
275
- // Accumulate text
276
- currentText += char
277
- i++
278
- }
279
-
280
- // Add remaining text
281
- if (currentText.trim()) {
282
- parts.push(`"${escapeString(currentText.trim())}"`)
283
- }
284
-
285
- if (parts.length === 0) return 'null'
286
- if (parts.length === 1) return parts[0]!
287
- return `[${parts.join(', ')}]`
288
- }
289
-
290
- /**
291
- * Escape a string for use in JavaScript
292
- */
293
- function escapeString(str: string): string {
294
- return str
295
- .replace(/\\/g, '\\\\')
296
- .replace(/"/g, '\\"')
297
- .replace(/\n/g, '\\n')
298
- .replace(/\r/g, '\\r')
299
- .replace(/\t/g, '\\t')
300
- }
301
-
302
- /**
303
- * Parse a single JSX element starting at the given index
304
- */
305
- function parseJSXElement(code: string, startIndex: number): { hCall: string; endIndex: number } | null {
306
- // Extract tag name
307
- const tagMatch = code.slice(startIndex).match(/^<([a-zA-Z][a-zA-Z0-9]*)/)
308
- if (!tagMatch) return null
309
-
310
- const tagName = tagMatch[1]!
311
- let i = startIndex + tagMatch[0].length
312
-
313
- // Parse attributes
314
- const { attrs, endIndex: attrEnd, isSelfClosing } = parseJSXAttributes(code, i)
315
- i = attrEnd
316
-
317
- if (isSelfClosing) {
318
- return {
319
- hCall: `__zenith.h("${tagName}", ${attrs}, null)`,
320
- endIndex: i
321
- }
322
- }
323
-
324
- // Parse children until closing tag
325
- const { children, endIndex: childEnd } = parseJSXChildren(code, i, tagName)
326
- i = childEnd
327
-
328
- // Skip closing tag
329
- const closeTag = `</${tagName}>`
330
- if (code.slice(i, i + closeTag.length).toLowerCase() === closeTag.toLowerCase()) {
331
- i += closeTag.length
332
- }
333
-
334
- return {
335
- hCall: `__zenith.h("${tagName}", ${attrs}, ${children})`,
336
- endIndex: i
337
- }
338
- }
339
-
340
- /**
341
- * Main transformer function
342
- *
343
- * Transforms JSX-like tags inside Zenith expressions into __zenith.h() calls.
344
- */
345
- export function transformExpressionJSX(code: string): string {
346
- // Skip if no JSX-like content (optimization)
347
- if (!/<[a-zA-Z]/.test(code)) {
348
- return code
349
- }
350
-
351
- let result = ''
352
- let i = 0
353
-
354
- while (i < code.length) {
355
- // Look for potential JSX tag start
356
- // Only treat as JSX if it follows common JSX contexts: (, return, =, :, ,, [, ?
357
- if (code[i] === '<' && /[a-zA-Z]/.test(code[i + 1] || '')) {
358
- // Check if this looks like a JSX context
359
- const beforeChar = i > 0 ? code[i - 1] : ''
360
- const beforeTrimmed = code.slice(0, i).trimEnd()
361
- const lastChar = beforeTrimmed[beforeTrimmed.length - 1] || ''
362
-
363
- // Common JSX-starting contexts
364
- const jsxContexts = ['(', '=', ':', ',', '[', '?', '{', 'n'] // 'n' for 'return'
365
- const isJSXContext = jsxContexts.includes(lastChar) ||
366
- beforeTrimmed.endsWith('return') ||
367
- beforeTrimmed === '' ||
368
- (beforeChar && /\s/.test(beforeChar))
369
-
370
- if (isJSXContext) {
371
- const parsed = parseJSXElement(code, i)
372
- if (parsed) {
373
- result += parsed.hCall
374
- i = parsed.endIndex
375
- continue
376
- }
377
- }
378
- }
379
-
380
- result += code[i]
381
- i++
382
- }
383
-
384
- return result
385
- }