@zenithbuild/compiler 1.0.2

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/build-analyzer.d.ts +44 -0
  4. package/dist/build-analyzer.js +87 -0
  5. package/dist/bundler.d.ts +31 -0
  6. package/dist/bundler.js +86 -0
  7. package/dist/core/components/index.d.ts +9 -0
  8. package/dist/core/components/index.js +13 -0
  9. package/dist/core/config/index.d.ts +11 -0
  10. package/dist/core/config/index.js +10 -0
  11. package/dist/core/config/loader.d.ts +17 -0
  12. package/dist/core/config/loader.js +60 -0
  13. package/dist/core/config/types.d.ts +98 -0
  14. package/dist/core/config/types.js +32 -0
  15. package/dist/core/index.d.ts +7 -0
  16. package/dist/core/index.js +6 -0
  17. package/dist/core/lifecycle/index.d.ts +16 -0
  18. package/dist/core/lifecycle/index.js +19 -0
  19. package/dist/core/lifecycle/zen-mount.d.ts +66 -0
  20. package/dist/core/lifecycle/zen-mount.js +151 -0
  21. package/dist/core/lifecycle/zen-unmount.d.ts +54 -0
  22. package/dist/core/lifecycle/zen-unmount.js +76 -0
  23. package/dist/core/plugins/bridge.d.ts +116 -0
  24. package/dist/core/plugins/bridge.js +121 -0
  25. package/dist/core/plugins/index.d.ts +6 -0
  26. package/dist/core/plugins/index.js +6 -0
  27. package/dist/core/plugins/registry.d.ts +67 -0
  28. package/dist/core/plugins/registry.js +113 -0
  29. package/dist/core/reactivity/index.d.ts +30 -0
  30. package/dist/core/reactivity/index.js +33 -0
  31. package/dist/core/reactivity/tracking.d.ts +74 -0
  32. package/dist/core/reactivity/tracking.js +136 -0
  33. package/dist/core/reactivity/zen-batch.d.ts +45 -0
  34. package/dist/core/reactivity/zen-batch.js +54 -0
  35. package/dist/core/reactivity/zen-effect.d.ts +48 -0
  36. package/dist/core/reactivity/zen-effect.js +98 -0
  37. package/dist/core/reactivity/zen-memo.d.ts +43 -0
  38. package/dist/core/reactivity/zen-memo.js +100 -0
  39. package/dist/core/reactivity/zen-ref.d.ts +44 -0
  40. package/dist/core/reactivity/zen-ref.js +34 -0
  41. package/dist/core/reactivity/zen-signal.d.ts +48 -0
  42. package/dist/core/reactivity/zen-signal.js +84 -0
  43. package/dist/core/reactivity/zen-state.d.ts +35 -0
  44. package/dist/core/reactivity/zen-state.js +147 -0
  45. package/dist/core/reactivity/zen-untrack.d.ts +38 -0
  46. package/dist/core/reactivity/zen-untrack.js +41 -0
  47. package/dist/css/index.d.ts +73 -0
  48. package/dist/css/index.js +246 -0
  49. package/dist/discovery/componentDiscovery.d.ts +42 -0
  50. package/dist/discovery/componentDiscovery.js +56 -0
  51. package/dist/discovery/layouts.d.ts +13 -0
  52. package/dist/discovery/layouts.js +41 -0
  53. package/dist/errors/compilerError.d.ts +31 -0
  54. package/dist/errors/compilerError.js +51 -0
  55. package/dist/finalize/finalizeOutput.d.ts +32 -0
  56. package/dist/finalize/finalizeOutput.js +62 -0
  57. package/dist/finalize/generateFinalBundle.d.ts +24 -0
  58. package/dist/finalize/generateFinalBundle.js +68 -0
  59. package/dist/index.d.ts +36 -0
  60. package/dist/index.js +51 -0
  61. package/dist/ir/types.d.ts +181 -0
  62. package/dist/ir/types.js +8 -0
  63. package/dist/output/types.d.ts +30 -0
  64. package/dist/output/types.js +6 -0
  65. package/dist/parse/detectMapExpressions.d.ts +45 -0
  66. package/dist/parse/detectMapExpressions.js +77 -0
  67. package/dist/parse/parseScript.d.ts +8 -0
  68. package/dist/parse/parseScript.js +36 -0
  69. package/dist/parse/parseTemplate.d.ts +11 -0
  70. package/dist/parse/parseTemplate.js +487 -0
  71. package/dist/parse/parseZenFile.d.ts +11 -0
  72. package/dist/parse/parseZenFile.js +50 -0
  73. package/dist/parse/scriptAnalysis.d.ts +25 -0
  74. package/dist/parse/scriptAnalysis.js +60 -0
  75. package/dist/parse/trackLoopContext.d.ts +20 -0
  76. package/dist/parse/trackLoopContext.js +62 -0
  77. package/dist/parseZenFile.d.ts +10 -0
  78. package/dist/parseZenFile.js +55 -0
  79. package/dist/runtime/analyzeAndEmit.d.ts +20 -0
  80. package/dist/runtime/analyzeAndEmit.js +70 -0
  81. package/dist/runtime/build.d.ts +6 -0
  82. package/dist/runtime/build.js +13 -0
  83. package/dist/runtime/bundle-generator.d.ts +27 -0
  84. package/dist/runtime/bundle-generator.js +1263 -0
  85. package/dist/runtime/client-runtime.d.ts +41 -0
  86. package/dist/runtime/client-runtime.js +397 -0
  87. package/dist/runtime/dataExposure.d.ts +52 -0
  88. package/dist/runtime/dataExposure.js +227 -0
  89. package/dist/runtime/generateDOM.d.ts +21 -0
  90. package/dist/runtime/generateDOM.js +194 -0
  91. package/dist/runtime/generateHydrationBundle.d.ts +15 -0
  92. package/dist/runtime/generateHydrationBundle.js +399 -0
  93. package/dist/runtime/hydration.d.ts +53 -0
  94. package/dist/runtime/hydration.js +271 -0
  95. package/dist/runtime/navigation.d.ts +58 -0
  96. package/dist/runtime/navigation.js +372 -0
  97. package/dist/runtime/serve.d.ts +13 -0
  98. package/dist/runtime/serve.js +76 -0
  99. package/dist/runtime/thinRuntime.d.ts +23 -0
  100. package/dist/runtime/thinRuntime.js +158 -0
  101. package/dist/runtime/transformIR.d.ts +19 -0
  102. package/dist/runtime/transformIR.js +285 -0
  103. package/dist/runtime/wrapExpression.d.ts +24 -0
  104. package/dist/runtime/wrapExpression.js +76 -0
  105. package/dist/runtime/wrapExpressionWithLoop.d.ts +17 -0
  106. package/dist/runtime/wrapExpressionWithLoop.js +75 -0
  107. package/dist/spa-build.d.ts +26 -0
  108. package/dist/spa-build.js +866 -0
  109. package/dist/ssg-build.d.ts +32 -0
  110. package/dist/ssg-build.js +408 -0
  111. package/dist/test/analyze-emit.test.d.ts +1 -0
  112. package/dist/test/analyze-emit.test.js +88 -0
  113. package/dist/test/bundler-contract.test.d.ts +1 -0
  114. package/dist/test/bundler-contract.test.js +137 -0
  115. package/dist/test/compiler-authority.test.d.ts +1 -0
  116. package/dist/test/compiler-authority.test.js +90 -0
  117. package/dist/test/component-instance-test.d.ts +1 -0
  118. package/dist/test/component-instance-test.js +115 -0
  119. package/dist/test/error-native-bridge.test.d.ts +1 -0
  120. package/dist/test/error-native-bridge.test.js +51 -0
  121. package/dist/test/error-serialization.test.d.ts +1 -0
  122. package/dist/test/error-serialization.test.js +38 -0
  123. package/dist/test/macro-inlining.test.d.ts +1 -0
  124. package/dist/test/macro-inlining.test.js +178 -0
  125. package/dist/test/validate-test.d.ts +6 -0
  126. package/dist/test/validate-test.js +95 -0
  127. package/dist/transform/classifyExpression.d.ts +46 -0
  128. package/dist/transform/classifyExpression.js +354 -0
  129. package/dist/transform/componentResolver.d.ts +15 -0
  130. package/dist/transform/componentResolver.js +30 -0
  131. package/dist/transform/expressionTransformer.d.ts +19 -0
  132. package/dist/transform/expressionTransformer.js +333 -0
  133. package/dist/transform/fragmentLowering.d.ts +25 -0
  134. package/dist/transform/fragmentLowering.js +468 -0
  135. package/dist/transform/layoutProcessor.d.ts +5 -0
  136. package/dist/transform/layoutProcessor.js +34 -0
  137. package/dist/transform/transformTemplate.d.ts +11 -0
  138. package/dist/transform/transformTemplate.js +33 -0
  139. package/dist/validate/invariants.d.ts +23 -0
  140. package/dist/validate/invariants.js +55 -0
  141. package/native/compiler-native/compiler-native.node +0 -0
  142. package/native/compiler-native/index.d.ts +113 -0
  143. package/native/compiler-native/index.js +19 -0
  144. package/native/compiler-native/package.json +19 -0
  145. package/package.json +49 -0
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Expression Wrapper with Loop Context Support
3
+ *
4
+ * Phase 7: Wraps expressions that reference loop variables from map iterations
5
+ *
6
+ * Generates runtime functions that accept (state, loaderData, props, stores, loopContext)
7
+ * and evaluate expressions with both global state and loop-scoped variables available
8
+ */
9
+ import type { ExpressionIR, LoopContext } from '../ir/types';
10
+ import type { ExpressionDataDependencies } from './dataExposure';
11
+ /**
12
+ * Generate an expression wrapper that accepts loop context
13
+ *
14
+ * Phase 7: Expressions inside map loops need access to loop variables (e.g., todo, index)
15
+ * in addition to global state (state, loaderData, props, stores)
16
+ */
17
+ export declare function wrapExpressionWithLoopContext(expr: ExpressionIR, loopContext?: LoopContext, dependencies?: ExpressionDataDependencies): string;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Expression Wrapper with Loop Context Support
3
+ *
4
+ * Phase 7: Wraps expressions that reference loop variables from map iterations
5
+ *
6
+ * Generates runtime functions that accept (state, loaderData, props, stores, loopContext)
7
+ * and evaluate expressions with both global state and loop-scoped variables available
8
+ */
9
+ import { transformExpressionJSX } from '../transform/expressionTransformer';
10
+ /**
11
+ * Generate an expression wrapper that accepts loop context
12
+ *
13
+ * Phase 7: Expressions inside map loops need access to loop variables (e.g., todo, index)
14
+ * in addition to global state (state, loaderData, props, stores)
15
+ */
16
+ export function wrapExpressionWithLoopContext(expr, loopContext, dependencies) {
17
+ const { id, code } = expr;
18
+ const escapedCode = code.replace(/`/g, '\\`').replace(/\$/g, '\\$');
19
+ if (!loopContext || loopContext.variables.length === 0) {
20
+ // No loop context - use standard wrapper (will be handled by wrapExpression)
21
+ return '';
22
+ }
23
+ // Determine arguments based on dependencies
24
+ const args = [];
25
+ if (dependencies?.usesState || (dependencies?.stateProperties && dependencies.stateProperties.length > 0))
26
+ args.push('state');
27
+ if (dependencies?.usesLoaderData)
28
+ args.push('loaderData');
29
+ if (dependencies?.usesProps)
30
+ args.push('props');
31
+ if (dependencies?.usesStores)
32
+ args.push('stores');
33
+ // Phase 7: Always add loopContext as the last argument
34
+ args.push('loopContext');
35
+ const argsStr = args.join(', ');
36
+ // Generate function that merges state and loop context
37
+ // Loop context variables take precedence over state properties with the same name
38
+ const loopVarsDecl = loopContext.variables.map(v => ` const ${v} = loopContext?.${v};`).join('\n');
39
+ const loopVarsObject = `{ ${loopContext.variables.join(', ')} }`;
40
+ // Create merged context for expression evaluation
41
+ // Order: loopContext > stores > props > loaderData > state
42
+ const contextMerge = [];
43
+ if (dependencies?.usesState || (dependencies?.stateProperties && dependencies.stateProperties.length > 0))
44
+ contextMerge.push('state');
45
+ if (dependencies?.usesStores)
46
+ contextMerge.push('stores');
47
+ if (dependencies?.usesProps)
48
+ contextMerge.push('props');
49
+ if (dependencies?.usesLoaderData)
50
+ contextMerge.push('loaderData');
51
+ if (loopContext)
52
+ contextMerge.push('loopContext');
53
+ const contextObject = contextMerge.length > 0
54
+ ? `const __ctx = Object.assign({}, ${contextMerge.join(', ')});`
55
+ : `const __ctx = loopContext || {};`;
56
+ // Transform JSX
57
+ // The fix for 'undefined' string assignment is applied within transformExpressionJSX
58
+ // by ensuring that any remaining text is properly quoted as a string literal
59
+ // or recognized as an existing h() call.
60
+ const transformedCode = transformExpressionJSX(code);
61
+ return `
62
+ // Expression with loop context: ${escapedCode}
63
+ // Loop variables: ${loopContext.variables.join(', ')}
64
+ const ${id} = (${argsStr}) => {
65
+ try {
66
+ ${contextObject}
67
+ with (__ctx) {
68
+ return ${transformedCode};
69
+ }
70
+ } catch (e) {
71
+ console.warn('[Zenith] Expression evaluation error for "${escapedCode}":', e);
72
+ return undefined;
73
+ }
74
+ };`;
75
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Zenith SPA Build System
3
+ *
4
+ * Builds all pages into a single index.html with:
5
+ * - Route manifest
6
+ * - Compiled page modules (inlined)
7
+ * - Runtime router
8
+ * - Shell HTML with router outlet
9
+ */
10
+ interface SPABuildOptions {
11
+ /** Pages directory */
12
+ pagesDir: string;
13
+ /** Output directory */
14
+ outDir: string;
15
+ /** Base directory for components/layouts */
16
+ baseDir?: string;
17
+ }
18
+ /**
19
+ * Build SPA from pages directory
20
+ */
21
+ export declare function buildSPA(options: SPABuildOptions): Promise<void>;
22
+ /**
23
+ * Watch mode for development (future)
24
+ */
25
+ export declare function watchSPA(_options: SPABuildOptions): void;
26
+ export {};