@zenithbuild/compiler 1.3.2 → 1.3.9

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 (73) hide show
  1. package/dist/build-analyzer.d.ts +44 -0
  2. package/dist/build-analyzer.js +87 -0
  3. package/dist/bundler.d.ts +31 -0
  4. package/dist/bundler.js +92 -0
  5. package/dist/core/config/index.d.ts +11 -0
  6. package/dist/core/config/index.js +10 -0
  7. package/dist/core/config/loader.d.ts +17 -0
  8. package/dist/core/config/loader.js +60 -0
  9. package/dist/core/config/types.d.ts +98 -0
  10. package/dist/core/config/types.js +32 -0
  11. package/dist/core/index.d.ts +7 -0
  12. package/dist/core/index.js +6 -0
  13. package/dist/core/plugins/bridge.d.ts +116 -0
  14. package/dist/core/plugins/bridge.js +121 -0
  15. package/dist/core/plugins/index.d.ts +6 -0
  16. package/dist/core/plugins/index.js +6 -0
  17. package/dist/core/plugins/registry.d.ts +67 -0
  18. package/dist/core/plugins/registry.js +112 -0
  19. package/dist/css/index.d.ts +73 -0
  20. package/dist/css/index.js +246 -0
  21. package/dist/discovery/componentDiscovery.d.ts +41 -0
  22. package/dist/discovery/componentDiscovery.js +66 -0
  23. package/dist/discovery/layouts.d.ts +14 -0
  24. package/dist/discovery/layouts.js +36 -0
  25. package/dist/errors/compilerError.d.ts +31 -0
  26. package/dist/errors/compilerError.js +51 -0
  27. package/dist/finalize/generateFinalBundle.d.ts +24 -0
  28. package/dist/finalize/generateFinalBundle.js +68 -0
  29. package/dist/index.d.ts +34 -0
  30. package/dist/index.js +44 -0
  31. package/dist/ir/types.d.ts +206 -0
  32. package/dist/ir/types.js +8 -0
  33. package/dist/output/types.d.ts +39 -0
  34. package/dist/output/types.js +6 -0
  35. package/dist/parseZenFile.d.ts +17 -0
  36. package/dist/parseZenFile.js +52 -0
  37. package/dist/runtime/build.d.ts +6 -0
  38. package/dist/runtime/build.js +13 -0
  39. package/dist/runtime/bundle-generator.d.ts +27 -0
  40. package/dist/runtime/bundle-generator.js +1438 -0
  41. package/dist/runtime/client-runtime.d.ts +41 -0
  42. package/dist/runtime/client-runtime.js +397 -0
  43. package/dist/runtime/hydration.d.ts +53 -0
  44. package/dist/runtime/hydration.js +271 -0
  45. package/dist/runtime/navigation.d.ts +58 -0
  46. package/dist/runtime/navigation.js +372 -0
  47. package/dist/runtime/serve.d.ts +13 -0
  48. package/dist/runtime/serve.js +76 -0
  49. package/dist/runtime/thinRuntime.d.ts +23 -0
  50. package/dist/runtime/thinRuntime.js +158 -0
  51. package/dist/spa-build.d.ts +26 -0
  52. package/dist/spa-build.js +849 -0
  53. package/dist/ssg-build.d.ts +31 -0
  54. package/dist/ssg-build.js +429 -0
  55. package/dist/test/bundler-contract.test.d.ts +1 -0
  56. package/dist/test/bundler-contract.test.js +137 -0
  57. package/dist/test/compiler-entry.test.d.ts +1 -0
  58. package/dist/test/compiler-entry.test.js +28 -0
  59. package/dist/test/error-native-bridge.test.d.ts +1 -0
  60. package/dist/test/error-native-bridge.test.js +31 -0
  61. package/dist/test/error-serialization.test.d.ts +1 -0
  62. package/dist/test/error-serialization.test.js +38 -0
  63. package/dist/test/phase5-boundary.test.d.ts +1 -0
  64. package/dist/test/phase5-boundary.test.js +51 -0
  65. package/dist/transform/layoutProcessor.d.ts +26 -0
  66. package/dist/transform/layoutProcessor.js +34 -0
  67. package/dist/validate/invariants.d.ts +23 -0
  68. package/dist/validate/invariants.js +55 -0
  69. package/native/compiler-native/compiler-native.node +0 -0
  70. package/native/compiler-native/index.d.ts +2 -46
  71. package/native/compiler-native/index.js +1 -16
  72. package/native/compiler-native/package.json +1 -1
  73. package/package.json +15 -5
@@ -0,0 +1,38 @@
1
+ import { InvariantError, CompilerError } from '../errors/compilerError';
2
+ /**
3
+ * Test cases for the enhanced Error System
4
+ */
5
+ function testErrorStructure() {
6
+ console.log('Testing CompilerError structure...');
7
+ const error = new CompilerError('Test message', 'test.zen', 10, 5, 'COMPILER_ERROR', 'TEST_CONTEXT', ['Hint 1', 'Hint 2']);
8
+ console.assert(error.message.includes('Test message'), 'Message should be preserved');
9
+ console.assert(error.file === 'test.zen', 'File should be preserved');
10
+ console.assert(error.line === 10, 'Line should be preserved');
11
+ console.assert(error.column === 5, 'Column should be preserved');
12
+ console.assert(error.context === 'TEST_CONTEXT', 'Context should be preserved');
13
+ console.assert(error.hints.length === 2, 'Hints should be preserved');
14
+ console.assert(error.hints[0] === 'Hint 1', 'Hint 1 should match');
15
+ console.log('✅ CompilerError structure test passed');
16
+ }
17
+ function testInvariantErrorStructure() {
18
+ console.log('Testing InvariantError structure...');
19
+ const error = new InvariantError('INV001', 'Invariant failed', 'Always be true', 'test.zen', 20, 15, 'INVARIANT_CONTEXT', ['Fix hint']);
20
+ console.assert(error.code === 'INV001', 'Code should be preserved');
21
+ console.assert(error.guarantee === 'Always be true', 'Guarantee should be preserved');
22
+ console.assert(error.errorType === 'InvariantViolation', 'Default errorType should be InvariantViolation');
23
+ console.assert(error.context === 'INVARIANT_CONTEXT', 'Context should be preserved');
24
+ console.assert(error.hints[0] === 'Fix hint', 'Hints should be preserved');
25
+ console.log('✅ InvariantError structure test passed');
26
+ }
27
+ // Run tests
28
+ if (import.meta.main) {
29
+ try {
30
+ testErrorStructure();
31
+ testInvariantErrorStructure();
32
+ console.log('✅ All Error System unit tests passed!');
33
+ }
34
+ catch (e) {
35
+ console.error('❌ Tests failed:', e);
36
+ process.exit(1);
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { describe, it, expect } from 'bun:test';
2
+ import { compile } from '../index';
3
+ import * as Compiler from '../index';
4
+ /**
5
+ * Phase 5: Boundary & Integration Lockdown
6
+ *
7
+ * These tests ensure that the Zenith Compiler enforces strict boundaries:
8
+ * 1. The CLI acts as a thin transport.
9
+ * 2. The Internal API is locked down (only specific exports).
10
+ * 3. Legacy paths are removed.
11
+ */
12
+ describe('Phase 5: Boundary Contracts', () => {
13
+ it('Should expose only the allowed API surface', () => {
14
+ const exportedKeys = Object.keys(Compiler);
15
+ // Allowed public exports (Hardened Surface)
16
+ const allowed = [
17
+ 'compile',
18
+ 'parseZenFile',
19
+ // Types are allowed (and don't show up in Object.keys except in some environments, but we list them if they do)
20
+ 'FinalizedOutput',
21
+ 'CompiledTemplate'
22
+ ];
23
+ // Ensure everything exported is in the allowed list
24
+ exportedKeys.forEach(key => {
25
+ expect(allowed).toContain(key);
26
+ });
27
+ // Ensure important ones are present
28
+ expect(Compiler.compile).toBeDefined();
29
+ });
30
+ it('Should compile a simple file without side effects (Purity Check)', async () => {
31
+ const source = `
32
+ <script>
33
+ state count = 0;
34
+ </script>
35
+ <button on:click={() => count++}>{count}</button>
36
+ `;
37
+ const result = await compile(source, 'integrity-check.zen', {});
38
+ expect(result.finalized).toBeDefined();
39
+ // Ensure no "patching" logic in pure compile result
40
+ // (If there was patching in CLI, it's not here)
41
+ });
42
+ // Verify Legacy Paths are Gone
43
+ it('Should NOT expose compileZenSource (Legacy)', () => {
44
+ // @ts-ignore
45
+ expect(Compiler.compileZenSource).toBeUndefined();
46
+ });
47
+ it('Should NOT expose old build modes', () => {
48
+ // @ts-ignore
49
+ expect(Compiler.buildSPA).toBeUndefined();
50
+ });
51
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Layout Processor - wraps page content with layout HTML
3
+ *
4
+ * This module provides TypeScript-based layout processing by replacing
5
+ * the default slot in a layout with the page content.
6
+ */
7
+ export interface LayoutDefinition {
8
+ name: string;
9
+ filePath: string;
10
+ html: string;
11
+ props?: string[];
12
+ styles?: string[];
13
+ scripts?: string[];
14
+ }
15
+ /**
16
+ * Process layout wrapping for a Zenith source file.
17
+ *
18
+ * Takes page source content and wraps it with the layout HTML,
19
+ * replacing the <slot /> placeholder with the page content.
20
+ *
21
+ * @param source - The source content of the page
22
+ * @param layout - The layout definition
23
+ * @param _props - Optional props (reserved for future use)
24
+ * @returns Processed source with layout applied
25
+ */
26
+ export declare function processLayout(source: string, layout: LayoutDefinition | string, _props?: Record<string, any>): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Layout Processor - wraps page content with layout HTML
3
+ *
4
+ * This module provides TypeScript-based layout processing by replacing
5
+ * the default slot in a layout with the page content.
6
+ */
7
+ /**
8
+ * Process layout wrapping for a Zenith source file.
9
+ *
10
+ * Takes page source content and wraps it with the layout HTML,
11
+ * replacing the <slot /> placeholder with the page content.
12
+ *
13
+ * @param source - The source content of the page
14
+ * @param layout - The layout definition
15
+ * @param _props - Optional props (reserved for future use)
16
+ * @returns Processed source with layout applied
17
+ */
18
+ export function processLayout(source, layout, _props) {
19
+ // If layout is a string path, return source unchanged (caller should resolve)
20
+ if (typeof layout === 'string') {
21
+ return source;
22
+ }
23
+ // Extract template portion from page source (content between close of <script> and open of <style> or end)
24
+ // For now, pass through - the native compiler handles layout via parseFullZenNative options
25
+ const layoutHtml = layout.html;
26
+ // Replace default slot with page content
27
+ // The slot syntax in Zenith is <slot /> or <slot></slot>
28
+ const slotPattern = /<slot\s*\/?>/gi;
29
+ if (slotPattern.test(layoutHtml)) {
30
+ return layoutHtml.replace(slotPattern, source);
31
+ }
32
+ // If no slot found, append page content
33
+ return layoutHtml + '\n' + source;
34
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Invariant Validation
3
+ *
4
+ * NATIVE BRIDGE: All validation logic exists in Rust (`native/compiler-native/src/validate.rs`).
5
+ * The NAPI function `validateIr(irJson)` is the sole semantic authority.
6
+ */
7
+ import type { ZenIR } from '../ir/types';
8
+ /**
9
+ * Native bridge for IR validation
10
+ */
11
+ export declare function validateIr(ir: ZenIR): void;
12
+ export declare const INVARIANT: {
13
+ readonly LOOP_CONTEXT_LOST: "INV001";
14
+ readonly ATTRIBUTE_NOT_FORWARDED: "INV002";
15
+ readonly UNRESOLVED_COMPONENT: "INV003";
16
+ readonly REACTIVE_BOUNDARY: "INV004";
17
+ readonly TEMPLATE_TAG: "INV005";
18
+ readonly SLOT_ATTRIBUTE: "INV006";
19
+ readonly ORPHAN_COMPOUND: "INV007";
20
+ readonly NON_ENUMERABLE_JSX: "INV008";
21
+ readonly UNREGISTERED_EXPRESSION: "INV009";
22
+ readonly COMPONENT_PRECOMPILED: "INV010";
23
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Invariant Validation
3
+ *
4
+ * NATIVE BRIDGE: All validation logic exists in Rust (`native/compiler-native/src/validate.rs`).
5
+ * The NAPI function `validateIr(irJson)` is the sole semantic authority.
6
+ */
7
+ import { InvariantError } 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
+ * Native bridge for IR validation
22
+ */
23
+ export function validateIr(ir) {
24
+ if (native && native.validateIr) {
25
+ const validationIR = {
26
+ filePath: ir.filePath,
27
+ template: {
28
+ raw: ir.template.raw,
29
+ nodes: ir.template.nodes,
30
+ expressions: ir.template.expressions,
31
+ },
32
+ styles: ir.styles,
33
+ script: ir.script,
34
+ };
35
+ const error = native.validateIr(JSON.stringify(validationIR));
36
+ if (error) {
37
+ throw new InvariantError(error.code, error.message, error.guarantee, error.file, error.line, error.column, error.context, error.hints);
38
+ }
39
+ }
40
+ else {
41
+ throw new Error('[Zenith Native] Validation bridge unavailable');
42
+ }
43
+ }
44
+ export const INVARIANT = {
45
+ LOOP_CONTEXT_LOST: 'INV001',
46
+ ATTRIBUTE_NOT_FORWARDED: 'INV002',
47
+ UNRESOLVED_COMPONENT: 'INV003',
48
+ REACTIVE_BOUNDARY: 'INV004',
49
+ TEMPLATE_TAG: 'INV005',
50
+ SLOT_ATTRIBUTE: 'INV006',
51
+ ORPHAN_COMPOUND: 'INV007',
52
+ NON_ENUMERABLE_JSX: 'INV008',
53
+ UNREGISTERED_EXPRESSION: 'INV009',
54
+ COMPONENT_PRECOMPILED: 'INV010',
55
+ };
@@ -20,25 +20,7 @@ export interface ScriptImport {
20
20
  typeOnly: boolean
21
21
  sideEffect: boolean
22
22
  }
23
- export declare function generateRuntimeCode(inputJson: string): RuntimeCode
24
23
  export declare function generateCodegenIntent(): string
25
- export declare function resolveComponentsNative(irJson: string, componentsJson: string): string
26
- /** Discover all components in a directory */
27
- export declare function discoverComponentsNative(baseDir: string): any
28
- export declare function extractStylesNative(source: string): Array<string>
29
- export declare function extractPageBindingsNative(script: string): Array<string>
30
- export declare function extractPagePropsNative(script: string): Array<string>
31
- export interface VirtualModule {
32
- id: string
33
- code: string
34
- }
35
- export interface BundlePlan {
36
- entry: string
37
- platform: string
38
- format: string
39
- resolveRoots: Array<string>
40
- virtualModules: Array<VirtualModule>
41
- }
42
24
  /**
43
25
  * Manifest export for the bundler's capability-based chunking.
44
26
  * This is the Compiler → Bundler handshake contract.
@@ -60,6 +42,8 @@ export interface ZenManifestExport {
60
42
  requiredCapabilities: Array<string>
61
43
  /** Compiled script content (author code) */
62
44
  script: string
45
+ /** Full hydrated bundle */
46
+ bundle: string
63
47
  /** Compiled expressions */
64
48
  expressions: string
65
49
  /** Compiled styles */
@@ -74,10 +58,6 @@ export interface FinalizedOutput {
74
58
  /** Manifest for bundler's capability-based chunking */
75
59
  manifest?: ZenManifestExport
76
60
  }
77
- export declare function finalizeOutputNative(irJson: any, compiledJson: any): FinalizedOutput
78
- export declare function parseTemplateNative(html: string, filePath: string): any
79
- export declare function parseScriptNative(html: string): any | null
80
- export declare function isComponentTagNative(tagName: string): boolean
81
61
  /**
82
62
  * Full Zenith compilation entry point - the "One True Syscall"
83
63
  *
@@ -92,29 +72,6 @@ export interface ParseFullOptions {
92
72
  props?: any
93
73
  }
94
74
  export declare function parseFullZenNative(source: string, filePath: string, optionsJson: string): any
95
- export interface ExpressionAnalysisResult {
96
- id: string
97
- classification: string
98
- dependencies: Array<string>
99
- usesState: boolean
100
- usesLoopContext: boolean
101
- }
102
- export interface EvaluatedExpression {
103
- id: string
104
- expressionType: string
105
- dependencies: Array<string>
106
- usesState: boolean
107
- usesLoopContext: boolean
108
- classificationJson: string
109
- }
110
- export interface AnalysisOutput {
111
- results: Array<ExpressionAnalysisResult>
112
- bindingCount: number
113
- }
114
- export declare function lowerFragmentsNative(nodesJson: string, expressionsJson: string, filePath: string): string
115
- export declare function evaluateExpressionNative(id: string, code: string, knownBindingsJson: string, loopContextJson?: string | undefined | null): EvaluatedExpression
116
- export declare function classifyExpressionNative(code: string): string
117
- export declare function analyzeExpressions(inputJson: string): AnalysisOutput
118
75
  export interface Binding {
119
76
  id: string
120
77
  type: string
@@ -147,6 +104,5 @@ export interface LoopContext {
147
104
  variables: Array<string>
148
105
  mapSource?: string
149
106
  }
150
- export declare function validateIr(irJson: string): CompilerError | null
151
107
  export declare function compileBridge(): string
152
108
  export declare class ResolutionContext { }
@@ -310,25 +310,10 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { generateRuntimeCode, generateCodegenIntent, ResolutionContext, resolveComponentsNative, discoverComponentsNative, extractStylesNative, extractPageBindingsNative, extractPagePropsNative, finalizeOutputNative, parseTemplateNative, parseScriptNative, isComponentTagNative, parseFullZenNative, lowerFragmentsNative, evaluateExpressionNative, classifyExpressionNative, analyzeExpressions, transformTemplateNative, validateIr, compileBridge } = nativeBinding
313
+ const { generateCodegenIntent, ResolutionContext, parseFullZenNative, transformTemplateNative, compileBridge } = nativeBinding
314
314
 
315
- module.exports.generateRuntimeCode = generateRuntimeCode
316
315
  module.exports.generateCodegenIntent = generateCodegenIntent
317
316
  module.exports.ResolutionContext = ResolutionContext
318
- module.exports.resolveComponentsNative = resolveComponentsNative
319
- module.exports.discoverComponentsNative = discoverComponentsNative
320
- module.exports.extractStylesNative = extractStylesNative
321
- module.exports.extractPageBindingsNative = extractPageBindingsNative
322
- module.exports.extractPagePropsNative = extractPagePropsNative
323
- module.exports.finalizeOutputNative = finalizeOutputNative
324
- module.exports.parseTemplateNative = parseTemplateNative
325
- module.exports.parseScriptNative = parseScriptNative
326
- module.exports.isComponentTagNative = isComponentTagNative
327
317
  module.exports.parseFullZenNative = parseFullZenNative
328
- module.exports.lowerFragmentsNative = lowerFragmentsNative
329
- module.exports.evaluateExpressionNative = evaluateExpressionNative
330
- module.exports.classifyExpressionNative = classifyExpressionNative
331
- module.exports.analyzeExpressions = analyzeExpressions
332
318
  module.exports.transformTemplateNative = transformTemplateNative
333
- module.exports.validateIr = validateIr
334
319
  module.exports.compileBridge = compileBridge
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenithbuild/compiler-native",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@zenithbuild/compiler",
3
- "version": "1.3.2",
3
+ "version": "1.3.9",
4
4
  "description": "The Iron Heart: Native Compiler for the Zenith Framework",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": "./dist/index.js",
9
- "./config": "./dist/core/config/index.js",
10
- "./plugins": "./dist/core/plugins/index.js",
11
- "./runtime": "./dist/runtime/index.js"
9
+ "./config": "./dist/core/config/loader.js",
10
+ "./plugins": "./dist/core/plugins/bridge.js",
11
+ "./registry": "./dist/core/plugins/registry.js",
12
+ "./runtime": "./dist/runtime/bundle-generator.js",
13
+ "./discovery": "./dist/discovery/componentDiscovery.js",
14
+ "./layouts": "./dist/discovery/layouts.js",
15
+ "./transform": "./dist/transform/layoutProcessor.js",
16
+ "./css": "./dist/css/index.js",
17
+ "./bundler": "./dist/bundler/index.js"
12
18
  },
13
19
  "files": [
14
20
  "dist",
@@ -21,7 +27,7 @@
21
27
  "access": "public"
22
28
  },
23
29
  "scripts": {
24
- "build": "tsc --skipLibCheck && cd native/compiler-native && bun run build",
30
+ "build": "tsc --skipLibCheck && cd native/compiler-native && bun run build && cp compiler-native.node compiler-native.darwin-arm64.node 2>/dev/null || true",
25
31
  "test": "bun test"
26
32
  },
27
33
  "dependencies": {
@@ -37,7 +43,11 @@
37
43
  "prompts": "^2.4.2",
38
44
  "glob": "^10.3.10"
39
45
  },
46
+ "peerDependencies": {
47
+ "@zenithbuild/runtime": "^0.1.0"
48
+ },
40
49
  "devDependencies": {
50
+ "@zenithbuild/runtime": "workspace:*",
41
51
  "@types/node": "^20.11.0",
42
52
  "@types/acorn": "^6.0.4",
43
53
  "@types/marked": "^6.0.0",