@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,62 @@
1
+ /**
2
+ * Loop Context Tracking
3
+ *
4
+ * Phase 7: Utilities for tracking and propagating loop context through the parse tree
5
+ */
6
+ import { detectMapExpression, referencesLoopVariable } from './detectMapExpressions';
7
+ /**
8
+ * Check if an expression should have loop context attached
9
+ * Returns the loop context if the expression references loop variables
10
+ */
11
+ export function shouldAttachLoopContext(expr, parentLoopContext) {
12
+ if (!parentLoopContext) {
13
+ return undefined;
14
+ }
15
+ // Check if this expression references any loop variables
16
+ if (referencesLoopVariable(expr.code, parentLoopContext.variables)) {
17
+ return parentLoopContext;
18
+ }
19
+ return undefined;
20
+ }
21
+ /**
22
+ * Merge loop contexts for nested loops
23
+ * Inner loops inherit outer loop variables
24
+ */
25
+ export function mergeLoopContext(outer, inner) {
26
+ if (!inner) {
27
+ return outer;
28
+ }
29
+ if (!outer) {
30
+ return inner;
31
+ }
32
+ // Merge variables: outer variables come first, then inner
33
+ // This allows expressions to reference both outer and inner loop variables
34
+ return {
35
+ variables: [...outer.variables, ...inner.variables],
36
+ mapSource: inner.mapSource || outer.mapSource
37
+ };
38
+ }
39
+ /**
40
+ * Detect if an expression is a map expression and extract its loop context
41
+ */
42
+ export function extractLoopContextFromExpression(expr) {
43
+ const mapInfo = detectMapExpression(expr);
44
+ if (!mapInfo.isMap) {
45
+ return undefined;
46
+ }
47
+ // extractLoopVariables expects a MapExpressionInfo, not a string
48
+ const variables = [];
49
+ if (mapInfo.itemVariable) {
50
+ variables.push(mapInfo.itemVariable);
51
+ }
52
+ if (mapInfo.indexVariable) {
53
+ variables.push(mapInfo.indexVariable);
54
+ }
55
+ if (variables.length === 0) {
56
+ return undefined;
57
+ }
58
+ return {
59
+ variables,
60
+ mapSource: mapInfo.arraySource
61
+ };
62
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Zenith File Parser (Native Bridge)
3
+ *
4
+ * Delegates parsing of .zen files to the Rust native compiler.
5
+ */
6
+ import type { ZenIR } from './ir/types';
7
+ /**
8
+ * Parse a .zen file into IR via Native Bridge
9
+ */
10
+ export declare function parseZenFile(filePath: string, sourceInput?: string): ZenIR;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Zenith File Parser (Native Bridge)
3
+ *
4
+ * Delegates parsing of .zen files to the Rust native compiler.
5
+ */
6
+ import { readFileSync } from 'fs';
7
+ import { CompilerError } from './errors/compilerError';
8
+ let native;
9
+ try {
10
+ try {
11
+ native = require('../native/compiler-native');
12
+ }
13
+ catch {
14
+ native = require('../native/compiler-native/index.js');
15
+ }
16
+ }
17
+ catch (e) {
18
+ // Bridge load handled elsewhere
19
+ }
20
+ /**
21
+ * Parse a .zen file into IR via Native Bridge
22
+ */
23
+ export function parseZenFile(filePath, sourceInput) {
24
+ let source;
25
+ if (sourceInput) {
26
+ source = sourceInput;
27
+ }
28
+ else {
29
+ try {
30
+ source = readFileSync(filePath, 'utf-8');
31
+ }
32
+ catch (error) {
33
+ throw new CompilerError(`Failed to read file: ${error.message}`, filePath, 1, 1);
34
+ }
35
+ }
36
+ if (native && native.parseTemplateNative && native.parseScriptNative && native.extractStylesNative) {
37
+ try {
38
+ const template = native.parseTemplateNative(source, filePath);
39
+ const script = native.parseScriptNative(source);
40
+ const stylesRaw = native.extractStylesNative(source);
41
+ const styles = stylesRaw.map((s) => ({ raw: s }));
42
+ return {
43
+ filePath,
44
+ template,
45
+ script,
46
+ styles
47
+ };
48
+ }
49
+ catch (error) {
50
+ console.warn(`[Zenith Native] Parsing failed for ${filePath}: ${error.message}`);
51
+ throw error;
52
+ }
53
+ }
54
+ throw new Error(`[Zenith Native] Parser bridge unavailable - cannot compile ${filePath}`);
55
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Transform IR to Runtime Code
3
+ *
4
+ * NATIVE BRIDGE: Delegates ALL compilation to Rust (`native/compiler-native/src/codegen.rs`).
5
+ */
6
+ import type { ZenIR } from '../ir/types';
7
+ export interface RuntimeCode {
8
+ expressions: string;
9
+ render: string;
10
+ hydration: string;
11
+ styles: string;
12
+ script: string;
13
+ stateInit: string;
14
+ bundle: string;
15
+ npmImports: any[];
16
+ }
17
+ /**
18
+ * Analyze ZenIR and emit runtime JavaScript code via Native Bridge
19
+ */
20
+ export declare function analyzeAndEmit(ir: ZenIR): Promise<RuntimeCode>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Transform IR to Runtime Code
3
+ *
4
+ * NATIVE BRIDGE: Delegates ALL compilation to Rust (`native/compiler-native/src/codegen.rs`).
5
+ */
6
+ let native;
7
+ try {
8
+ try {
9
+ native = require('../../native/compiler-native');
10
+ }
11
+ catch {
12
+ native = require('../../native/compiler-native/index.js');
13
+ }
14
+ }
15
+ catch (e) {
16
+ // Bridge load handled elsewhere
17
+ }
18
+ /**
19
+ * Analyze ZenIR and emit runtime JavaScript code via Native Bridge
20
+ */
21
+ export async function analyzeAndEmit(ir) {
22
+ const scriptContent = ir.script?.raw || '';
23
+ if (!native || !native.generateRuntimeCode) {
24
+ throw new Error(`[Zenith Native] Runtime codegen bridge unavailable`);
25
+ }
26
+ const codegenInput = {
27
+ filePath: ir.filePath,
28
+ scriptContent: scriptContent,
29
+ expressions: ir.template.expressions,
30
+ styles: ir.styles.map(s => ({ raw: s.raw })),
31
+ templateBindings: collectTemplateBindings(ir.template.nodes),
32
+ location: ir.filePath,
33
+ nodes: ir.template.nodes,
34
+ pageBindings: ir.pageBindings || [],
35
+ };
36
+ try {
37
+ return native.generateRuntimeCode(JSON.stringify(codegenInput));
38
+ }
39
+ catch (e) {
40
+ throw new Error(`[Zenith Native] Codegen failed: ${e.message}`);
41
+ }
42
+ }
43
+ /**
44
+ * Collect template bindings (loop item/index variables) for native codegen
45
+ */
46
+ function collectTemplateBindings(nodes) {
47
+ const bindings = [];
48
+ function walk(nodeList) {
49
+ for (const node of nodeList) {
50
+ if (node.type === 'loop-fragment') {
51
+ bindings.push(node.itemVar);
52
+ if (node.indexVar)
53
+ bindings.push(node.indexVar);
54
+ walk(node.body);
55
+ }
56
+ else if (node.type === 'element') {
57
+ walk(node.children);
58
+ }
59
+ else if (node.type === 'conditional-fragment') {
60
+ walk(node.consequent);
61
+ walk(node.alternate);
62
+ }
63
+ else if (node.type === 'optional-fragment') {
64
+ walk(node.fragment);
65
+ }
66
+ }
67
+ }
68
+ walk(nodes);
69
+ return bindings;
70
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Zenith App Build Script
3
+ *
4
+ * Builds all pages into a single SPA with file-based routing.
5
+ */
6
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Zenith App Build Script
3
+ *
4
+ * Builds all pages into a single SPA with file-based routing.
5
+ */
6
+ import { buildSPA } from "../spa-build";
7
+ import path from "path";
8
+ const appDir = path.resolve(import.meta.dir, "..", "app");
9
+ buildSPA({
10
+ pagesDir: path.join(appDir, "pages"),
11
+ outDir: path.join(appDir, "dist"),
12
+ baseDir: appDir
13
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Zenith Bundle Generator
3
+ *
4
+ * Generates the shared client runtime bundle that gets served as:
5
+ * - /assets/bundle.js in production
6
+ * - /runtime.js in development
7
+ *
8
+ * This is a cacheable, versioned file that contains:
9
+ * - Reactivity primitives (zenSignal, zenState, zenEffect, etc.)
10
+ * - Lifecycle hooks (zenOnMount, zenOnUnmount)
11
+ * - Hydration functions (zenithHydrate)
12
+ * - Event binding utilities
13
+ */
14
+ /**
15
+ * Generate the complete client runtime bundle
16
+ * This is served as an external JS file, not inlined
17
+ */
18
+ export declare function generateBundleJS(pluginData?: Record<string, any>): string;
19
+ /**
20
+ * Generate a minified version of the bundle
21
+ * For production builds
22
+ */
23
+ export declare function generateMinifiedBundleJS(): string;
24
+ /**
25
+ * Get bundle version for cache busting
26
+ */
27
+ export declare function getBundleVersion(): string;