@zenithbuild/compiler 1.0.15 → 1.3.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.
Files changed (144) hide show
  1. package/native/compiler-native/compiler-native.node +0 -0
  2. package/native/compiler-native/index.d.ts +46 -7
  3. package/native/compiler-native/index.js +332 -17
  4. package/package.json +3 -3
  5. package/dist/build-analyzer.d.ts +0 -44
  6. package/dist/build-analyzer.js +0 -87
  7. package/dist/bundler.d.ts +0 -31
  8. package/dist/bundler.js +0 -86
  9. package/dist/compiler-native-ep39xj7a.node +0 -0
  10. package/dist/compiler-native-ftk9z446.node +0 -0
  11. package/dist/core/components/index.d.ts +0 -9
  12. package/dist/core/components/index.js +0 -13
  13. package/dist/core/config/index.d.ts +0 -11
  14. package/dist/core/config/index.js +0 -10
  15. package/dist/core/config/loader.d.ts +0 -17
  16. package/dist/core/config/loader.js +0 -60
  17. package/dist/core/config/types.d.ts +0 -98
  18. package/dist/core/config/types.js +0 -32
  19. package/dist/core/index.d.ts +0 -7
  20. package/dist/core/index.js +0 -6
  21. package/dist/core/lifecycle/index.d.ts +0 -16
  22. package/dist/core/lifecycle/index.js +0 -19
  23. package/dist/core/lifecycle/zen-mount.d.ts +0 -66
  24. package/dist/core/lifecycle/zen-mount.js +0 -151
  25. package/dist/core/lifecycle/zen-unmount.d.ts +0 -54
  26. package/dist/core/lifecycle/zen-unmount.js +0 -76
  27. package/dist/core/plugins/bridge.d.ts +0 -116
  28. package/dist/core/plugins/bridge.js +0 -121
  29. package/dist/core/plugins/index.d.ts +0 -6
  30. package/dist/core/plugins/index.js +0 -6
  31. package/dist/core/plugins/registry.d.ts +0 -67
  32. package/dist/core/plugins/registry.js +0 -112
  33. package/dist/core/reactivity/index.d.ts +0 -30
  34. package/dist/core/reactivity/index.js +0 -33
  35. package/dist/core/reactivity/tracking.d.ts +0 -74
  36. package/dist/core/reactivity/tracking.js +0 -136
  37. package/dist/core/reactivity/zen-batch.d.ts +0 -45
  38. package/dist/core/reactivity/zen-batch.js +0 -54
  39. package/dist/core/reactivity/zen-effect.d.ts +0 -48
  40. package/dist/core/reactivity/zen-effect.js +0 -98
  41. package/dist/core/reactivity/zen-memo.d.ts +0 -43
  42. package/dist/core/reactivity/zen-memo.js +0 -100
  43. package/dist/core/reactivity/zen-ref.d.ts +0 -44
  44. package/dist/core/reactivity/zen-ref.js +0 -34
  45. package/dist/core/reactivity/zen-signal.d.ts +0 -48
  46. package/dist/core/reactivity/zen-signal.js +0 -84
  47. package/dist/core/reactivity/zen-state.d.ts +0 -35
  48. package/dist/core/reactivity/zen-state.js +0 -147
  49. package/dist/core/reactivity/zen-untrack.d.ts +0 -38
  50. package/dist/core/reactivity/zen-untrack.js +0 -41
  51. package/dist/css/index.d.ts +0 -73
  52. package/dist/css/index.js +0 -246
  53. package/dist/discovery/componentDiscovery.d.ts +0 -42
  54. package/dist/discovery/componentDiscovery.js +0 -56
  55. package/dist/discovery/layouts.d.ts +0 -13
  56. package/dist/discovery/layouts.js +0 -41
  57. package/dist/errors/compilerError.d.ts +0 -31
  58. package/dist/errors/compilerError.js +0 -51
  59. package/dist/finalize/finalizeOutput.d.ts +0 -32
  60. package/dist/finalize/finalizeOutput.js +0 -62
  61. package/dist/finalize/generateFinalBundle.d.ts +0 -24
  62. package/dist/finalize/generateFinalBundle.js +0 -68
  63. package/dist/index.d.ts +0 -38
  64. package/dist/index.js +0 -57
  65. package/dist/ir/types.d.ts +0 -181
  66. package/dist/ir/types.js +0 -8
  67. package/dist/output/types.d.ts +0 -30
  68. package/dist/output/types.js +0 -6
  69. package/dist/parse/detectMapExpressions.d.ts +0 -45
  70. package/dist/parse/detectMapExpressions.js +0 -77
  71. package/dist/parse/parseScript.d.ts +0 -8
  72. package/dist/parse/parseScript.js +0 -36
  73. package/dist/parse/parseTemplate.d.ts +0 -11
  74. package/dist/parse/parseTemplate.js +0 -487
  75. package/dist/parse/parseZenFile.d.ts +0 -11
  76. package/dist/parse/parseZenFile.js +0 -50
  77. package/dist/parse/scriptAnalysis.d.ts +0 -25
  78. package/dist/parse/scriptAnalysis.js +0 -60
  79. package/dist/parse/trackLoopContext.d.ts +0 -20
  80. package/dist/parse/trackLoopContext.js +0 -62
  81. package/dist/parseZenFile.d.ts +0 -10
  82. package/dist/parseZenFile.js +0 -55
  83. package/dist/runtime/analyzeAndEmit.d.ts +0 -20
  84. package/dist/runtime/analyzeAndEmit.js +0 -70
  85. package/dist/runtime/build.d.ts +0 -6
  86. package/dist/runtime/build.js +0 -13
  87. package/dist/runtime/bundle-generator.d.ts +0 -27
  88. package/dist/runtime/bundle-generator.js +0 -1438
  89. package/dist/runtime/client-runtime.d.ts +0 -41
  90. package/dist/runtime/client-runtime.js +0 -397
  91. package/dist/runtime/dataExposure.d.ts +0 -52
  92. package/dist/runtime/dataExposure.js +0 -227
  93. package/dist/runtime/generateDOM.d.ts +0 -21
  94. package/dist/runtime/generateDOM.js +0 -194
  95. package/dist/runtime/generateHydrationBundle.d.ts +0 -15
  96. package/dist/runtime/generateHydrationBundle.js +0 -399
  97. package/dist/runtime/hydration.d.ts +0 -53
  98. package/dist/runtime/hydration.js +0 -271
  99. package/dist/runtime/navigation.d.ts +0 -58
  100. package/dist/runtime/navigation.js +0 -372
  101. package/dist/runtime/serve.d.ts +0 -13
  102. package/dist/runtime/serve.js +0 -76
  103. package/dist/runtime/thinRuntime.d.ts +0 -23
  104. package/dist/runtime/thinRuntime.js +0 -158
  105. package/dist/runtime/transformIR.d.ts +0 -19
  106. package/dist/runtime/transformIR.js +0 -285
  107. package/dist/runtime/wrapExpression.d.ts +0 -24
  108. package/dist/runtime/wrapExpression.js +0 -76
  109. package/dist/runtime/wrapExpressionWithLoop.d.ts +0 -17
  110. package/dist/runtime/wrapExpressionWithLoop.js +0 -75
  111. package/dist/spa-build.d.ts +0 -26
  112. package/dist/spa-build.js +0 -857
  113. package/dist/ssg-build.d.ts +0 -32
  114. package/dist/ssg-build.js +0 -408
  115. package/dist/test/analyze-emit.test.d.ts +0 -1
  116. package/dist/test/analyze-emit.test.js +0 -88
  117. package/dist/test/bundler-contract.test.d.ts +0 -1
  118. package/dist/test/bundler-contract.test.js +0 -137
  119. package/dist/test/compiler-authority.test.d.ts +0 -1
  120. package/dist/test/compiler-authority.test.js +0 -90
  121. package/dist/test/component-instance-test.d.ts +0 -1
  122. package/dist/test/component-instance-test.js +0 -115
  123. package/dist/test/error-native-bridge.test.d.ts +0 -1
  124. package/dist/test/error-native-bridge.test.js +0 -51
  125. package/dist/test/error-serialization.test.d.ts +0 -1
  126. package/dist/test/error-serialization.test.js +0 -38
  127. package/dist/test/macro-inlining.test.d.ts +0 -1
  128. package/dist/test/macro-inlining.test.js +0 -178
  129. package/dist/test/validate-test.d.ts +0 -6
  130. package/dist/test/validate-test.js +0 -95
  131. package/dist/transform/classifyExpression.d.ts +0 -46
  132. package/dist/transform/classifyExpression.js +0 -359
  133. package/dist/transform/componentResolver.d.ts +0 -15
  134. package/dist/transform/componentResolver.js +0 -24
  135. package/dist/transform/expressionTransformer.d.ts +0 -19
  136. package/dist/transform/expressionTransformer.js +0 -333
  137. package/dist/transform/fragmentLowering.d.ts +0 -25
  138. package/dist/transform/fragmentLowering.js +0 -468
  139. package/dist/transform/layoutProcessor.d.ts +0 -5
  140. package/dist/transform/layoutProcessor.js +0 -34
  141. package/dist/transform/transformTemplate.d.ts +0 -11
  142. package/dist/transform/transformTemplate.js +0 -33
  143. package/dist/validate/invariants.d.ts +0 -23
  144. package/dist/validate/invariants.js +0 -55
@@ -1,359 +0,0 @@
1
- /**
2
- * Expression Classification
3
- *
4
- * Analyzes expression code to determine output type for structural lowering.
5
- *
6
- * JSX expressions are allowed if — and only if — the compiler can statically
7
- * enumerate all possible DOM shapes and lower them at compile time.
8
- */
9
- /**
10
- * Check if code contains JSX-like tags
11
- */
12
- function containsJSX(code) {
13
- // Match opening JSX tags: <Tag or <tag
14
- return /<[a-zA-Z]/.test(code);
15
- }
16
- /**
17
- * Check if expression starts with a JSX element
18
- */
19
- function startsWithJSX(code) {
20
- const trimmed = code.trim();
21
- return /^<[a-zA-Z]/.test(trimmed) || /^<>/.test(trimmed);
22
- }
23
- /**
24
- * Classify expression output type
25
- *
26
- * @param code - The expression code to classify
27
- * @returns Classification result with metadata
28
- */
29
- export function classifyExpression(code) {
30
- const trimmed = code.trim();
31
- // Check for .map() expressions with JSX body
32
- const mapMatch = parseMapExpression(trimmed);
33
- if (mapMatch) {
34
- return {
35
- type: 'loop',
36
- loopSource: mapMatch.source,
37
- loopItemVar: mapMatch.itemVar,
38
- loopIndexVar: mapMatch.indexVar,
39
- loopBody: mapMatch.body
40
- };
41
- }
42
- // Check for ternary with JSX branches: condition ? <A /> : <B />
43
- const ternaryMatch = parseTernaryExpression(trimmed);
44
- if (ternaryMatch && (containsJSX(ternaryMatch.consequent) || containsJSX(ternaryMatch.alternate))) {
45
- return {
46
- type: 'conditional',
47
- condition: ternaryMatch.condition,
48
- consequent: ternaryMatch.consequent,
49
- alternate: ternaryMatch.alternate
50
- };
51
- }
52
- // Check for logical AND with JSX: condition && <A />
53
- const logicalAndMatch = parseLogicalAndExpression(trimmed);
54
- if (logicalAndMatch && containsJSX(logicalAndMatch.fragment)) {
55
- return {
56
- type: 'optional',
57
- optionalCondition: logicalAndMatch.condition,
58
- optionalFragment: logicalAndMatch.fragment
59
- };
60
- }
61
- // All other expressions (including inline JSX like {<span>text</span>})
62
- // are treated as primitive and handled by the existing expression transformer
63
- // which converts JSX to __zenith.h() calls at runtime
64
- return { type: 'primitive' };
65
- }
66
- /**
67
- * Parse .map() expression
68
- *
69
- * Matches:
70
- * - source.map(item => body)
71
- * - source.map((item, index) => body)
72
- */
73
- function parseMapExpression(code) {
74
- // Pattern: source.map(item => body)
75
- // Pattern: source.map((item) => body)
76
- // Pattern: source.map((item, index) => body)
77
- // Find .map(
78
- const mapIndex = code.indexOf('.map(');
79
- if (mapIndex === -1) {
80
- // console.log('[Classify] No .map( found in:', code.slice(0, 50));
81
- return null;
82
- }
83
- const source = code.slice(0, mapIndex).trim();
84
- if (!source)
85
- return null;
86
- // Find the arrow function parameters
87
- let afterMap = code.slice(mapIndex + 5); // after ".map("
88
- // Skip whitespace
89
- afterMap = afterMap.trimStart();
90
- // Check for parenthesized params: (item) or (item, index)
91
- let itemVar;
92
- let indexVar;
93
- let bodyStart;
94
- if (afterMap.startsWith('(')) {
95
- // Find closing paren
96
- const closeParenIndex = findBalancedParen(afterMap, 0);
97
- if (closeParenIndex === -1)
98
- return null;
99
- const paramsStr = afterMap.slice(1, closeParenIndex);
100
- const params = paramsStr.split(',').map(p => p.trim());
101
- itemVar = params[0] || '';
102
- indexVar = params[1];
103
- // Find arrow
104
- const afterParams = afterMap.slice(closeParenIndex + 1).trimStart();
105
- if (!afterParams.startsWith('=>'))
106
- return null;
107
- bodyStart = mapIndex + 5 + (afterMap.length - afterParams.length) + 2;
108
- }
109
- else {
110
- // Simple param: item => body
111
- const arrowIndex = afterMap.indexOf('=>');
112
- if (arrowIndex === -1)
113
- return null;
114
- itemVar = afterMap.slice(0, arrowIndex).trim();
115
- bodyStart = mapIndex + 5 + arrowIndex + 2;
116
- }
117
- if (!itemVar)
118
- return null;
119
- // Extract body (everything after => until the closing paren of .map())
120
- let body = code.slice(bodyStart).trim();
121
- // Remove trailing ) from .map()
122
- if (body.endsWith(')')) {
123
- body = body.slice(0, -1).trim();
124
- }
125
- // Check if body contains JSX
126
- if (!containsJSX(body)) {
127
- console.log('[Classify] Body does not contain JSX:', body.slice(0, 50));
128
- return null;
129
- }
130
- console.log('[Classify] Successfully identified loop for source:', source);
131
- return { source, itemVar, indexVar, body };
132
- }
133
- /**
134
- * Find matching closing parenthesis
135
- */
136
- function findBalancedParen(code, startIndex) {
137
- if (code[startIndex] !== '(')
138
- return -1;
139
- let depth = 1;
140
- let i = startIndex + 1;
141
- while (i < code.length && depth > 0) {
142
- if (code[i] === '(')
143
- depth++;
144
- else if (code[i] === ')')
145
- depth--;
146
- i++;
147
- }
148
- return depth === 0 ? i - 1 : -1;
149
- }
150
- /**
151
- * Parse ternary expression
152
- *
153
- * Matches: condition ? consequent : alternate
154
- */
155
- function parseTernaryExpression(code) {
156
- // Find the ? that's not inside JSX or strings
157
- const questionIndex = findTernaryOperator(code);
158
- if (questionIndex === -1)
159
- return null;
160
- const condition = code.slice(0, questionIndex).trim();
161
- const afterQuestion = code.slice(questionIndex + 1);
162
- // Find the : that matches this ternary
163
- const colonIndex = findTernaryColon(afterQuestion);
164
- if (colonIndex === -1)
165
- return null;
166
- const consequent = afterQuestion.slice(0, colonIndex).trim();
167
- const alternate = afterQuestion.slice(colonIndex + 1).trim();
168
- if (!condition || !consequent || !alternate)
169
- return null;
170
- return { condition, consequent, alternate };
171
- }
172
- /**
173
- * Find ternary ? operator (not inside JSX or nested ternaries)
174
- */
175
- function findTernaryOperator(code) {
176
- let depth = 0;
177
- let inString = false;
178
- let stringChar = '';
179
- let inTemplate = false;
180
- let jsxDepth = 0;
181
- for (let i = 0; i < code.length; i++) {
182
- const char = code[i];
183
- const prevChar = i > 0 ? code[i - 1] : '';
184
- // Handle escape
185
- if (prevChar === '\\')
186
- continue;
187
- // Handle strings
188
- if (!inString && !inTemplate && (char === '"' || char === "'")) {
189
- inString = true;
190
- stringChar = char;
191
- continue;
192
- }
193
- if (inString && char === stringChar) {
194
- inString = false;
195
- continue;
196
- }
197
- // Handle template literals
198
- if (!inString && !inTemplate && char === '`') {
199
- inTemplate = true;
200
- continue;
201
- }
202
- if (inTemplate && char === '`') {
203
- inTemplate = false;
204
- continue;
205
- }
206
- if (inString || inTemplate)
207
- continue;
208
- // Track JSX depth
209
- if (char === '<' && /[a-zA-Z>]/.test(code[i + 1] || '')) {
210
- jsxDepth++;
211
- }
212
- if (char === '>' && prevChar === '/') {
213
- jsxDepth = Math.max(0, jsxDepth - 1);
214
- }
215
- if (char === '/' && code[i + 1] === '>') {
216
- // self-closing tag, depth handled when we see >
217
- }
218
- if (char === '<' && code[i + 1] === '/') {
219
- // closing tag coming
220
- }
221
- if (char === '>' && jsxDepth > 0 && prevChar !== '/' && code.slice(0, i).includes('</')) {
222
- jsxDepth = Math.max(0, jsxDepth - 1);
223
- }
224
- // Track parens
225
- if (char === '(' || char === '{' || char === '[')
226
- depth++;
227
- if (char === ')' || char === '}' || char === ']')
228
- depth--;
229
- // Found ternary operator at top level
230
- if (char === '?' && depth === 0 && jsxDepth === 0) {
231
- return i;
232
- }
233
- }
234
- return -1;
235
- }
236
- /**
237
- * Find ternary : operator (matching the ?)
238
- */
239
- function findTernaryColon(code) {
240
- let depth = 0;
241
- let ternaryDepth = 0;
242
- let inString = false;
243
- let stringChar = '';
244
- let inTemplate = false;
245
- let jsxDepth = 0;
246
- for (let i = 0; i < code.length; i++) {
247
- const char = code[i];
248
- const prevChar = i > 0 ? code[i - 1] : '';
249
- // Handle escape
250
- if (prevChar === '\\')
251
- continue;
252
- // Handle strings
253
- if (!inString && !inTemplate && (char === '"' || char === "'")) {
254
- inString = true;
255
- stringChar = char;
256
- continue;
257
- }
258
- if (inString && char === stringChar) {
259
- inString = false;
260
- continue;
261
- }
262
- // Handle template literals
263
- if (!inString && !inTemplate && char === '`') {
264
- inTemplate = true;
265
- continue;
266
- }
267
- if (inTemplate && char === '`') {
268
- inTemplate = false;
269
- continue;
270
- }
271
- if (inString || inTemplate)
272
- continue;
273
- // Track JSX depth (simplified)
274
- if (char === '<' && /[a-zA-Z>]/.test(code[i + 1] || '')) {
275
- jsxDepth++;
276
- }
277
- if (char === '>' && (prevChar === '/' || jsxDepth > 0)) {
278
- jsxDepth = Math.max(0, jsxDepth - 1);
279
- }
280
- // Track parens
281
- if (char === '(' || char === '{' || char === '[')
282
- depth++;
283
- if (char === ')' || char === '}' || char === ']')
284
- depth--;
285
- // Track nested ternaries
286
- if (char === '?')
287
- ternaryDepth++;
288
- if (char === ':' && ternaryDepth > 0) {
289
- ternaryDepth--;
290
- continue;
291
- }
292
- // Found matching colon at top level
293
- if (char === ':' && depth === 0 && ternaryDepth === 0 && jsxDepth === 0) {
294
- return i;
295
- }
296
- }
297
- return -1;
298
- }
299
- /**
300
- * Parse logical AND expression
301
- *
302
- * Matches: condition && fragment
303
- */
304
- function parseLogicalAndExpression(code) {
305
- // Find && at top level
306
- let depth = 0;
307
- let inString = false;
308
- let stringChar = '';
309
- let inTemplate = false;
310
- for (let i = 0; i < code.length - 1; i++) {
311
- const char = code[i];
312
- const nextChar = code[i + 1];
313
- const prevChar = i > 0 ? code[i - 1] : '';
314
- // Handle escape
315
- if (prevChar === '\\')
316
- continue;
317
- // Handle strings
318
- if (!inString && !inTemplate && (char === '"' || char === "'")) {
319
- inString = true;
320
- stringChar = char;
321
- continue;
322
- }
323
- if (inString && char === stringChar) {
324
- inString = false;
325
- continue;
326
- }
327
- // Handle template literals
328
- if (!inString && !inTemplate && char === '`') {
329
- inTemplate = true;
330
- continue;
331
- }
332
- if (inTemplate && char === '`') {
333
- inTemplate = false;
334
- continue;
335
- }
336
- if (inString || inTemplate)
337
- continue;
338
- // Track parens
339
- if (char === '(' || char === '{' || char === '[')
340
- depth++;
341
- if (char === ')' || char === '}' || char === ']')
342
- depth--;
343
- // Found && at top level
344
- if (char === '&' && nextChar === '&' && depth === 0) {
345
- const condition = code.slice(0, i).trim();
346
- const fragment = code.slice(i + 2).trim();
347
- if (condition && fragment) {
348
- return { condition, fragment };
349
- }
350
- }
351
- }
352
- return null;
353
- }
354
- /**
355
- * Check if an expression type requires structural lowering
356
- */
357
- export function requiresStructuralLowering(type) {
358
- return type === 'conditional' || type === 'optional' || type === 'loop' || type === 'fragment';
359
- }
@@ -1,15 +0,0 @@
1
- import type { ZenIR } from '../ir/types';
2
- import type { ComponentMetadata } from '../discovery/componentDiscovery';
3
- /**
4
- * Inline all components in a ZenIR.
5
- *
6
- * This is Stage 2 of the compiler:
7
- * - Expands <Component /> tags into their templates.
8
- * - Renames local symbols in component scripts and expressions to avoid collisions.
9
- * - Merges component scripts directly into the main page script.
10
- * - Promotes component expressions to the page-level expression registry.
11
- *
12
- * NATIVE IMPLEMENTATION:
13
- * Delegates to the Rust native compiler for performance and correctness.
14
- */
15
- export declare function resolveComponentsInIR(ir: ZenIR, components: Map<string, ComponentMetadata>): ZenIR;
@@ -1,24 +0,0 @@
1
- import { resolveComponentsNative } from '../../native/compiler-native';
2
- /**
3
- * Inline all components in a ZenIR.
4
- *
5
- * This is Stage 2 of the compiler:
6
- * - Expands <Component /> tags into their templates.
7
- * - Renames local symbols in component scripts and expressions to avoid collisions.
8
- * - Merges component scripts directly into the main page script.
9
- * - Promotes component expressions to the page-level expression registry.
10
- *
11
- * NATIVE IMPLEMENTATION:
12
- * Delegates to the Rust native compiler for performance and correctness.
13
- */
14
- export function resolveComponentsInIR(ir, components) {
15
- const irJson = JSON.stringify(ir);
16
- // Convert Map to record for JSON serialization
17
- const componentsRecord = {};
18
- for (const [key, value] of components) {
19
- componentsRecord[key] = value;
20
- }
21
- const componentsJson = JSON.stringify(componentsRecord);
22
- const resolvedJson = resolveComponentsNative(irJson, componentsJson);
23
- return JSON.parse(resolvedJson);
24
- }
@@ -1,19 +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
- * Main transformer function
16
- *
17
- * Transforms JSX-like tags inside Zenith expressions into __zenith.h() calls.
18
- */
19
- export declare function transformExpressionJSX(code: string): string;