@zenithbuild/compiler 1.0.16 → 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.
- package/native/compiler-native/compiler-native.node +0 -0
- package/native/compiler-native/index.d.ts +46 -7
- package/native/compiler-native/index.js +332 -17
- package/package.json +1 -1
- package/dist/build-analyzer.d.ts +0 -44
- package/dist/build-analyzer.js +0 -87
- package/dist/bundler.d.ts +0 -31
- package/dist/bundler.js +0 -86
- package/dist/compiler-native-ep39xj7a.node +0 -0
- package/dist/compiler-native-ftk9z446.node +0 -0
- package/dist/core/components/index.d.ts +0 -9
- package/dist/core/components/index.js +0 -13
- package/dist/core/config/index.d.ts +0 -11
- package/dist/core/config/index.js +0 -10
- package/dist/core/config/loader.d.ts +0 -17
- package/dist/core/config/loader.js +0 -60
- package/dist/core/config/types.d.ts +0 -98
- package/dist/core/config/types.js +0 -32
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.js +0 -6
- package/dist/core/lifecycle/index.d.ts +0 -16
- package/dist/core/lifecycle/index.js +0 -19
- package/dist/core/lifecycle/zen-mount.d.ts +0 -66
- package/dist/core/lifecycle/zen-mount.js +0 -151
- package/dist/core/lifecycle/zen-unmount.d.ts +0 -54
- package/dist/core/lifecycle/zen-unmount.js +0 -76
- package/dist/core/plugins/bridge.d.ts +0 -116
- package/dist/core/plugins/bridge.js +0 -121
- package/dist/core/plugins/index.d.ts +0 -6
- package/dist/core/plugins/index.js +0 -6
- package/dist/core/plugins/registry.d.ts +0 -67
- package/dist/core/plugins/registry.js +0 -112
- package/dist/core/reactivity/index.d.ts +0 -30
- package/dist/core/reactivity/index.js +0 -33
- package/dist/core/reactivity/tracking.d.ts +0 -74
- package/dist/core/reactivity/tracking.js +0 -136
- package/dist/core/reactivity/zen-batch.d.ts +0 -45
- package/dist/core/reactivity/zen-batch.js +0 -54
- package/dist/core/reactivity/zen-effect.d.ts +0 -48
- package/dist/core/reactivity/zen-effect.js +0 -98
- package/dist/core/reactivity/zen-memo.d.ts +0 -43
- package/dist/core/reactivity/zen-memo.js +0 -100
- package/dist/core/reactivity/zen-ref.d.ts +0 -44
- package/dist/core/reactivity/zen-ref.js +0 -34
- package/dist/core/reactivity/zen-signal.d.ts +0 -48
- package/dist/core/reactivity/zen-signal.js +0 -84
- package/dist/core/reactivity/zen-state.d.ts +0 -35
- package/dist/core/reactivity/zen-state.js +0 -147
- package/dist/core/reactivity/zen-untrack.d.ts +0 -38
- package/dist/core/reactivity/zen-untrack.js +0 -41
- package/dist/css/index.d.ts +0 -73
- package/dist/css/index.js +0 -246
- package/dist/discovery/componentDiscovery.d.ts +0 -42
- package/dist/discovery/componentDiscovery.js +0 -56
- package/dist/discovery/layouts.d.ts +0 -13
- package/dist/discovery/layouts.js +0 -41
- package/dist/errors/compilerError.d.ts +0 -31
- package/dist/errors/compilerError.js +0 -51
- package/dist/finalize/finalizeOutput.d.ts +0 -32
- package/dist/finalize/finalizeOutput.js +0 -62
- package/dist/finalize/generateFinalBundle.d.ts +0 -24
- package/dist/finalize/generateFinalBundle.js +0 -68
- package/dist/index.d.ts +0 -38
- package/dist/index.js +0 -57
- package/dist/ir/types.d.ts +0 -181
- package/dist/ir/types.js +0 -8
- package/dist/output/types.d.ts +0 -30
- package/dist/output/types.js +0 -6
- package/dist/parse/detectMapExpressions.d.ts +0 -45
- package/dist/parse/detectMapExpressions.js +0 -77
- package/dist/parse/parseScript.d.ts +0 -8
- package/dist/parse/parseScript.js +0 -36
- package/dist/parse/parseTemplate.d.ts +0 -11
- package/dist/parse/parseTemplate.js +0 -487
- package/dist/parse/parseZenFile.d.ts +0 -11
- package/dist/parse/parseZenFile.js +0 -50
- package/dist/parse/scriptAnalysis.d.ts +0 -25
- package/dist/parse/scriptAnalysis.js +0 -60
- package/dist/parse/trackLoopContext.d.ts +0 -20
- package/dist/parse/trackLoopContext.js +0 -62
- package/dist/parseZenFile.d.ts +0 -10
- package/dist/parseZenFile.js +0 -55
- package/dist/runtime/analyzeAndEmit.d.ts +0 -20
- package/dist/runtime/analyzeAndEmit.js +0 -70
- package/dist/runtime/build.d.ts +0 -6
- package/dist/runtime/build.js +0 -13
- package/dist/runtime/bundle-generator.d.ts +0 -27
- package/dist/runtime/bundle-generator.js +0 -1438
- package/dist/runtime/client-runtime.d.ts +0 -41
- package/dist/runtime/client-runtime.js +0 -397
- package/dist/runtime/dataExposure.d.ts +0 -52
- package/dist/runtime/dataExposure.js +0 -227
- package/dist/runtime/generateDOM.d.ts +0 -21
- package/dist/runtime/generateDOM.js +0 -194
- package/dist/runtime/generateHydrationBundle.d.ts +0 -15
- package/dist/runtime/generateHydrationBundle.js +0 -399
- package/dist/runtime/hydration.d.ts +0 -53
- package/dist/runtime/hydration.js +0 -271
- package/dist/runtime/navigation.d.ts +0 -58
- package/dist/runtime/navigation.js +0 -372
- package/dist/runtime/serve.d.ts +0 -13
- package/dist/runtime/serve.js +0 -76
- package/dist/runtime/thinRuntime.d.ts +0 -23
- package/dist/runtime/thinRuntime.js +0 -158
- package/dist/runtime/transformIR.d.ts +0 -19
- package/dist/runtime/transformIR.js +0 -285
- package/dist/runtime/wrapExpression.d.ts +0 -24
- package/dist/runtime/wrapExpression.js +0 -76
- package/dist/runtime/wrapExpressionWithLoop.d.ts +0 -17
- package/dist/runtime/wrapExpressionWithLoop.js +0 -75
- package/dist/spa-build.d.ts +0 -26
- package/dist/spa-build.js +0 -857
- package/dist/ssg-build.d.ts +0 -32
- package/dist/ssg-build.js +0 -408
- package/dist/test/analyze-emit.test.d.ts +0 -1
- package/dist/test/analyze-emit.test.js +0 -88
- package/dist/test/bundler-contract.test.d.ts +0 -1
- package/dist/test/bundler-contract.test.js +0 -137
- package/dist/test/compiler-authority.test.d.ts +0 -1
- package/dist/test/compiler-authority.test.js +0 -90
- package/dist/test/component-instance-test.d.ts +0 -1
- package/dist/test/component-instance-test.js +0 -115
- package/dist/test/error-native-bridge.test.d.ts +0 -1
- package/dist/test/error-native-bridge.test.js +0 -51
- package/dist/test/error-serialization.test.d.ts +0 -1
- package/dist/test/error-serialization.test.js +0 -38
- package/dist/test/macro-inlining.test.d.ts +0 -1
- package/dist/test/macro-inlining.test.js +0 -178
- package/dist/test/validate-test.d.ts +0 -6
- package/dist/test/validate-test.js +0 -95
- package/dist/transform/classifyExpression.d.ts +0 -46
- package/dist/transform/classifyExpression.js +0 -359
- package/dist/transform/componentResolver.d.ts +0 -15
- package/dist/transform/componentResolver.js +0 -24
- package/dist/transform/expressionTransformer.d.ts +0 -19
- package/dist/transform/expressionTransformer.js +0 -333
- package/dist/transform/fragmentLowering.d.ts +0 -25
- package/dist/transform/fragmentLowering.js +0 -468
- package/dist/transform/layoutProcessor.d.ts +0 -5
- package/dist/transform/layoutProcessor.js +0 -34
- package/dist/transform/transformTemplate.d.ts +0 -11
- package/dist/transform/transformTemplate.js +0 -33
- package/dist/validate/invariants.d.ts +0 -23
- package/dist/validate/invariants.js +0 -55
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component Discovery
|
|
3
|
-
*
|
|
4
|
-
* Discovers and catalogs components in a Zenith project
|
|
5
|
-
* Similar to layout discovery but for reusable components
|
|
6
|
-
*/
|
|
7
|
-
import type { TemplateNode, ExpressionIR } from '../ir/types';
|
|
8
|
-
export interface SlotDefinition {
|
|
9
|
-
name: string | null;
|
|
10
|
-
location: {
|
|
11
|
-
line: number;
|
|
12
|
-
column: number;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export interface ComponentMetadata {
|
|
16
|
-
name: string;
|
|
17
|
-
path: string;
|
|
18
|
-
template: string;
|
|
19
|
-
nodes: TemplateNode[];
|
|
20
|
-
expressions: ExpressionIR[];
|
|
21
|
-
slots: SlotDefinition[];
|
|
22
|
-
props: string[];
|
|
23
|
-
styles: string[];
|
|
24
|
-
script: string | null;
|
|
25
|
-
scriptAttributes: Record<string, string> | null;
|
|
26
|
-
hasScript: boolean;
|
|
27
|
-
hasStyles: boolean;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Discover all components in a directory
|
|
31
|
-
* @param baseDir - Base directory to search (e.g., src/components)
|
|
32
|
-
* @returns Map of component name to metadata
|
|
33
|
-
*/
|
|
34
|
-
export declare function discoverComponents(baseDir: string): Map<string, ComponentMetadata>;
|
|
35
|
-
/**
|
|
36
|
-
* Use native bridge for tag name checks
|
|
37
|
-
*/
|
|
38
|
-
export declare function isComponentTag(tagName: string): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Get component metadata by name
|
|
41
|
-
*/
|
|
42
|
-
export declare function getComponent(components: Map<string, ComponentMetadata>, name: string): ComponentMetadata | undefined;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component Discovery
|
|
3
|
-
*
|
|
4
|
-
* Discovers and catalogs components in a Zenith project
|
|
5
|
-
* Similar to layout discovery but for reusable components
|
|
6
|
-
*/
|
|
7
|
-
let native;
|
|
8
|
-
try {
|
|
9
|
-
try {
|
|
10
|
-
native = require('../../native/compiler-native');
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
native = require('../../native/compiler-native/index.js');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
// Bridge load handled elsewhere
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Discover all components in a directory
|
|
21
|
-
* @param baseDir - Base directory to search (e.g., src/components)
|
|
22
|
-
* @returns Map of component name to metadata
|
|
23
|
-
*/
|
|
24
|
-
export function discoverComponents(baseDir) {
|
|
25
|
-
if (native && native.discoverComponentsNative) {
|
|
26
|
-
try {
|
|
27
|
-
const raw = native.discoverComponentsNative(baseDir);
|
|
28
|
-
// The native function returns a Map-like object or Record
|
|
29
|
-
const components = new Map();
|
|
30
|
-
for (const [name, metadata] of Object.entries(raw)) {
|
|
31
|
-
components.set(name, metadata);
|
|
32
|
-
}
|
|
33
|
-
return components;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.warn(`[Zenith Native] Discovery failed for ${baseDir}: ${error.message}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Fallback or empty if native fails (bridge is required for performance)
|
|
40
|
-
return new Map();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Use native bridge for tag name checks
|
|
44
|
-
*/
|
|
45
|
-
export function isComponentTag(tagName) {
|
|
46
|
-
if (native && native.isComponentTagNative) {
|
|
47
|
-
return native.isComponentTagNative(tagName);
|
|
48
|
-
}
|
|
49
|
-
return tagName.length > 0 && tagName[0] === tagName[0]?.toUpperCase();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Get component metadata by name
|
|
53
|
-
*/
|
|
54
|
-
export function getComponent(components, name) {
|
|
55
|
-
return components.get(name);
|
|
56
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface LayoutMetadata {
|
|
2
|
-
name: string;
|
|
3
|
-
filePath: string;
|
|
4
|
-
props: string[];
|
|
5
|
-
states: Map<string, string>;
|
|
6
|
-
html: string;
|
|
7
|
-
scripts: string[];
|
|
8
|
-
styles: string[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Discover layouts in a directory
|
|
12
|
-
*/
|
|
13
|
-
export declare function discoverLayouts(layoutsDir: string): Map<string, LayoutMetadata>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
let native;
|
|
2
|
-
try {
|
|
3
|
-
try {
|
|
4
|
-
native = require('../../native/compiler-native');
|
|
5
|
-
}
|
|
6
|
-
catch {
|
|
7
|
-
native = require('../../native/compiler-native/index.js');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
// Bridge load handled elsewhere
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Discover layouts in a directory
|
|
15
|
-
*/
|
|
16
|
-
export function discoverLayouts(layoutsDir) {
|
|
17
|
-
if (native && native.discoverLayoutsNative) {
|
|
18
|
-
try {
|
|
19
|
-
const raw = native.discoverLayoutsNative(layoutsDir);
|
|
20
|
-
const layouts = new Map();
|
|
21
|
-
for (const [name, metadata] of Object.entries(raw)) {
|
|
22
|
-
// Adjust for Rust's camelCase vs Map mapping if needed
|
|
23
|
-
const meta = metadata;
|
|
24
|
-
layouts.set(name, {
|
|
25
|
-
name: meta.name,
|
|
26
|
-
filePath: meta.filePath,
|
|
27
|
-
props: meta.props,
|
|
28
|
-
states: new Map(Object.entries(meta.states || {})),
|
|
29
|
-
html: meta.html,
|
|
30
|
-
scripts: meta.scripts,
|
|
31
|
-
styles: meta.styles
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return layouts;
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
console.warn(`[Zenith Native] Layout discovery failed for ${layoutsDir}: ${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return new Map();
|
|
41
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compiler Error Handling
|
|
3
|
-
*
|
|
4
|
-
* Compiler errors with source location information
|
|
5
|
-
*/
|
|
6
|
-
export declare class CompilerError extends Error {
|
|
7
|
-
file: string;
|
|
8
|
-
line: number;
|
|
9
|
-
column: number;
|
|
10
|
-
errorType: string;
|
|
11
|
-
context?: string;
|
|
12
|
-
hints: string[];
|
|
13
|
-
code?: string;
|
|
14
|
-
constructor(message: string, file: string, line: number, column: number, errorType?: string, context?: string, hints?: string[], code?: string);
|
|
15
|
-
toString(): string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Invariant Error
|
|
19
|
-
*
|
|
20
|
-
* Thrown when a Zenith compiler invariant is violated.
|
|
21
|
-
* Invariants are non-negotiable rules that guarantee correct behavior.
|
|
22
|
-
*
|
|
23
|
-
* If an invariant fails, the compiler is at fault — not the user.
|
|
24
|
-
* The user receives a clear explanation of what is forbidden and why.
|
|
25
|
-
*/
|
|
26
|
-
export declare class InvariantError extends CompilerError {
|
|
27
|
-
invariantId: string;
|
|
28
|
-
guarantee: string;
|
|
29
|
-
constructor(invariantId: string, message: string, guarantee: string, file: string, line: number, column: number, context?: string, hints?: string[]);
|
|
30
|
-
toString(): string;
|
|
31
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compiler Error Handling
|
|
3
|
-
*
|
|
4
|
-
* Compiler errors with source location information
|
|
5
|
-
*/
|
|
6
|
-
export class CompilerError extends Error {
|
|
7
|
-
file;
|
|
8
|
-
line;
|
|
9
|
-
column;
|
|
10
|
-
errorType;
|
|
11
|
-
context;
|
|
12
|
-
hints;
|
|
13
|
-
code;
|
|
14
|
-
constructor(message, file, line, column, errorType = 'COMPILER_ERROR', context, hints = [], code) {
|
|
15
|
-
super(`${file}:${line}:${column} ${message}`);
|
|
16
|
-
this.name = 'CompilerError';
|
|
17
|
-
this.file = file;
|
|
18
|
-
this.line = line;
|
|
19
|
-
this.column = column;
|
|
20
|
-
this.errorType = errorType;
|
|
21
|
-
this.context = context;
|
|
22
|
-
this.hints = hints;
|
|
23
|
-
this.code = code;
|
|
24
|
-
}
|
|
25
|
-
toString() {
|
|
26
|
-
return `${this.file}:${this.line}:${this.column} [${this.errorType}] ${this.message}`;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Invariant Error
|
|
31
|
-
*
|
|
32
|
-
* Thrown when a Zenith compiler invariant is violated.
|
|
33
|
-
* Invariants are non-negotiable rules that guarantee correct behavior.
|
|
34
|
-
*
|
|
35
|
-
* If an invariant fails, the compiler is at fault — not the user.
|
|
36
|
-
* The user receives a clear explanation of what is forbidden and why.
|
|
37
|
-
*/
|
|
38
|
-
export class InvariantError extends CompilerError {
|
|
39
|
-
invariantId;
|
|
40
|
-
guarantee;
|
|
41
|
-
constructor(invariantId, message, guarantee, file, line, column, context, hints = []) {
|
|
42
|
-
super(`[${invariantId}] ${message}\n\n Zenith Guarantee: ${guarantee}`, file, line, column, 'COMPILER_INVARIANT_VIOLATION', context, hints, invariantId);
|
|
43
|
-
this.name = 'InvariantError';
|
|
44
|
-
this.invariantId = invariantId;
|
|
45
|
-
this.guarantee = guarantee;
|
|
46
|
-
this.code = invariantId;
|
|
47
|
-
}
|
|
48
|
-
toString() {
|
|
49
|
-
return `${this.file}:${this.line}:${this.column} [${this.invariantId}] ${this.message}`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finalize Output
|
|
3
|
-
*
|
|
4
|
-
* NATIVE BRIDGE: Delegates ALL finalization (Phase 8/9/10) to Rust (`native/compiler-native/src/finalize.rs`).
|
|
5
|
-
*/
|
|
6
|
-
import type { CompiledTemplate } from '../output/types';
|
|
7
|
-
import type { ZenIR, BundlePlan } from '../ir/types';
|
|
8
|
-
/**
|
|
9
|
-
* Finalized output ready for browser
|
|
10
|
-
*/
|
|
11
|
-
export interface FinalizedOutput {
|
|
12
|
-
html: string;
|
|
13
|
-
js: string;
|
|
14
|
-
npmImports: string;
|
|
15
|
-
styles: string[];
|
|
16
|
-
hasErrors: boolean;
|
|
17
|
-
errors: string[];
|
|
18
|
-
/** Compiler-emitted bundling plan. If present, bundling MUST occur. If absent, bundling MUST NOT occur. */
|
|
19
|
-
bundlePlan?: BundlePlan;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Finalize compiler output (Native Bridge)
|
|
23
|
-
*
|
|
24
|
-
* @param ir - Intermediate representation
|
|
25
|
-
* @param compiled - Compiled template
|
|
26
|
-
* @returns Finalized output
|
|
27
|
-
*/
|
|
28
|
-
export declare function finalizeOutput(ir: ZenIR, compiled: CompiledTemplate): Promise<FinalizedOutput>;
|
|
29
|
-
/**
|
|
30
|
-
* Generate final output with error handling
|
|
31
|
-
*/
|
|
32
|
-
export declare function finalizeOutputOrThrow(ir: ZenIR, compiled: CompiledTemplate): Promise<FinalizedOutput>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finalize Output
|
|
3
|
-
*
|
|
4
|
-
* NATIVE BRIDGE: Delegates ALL finalization (Phase 8/9/10) to Rust (`native/compiler-native/src/finalize.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
|
-
* Finalize compiler output (Native Bridge)
|
|
20
|
-
*
|
|
21
|
-
* @param ir - Intermediate representation
|
|
22
|
-
* @param compiled - Compiled template
|
|
23
|
-
* @returns Finalized output
|
|
24
|
-
*/
|
|
25
|
-
export async function finalizeOutput(ir, compiled) {
|
|
26
|
-
if (native && native.finalizeOutputNative) {
|
|
27
|
-
try {
|
|
28
|
-
const result = native.finalizeOutputNative(ir, compiled);
|
|
29
|
-
return {
|
|
30
|
-
html: result.html,
|
|
31
|
-
js: result.js,
|
|
32
|
-
npmImports: result.npmImports,
|
|
33
|
-
styles: result.styles,
|
|
34
|
-
hasErrors: result.hasErrors,
|
|
35
|
-
errors: result.errors,
|
|
36
|
-
bundlePlan: result.bundlePlan
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
return {
|
|
41
|
-
html: '',
|
|
42
|
-
js: '',
|
|
43
|
-
npmImports: '',
|
|
44
|
-
styles: [],
|
|
45
|
-
hasErrors: true,
|
|
46
|
-
errors: [`Native finalization failed: ${error.message}`]
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`[Zenith Native] Finalize bridge unavailable - cannot finalize ${ir.filePath}`);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Generate final output with error handling
|
|
54
|
-
*/
|
|
55
|
-
export async function finalizeOutputOrThrow(ir, compiled) {
|
|
56
|
-
const output = await finalizeOutput(ir, compiled);
|
|
57
|
-
if (output.hasErrors) {
|
|
58
|
-
const errorMessage = output.errors.join('\n\n');
|
|
59
|
-
throw new Error(`Compilation failed:\n\n${errorMessage}`);
|
|
60
|
-
}
|
|
61
|
-
return output;
|
|
62
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Final Bundle
|
|
3
|
-
*
|
|
4
|
-
* Phase 8/9/10: Generate final browser-ready bundle
|
|
5
|
-
*
|
|
6
|
-
* Combines:
|
|
7
|
-
* - Compiled HTML
|
|
8
|
-
* - Runtime JS
|
|
9
|
-
* - Expression functions
|
|
10
|
-
* - Event bindings
|
|
11
|
-
* - Style injection
|
|
12
|
-
*/
|
|
13
|
-
import type { FinalizedOutput } from './finalizeOutput';
|
|
14
|
-
/**
|
|
15
|
-
* Generate final bundle code
|
|
16
|
-
*
|
|
17
|
-
* This is the complete JavaScript bundle that will execute in the browser.
|
|
18
|
-
* All expressions are pre-compiled - no template parsing at runtime.
|
|
19
|
-
*/
|
|
20
|
-
export declare function generateFinalBundle(finalized: FinalizedOutput): string;
|
|
21
|
-
/**
|
|
22
|
-
* Generate HTML with inline script
|
|
23
|
-
*/
|
|
24
|
-
export declare function generateHTMLWithScript(html: string, jsBundle: string, styles: string[]): string;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Final Bundle
|
|
3
|
-
*
|
|
4
|
-
* Phase 8/9/10: Generate final browser-ready bundle
|
|
5
|
-
*
|
|
6
|
-
* Combines:
|
|
7
|
-
* - Compiled HTML
|
|
8
|
-
* - Runtime JS
|
|
9
|
-
* - Expression functions
|
|
10
|
-
* - Event bindings
|
|
11
|
-
* - Style injection
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Generate final bundle code
|
|
15
|
-
*
|
|
16
|
-
* This is the complete JavaScript bundle that will execute in the browser.
|
|
17
|
-
* All expressions are pre-compiled - no template parsing at runtime.
|
|
18
|
-
*/
|
|
19
|
-
export function generateFinalBundle(finalized) {
|
|
20
|
-
return `// Zenith Compiled Bundle (Phase 8/9/10)
|
|
21
|
-
// Generated at compile time - no .zen parsing in browser
|
|
22
|
-
// All expressions are pre-compiled - deterministic output
|
|
23
|
-
|
|
24
|
-
${finalized.js}
|
|
25
|
-
|
|
26
|
-
// Bundle complete - ready for browser execution
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate HTML with inline script
|
|
31
|
-
*/
|
|
32
|
-
export function generateHTMLWithScript(html, jsBundle, styles) {
|
|
33
|
-
// Inject styles as <style> tags
|
|
34
|
-
const styleTags = styles.map(style => `<style>${escapeHTML(style)}</style>`).join('\n');
|
|
35
|
-
// Inject JS bundle as inline script
|
|
36
|
-
const scriptTag = `<script>${jsBundle}</script>`;
|
|
37
|
-
// Find </head> or <body> to inject styles
|
|
38
|
-
// Find </body> to inject script
|
|
39
|
-
let result = html;
|
|
40
|
-
if (styleTags) {
|
|
41
|
-
if (result.includes('</head>')) {
|
|
42
|
-
result = result.replace('</head>', `${styleTags}\n</head>`);
|
|
43
|
-
}
|
|
44
|
-
else if (result.includes('<body')) {
|
|
45
|
-
result = result.replace('<body', `${styleTags}\n<body`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (scriptTag) {
|
|
49
|
-
if (result.includes('</body>')) {
|
|
50
|
-
result = result.replace('</body>', `${scriptTag}\n</body>`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
result += scriptTag;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Escape HTML for safe embedding
|
|
60
|
-
*/
|
|
61
|
-
function escapeHTML(str) {
|
|
62
|
-
return str
|
|
63
|
-
.replace(/&/g, '&')
|
|
64
|
-
.replace(/</g, '<')
|
|
65
|
-
.replace(/>/g, '>')
|
|
66
|
-
.replace(/"/g, '"')
|
|
67
|
-
.replace(/'/g, ''');
|
|
68
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ZenIR } from './ir/types';
|
|
2
|
-
import type { CompiledTemplate } from './output/types';
|
|
3
|
-
import type { FinalizedOutput } from './finalize/finalizeOutput';
|
|
4
|
-
import { parseZenFile } from './parseZenFile';
|
|
5
|
-
/**
|
|
6
|
-
* Compile a .zen file into IR and CompiledTemplate
|
|
7
|
-
*/
|
|
8
|
-
export declare function compileZen(filePath: string): Promise<{
|
|
9
|
-
ir: ZenIR;
|
|
10
|
-
compiled: CompiledTemplate;
|
|
11
|
-
finalized?: FinalizedOutput;
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* Compile Zen source string into IR and CompiledTemplate
|
|
15
|
-
*/
|
|
16
|
-
export declare function compileZenSource(source: string, filePath: string, options?: {
|
|
17
|
-
componentsDir?: string;
|
|
18
|
-
components?: Map<string, any>;
|
|
19
|
-
}): Promise<{
|
|
20
|
-
ir: ZenIR;
|
|
21
|
-
compiled: CompiledTemplate;
|
|
22
|
-
finalized?: FinalizedOutput;
|
|
23
|
-
}>;
|
|
24
|
-
export { parseZenFile };
|
|
25
|
-
export { discoverComponents } from './discovery/componentDiscovery';
|
|
26
|
-
export { discoverLayouts } from './discovery/layouts';
|
|
27
|
-
export { processLayout } from './transform/layoutProcessor';
|
|
28
|
-
export { bundlePageScript } from './bundler';
|
|
29
|
-
export { buildSSG } from './ssg-build';
|
|
30
|
-
export { buildSPA } from './spa-build';
|
|
31
|
-
export { generateBundleJS } from './runtime/bundle-generator';
|
|
32
|
-
export { generateRouteDefinition } from '@zenithbuild/router/manifest';
|
|
33
|
-
export { compileCss, compileCssAsync, resolveGlobalsCss } from './css';
|
|
34
|
-
export { loadZenithConfig } from './core/config/loader';
|
|
35
|
-
export { PluginRegistry, createPluginContext, getPluginDataByNamespace } from './core/plugins/registry';
|
|
36
|
-
export { createBridgeAPI, runPluginHooks, collectHookReturns, buildRuntimeEnvelope, clearHooks } from './core/plugins/bridge';
|
|
37
|
-
export type { HookContext } from './core/plugins/bridge';
|
|
38
|
-
export type { BundlePlan, ExpressionIR, ZenIR, TemplateNode } from './ir/types';
|
package/dist/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { transformTemplate } from './transform/transformTemplate';
|
|
3
|
-
import { finalizeOutputOrThrow } from './finalize/finalizeOutput';
|
|
4
|
-
import { validateIr } from './validate/invariants';
|
|
5
|
-
import { parseZenFile } from './parseZenFile';
|
|
6
|
-
import { discoverComponents } from './discovery/componentDiscovery';
|
|
7
|
-
import { resolveComponentsInIR } from './transform/componentResolver';
|
|
8
|
-
/**
|
|
9
|
-
* Compile a .zen file into IR and CompiledTemplate
|
|
10
|
-
*/
|
|
11
|
-
export async function compileZen(filePath) {
|
|
12
|
-
const source = readFileSync(filePath, 'utf-8');
|
|
13
|
-
return compileZenSource(source, filePath);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Compile Zen source string into IR and CompiledTemplate
|
|
17
|
-
*/
|
|
18
|
-
export async function compileZenSource(source, filePath, options) {
|
|
19
|
-
// Parse with native bridge
|
|
20
|
-
let ir = parseZenFile(filePath, source);
|
|
21
|
-
// Resolve components if explicitly provided OR if components directory is set
|
|
22
|
-
if (options?.components || options?.componentsDir) {
|
|
23
|
-
let components = options.components || new Map();
|
|
24
|
-
// If directory provided, discover and merge
|
|
25
|
-
if (options.componentsDir) {
|
|
26
|
-
const discovered = discoverComponents(options.componentsDir);
|
|
27
|
-
components = new Map([...components, ...discovered]);
|
|
28
|
-
}
|
|
29
|
-
// Component resolution may throw InvariantError — let it propagate
|
|
30
|
-
ir = resolveComponentsInIR(ir, components);
|
|
31
|
-
}
|
|
32
|
-
// Validate all compiler invariants after resolution
|
|
33
|
-
// Throws InvariantError if any invariant is violated
|
|
34
|
-
validateIr(ir);
|
|
35
|
-
const compiled = transformTemplate(ir);
|
|
36
|
-
try {
|
|
37
|
-
const finalized = await finalizeOutputOrThrow(ir, compiled);
|
|
38
|
-
return { ir, compiled, finalized };
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw new Error(`Failed to finalize output for ${filePath}:\n${error.message}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export { parseZenFile };
|
|
45
|
-
// Feature exports
|
|
46
|
-
export { discoverComponents } from './discovery/componentDiscovery';
|
|
47
|
-
export { discoverLayouts } from './discovery/layouts';
|
|
48
|
-
export { processLayout } from './transform/layoutProcessor';
|
|
49
|
-
export { bundlePageScript } from './bundler';
|
|
50
|
-
export { buildSSG } from './ssg-build';
|
|
51
|
-
export { buildSPA } from './spa-build';
|
|
52
|
-
export { generateBundleJS } from './runtime/bundle-generator';
|
|
53
|
-
export { generateRouteDefinition } from '@zenithbuild/router/manifest';
|
|
54
|
-
export { compileCss, compileCssAsync, resolveGlobalsCss } from './css';
|
|
55
|
-
export { loadZenithConfig } from './core/config/loader';
|
|
56
|
-
export { PluginRegistry, createPluginContext, getPluginDataByNamespace } from './core/plugins/registry';
|
|
57
|
-
export { createBridgeAPI, runPluginHooks, collectHookReturns, buildRuntimeEnvelope, clearHooks } from './core/plugins/bridge';
|