@zenithbuild/core 0.6.2 → 0.6.4

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 (112) hide show
  1. package/CORE_CONTRACT.md +145 -0
  2. package/README.md +14 -29
  3. package/bin/zenith.js +89 -0
  4. package/package.json +39 -56
  5. package/src/config.js +136 -0
  6. package/src/core-template.js +30 -0
  7. package/src/errors.js +54 -0
  8. package/src/guards.js +61 -0
  9. package/src/hash.js +52 -0
  10. package/src/index.js +26 -0
  11. package/src/ir/index.js +1 -0
  12. package/src/order.js +69 -0
  13. package/src/path.js +131 -0
  14. package/src/schema.js +28 -0
  15. package/src/version.js +67 -0
  16. package/bin/zen-build.ts +0 -2
  17. package/bin/zen-dev.ts +0 -2
  18. package/bin/zen-preview.ts +0 -2
  19. package/bin/zenith.ts +0 -2
  20. package/cli/commands/add.ts +0 -37
  21. package/cli/commands/build.ts +0 -37
  22. package/cli/commands/create.ts +0 -702
  23. package/cli/commands/dev.ts +0 -388
  24. package/cli/commands/index.ts +0 -112
  25. package/cli/commands/preview.ts +0 -62
  26. package/cli/commands/remove.ts +0 -33
  27. package/cli/index.ts +0 -10
  28. package/cli/main.ts +0 -101
  29. package/cli/utils/branding.ts +0 -178
  30. package/cli/utils/content.ts +0 -112
  31. package/cli/utils/logger.ts +0 -46
  32. package/cli/utils/plugin-manager.ts +0 -114
  33. package/cli/utils/project.ts +0 -77
  34. package/compiler/README.md +0 -380
  35. package/compiler/build-analyzer.ts +0 -122
  36. package/compiler/css/index.ts +0 -317
  37. package/compiler/discovery/componentDiscovery.ts +0 -178
  38. package/compiler/discovery/layouts.ts +0 -70
  39. package/compiler/errors/compilerError.ts +0 -56
  40. package/compiler/finalize/finalizeOutput.ts +0 -192
  41. package/compiler/finalize/generateFinalBundle.ts +0 -82
  42. package/compiler/index.ts +0 -83
  43. package/compiler/ir/types.ts +0 -174
  44. package/compiler/output/types.ts +0 -34
  45. package/compiler/parse/detectMapExpressions.ts +0 -102
  46. package/compiler/parse/importTypes.ts +0 -78
  47. package/compiler/parse/parseImports.ts +0 -309
  48. package/compiler/parse/parseScript.ts +0 -46
  49. package/compiler/parse/parseTemplate.ts +0 -599
  50. package/compiler/parse/parseZenFile.ts +0 -66
  51. package/compiler/parse/scriptAnalysis.ts +0 -91
  52. package/compiler/parse/trackLoopContext.ts +0 -82
  53. package/compiler/runtime/dataExposure.ts +0 -317
  54. package/compiler/runtime/generateDOM.ts +0 -246
  55. package/compiler/runtime/generateHydrationBundle.ts +0 -407
  56. package/compiler/runtime/hydration.ts +0 -309
  57. package/compiler/runtime/navigation.ts +0 -432
  58. package/compiler/runtime/thinRuntime.ts +0 -160
  59. package/compiler/runtime/transformIR.ts +0 -370
  60. package/compiler/runtime/wrapExpression.ts +0 -95
  61. package/compiler/runtime/wrapExpressionWithLoop.ts +0 -83
  62. package/compiler/spa-build.ts +0 -917
  63. package/compiler/ssg-build.ts +0 -422
  64. package/compiler/test/validate-test.ts +0 -104
  65. package/compiler/transform/classifyExpression.ts +0 -444
  66. package/compiler/transform/componentResolver.ts +0 -312
  67. package/compiler/transform/componentScriptTransformer.ts +0 -303
  68. package/compiler/transform/expressionTransformer.ts +0 -385
  69. package/compiler/transform/fragmentLowering.ts +0 -634
  70. package/compiler/transform/generateBindings.ts +0 -47
  71. package/compiler/transform/generateHTML.ts +0 -28
  72. package/compiler/transform/layoutProcessor.ts +0 -132
  73. package/compiler/transform/slotResolver.ts +0 -292
  74. package/compiler/transform/transformNode.ts +0 -126
  75. package/compiler/transform/transformTemplate.ts +0 -38
  76. package/compiler/validate/invariants.ts +0 -292
  77. package/compiler/validate/validateExpressions.ts +0 -168
  78. package/core/config/index.ts +0 -16
  79. package/core/config/loader.ts +0 -69
  80. package/core/config/types.ts +0 -89
  81. package/core/index.ts +0 -135
  82. package/core/lifecycle/index.ts +0 -49
  83. package/core/lifecycle/zen-mount.ts +0 -182
  84. package/core/lifecycle/zen-unmount.ts +0 -88
  85. package/core/plugins/index.ts +0 -7
  86. package/core/plugins/registry.ts +0 -81
  87. package/core/reactivity/index.ts +0 -54
  88. package/core/reactivity/tracking.ts +0 -167
  89. package/core/reactivity/zen-batch.ts +0 -57
  90. package/core/reactivity/zen-effect.ts +0 -139
  91. package/core/reactivity/zen-memo.ts +0 -146
  92. package/core/reactivity/zen-ref.ts +0 -52
  93. package/core/reactivity/zen-signal.ts +0 -121
  94. package/core/reactivity/zen-state.ts +0 -180
  95. package/core/reactivity/zen-untrack.ts +0 -44
  96. package/dist/cli.js +0 -11665
  97. package/dist/zen-build.js +0 -21172
  98. package/dist/zen-dev.js +0 -21172
  99. package/dist/zen-preview.js +0 -21172
  100. package/dist/zenith.js +0 -21172
  101. package/router/index.ts +0 -28
  102. package/router/manifest.ts +0 -314
  103. package/router/navigation/ZenLink.zen +0 -231
  104. package/router/navigation/index.ts +0 -78
  105. package/router/navigation/zen-link.ts +0 -584
  106. package/router/runtime.ts +0 -458
  107. package/router/types.ts +0 -168
  108. package/runtime/build.ts +0 -17
  109. package/runtime/bundle-generator.ts +0 -1247
  110. package/runtime/client-runtime.ts +0 -549
  111. package/runtime/serve.ts +0 -93
  112. package/tsconfig.json +0 -28
@@ -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
- }