@zeus-js/compiler-shared 0.1.0-beta.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.
@@ -0,0 +1,216 @@
1
+ /**
2
+ * compiler-shared v0.1.0-beta.9
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ Object.defineProperties(exports, {
7
+ __esModule: { value: true },
8
+ [Symbol.toStringTag]: { value: "Module" }
9
+ });
10
+ //#region packages/core/compiler-shared/src/semanticBuilders.ts
11
+ let nextId = 0;
12
+ function id() {
13
+ return nextId++;
14
+ }
15
+ function ref(name) {
16
+ return { name };
17
+ }
18
+ function expressionIR(code, span) {
19
+ return {
20
+ kind: "Expression",
21
+ code,
22
+ span
23
+ };
24
+ }
25
+ function identifierIR(name, span) {
26
+ return {
27
+ kind: "Identifier",
28
+ name,
29
+ span
30
+ };
31
+ }
32
+ function elementIR(input) {
33
+ var _input$attrs, _input$children;
34
+ return {
35
+ id: id(),
36
+ kind: "Element",
37
+ ref: input.ref,
38
+ tagName: input.tagName,
39
+ attrs: (_input$attrs = input.attrs) !== null && _input$attrs !== void 0 ? _input$attrs : [],
40
+ children: (_input$children = input.children) !== null && _input$children !== void 0 ? _input$children : [],
41
+ flags: {
42
+ isSVG: false,
43
+ isVoid: false,
44
+ isCustomElement: input.tagName.includes("-"),
45
+ ...input.flags
46
+ }
47
+ };
48
+ }
49
+ function textIR(value) {
50
+ return {
51
+ id: id(),
52
+ kind: "Text",
53
+ value
54
+ };
55
+ }
56
+ function dynamicTextIR(expr, nodeRef, once = false) {
57
+ return {
58
+ id: id(),
59
+ kind: "DynamicText",
60
+ expr,
61
+ ref: nodeRef,
62
+ once
63
+ };
64
+ }
65
+ function fragmentIR(children) {
66
+ return {
67
+ id: id(),
68
+ kind: "Fragment",
69
+ children
70
+ };
71
+ }
72
+ function staticAttrIR(name, value) {
73
+ return {
74
+ id: id(),
75
+ kind: "StaticAttribute",
76
+ name,
77
+ value
78
+ };
79
+ }
80
+ function attrBindingIR(name, expr) {
81
+ return {
82
+ id: id(),
83
+ kind: "AttrBinding",
84
+ name,
85
+ expr
86
+ };
87
+ }
88
+ function propBindingIR(name, expr) {
89
+ return {
90
+ id: id(),
91
+ kind: "PropBinding",
92
+ name,
93
+ expr
94
+ };
95
+ }
96
+ function eventBindingIR(eventName, handler) {
97
+ return {
98
+ id: id(),
99
+ kind: "EventBinding",
100
+ eventName,
101
+ handler
102
+ };
103
+ }
104
+ function refBindingIR(expr) {
105
+ return {
106
+ id: id(),
107
+ kind: "RefBinding",
108
+ expr
109
+ };
110
+ }
111
+ function componentIR(input) {
112
+ return {
113
+ id: id(),
114
+ kind: "Component",
115
+ ref: input.ref,
116
+ callee: input.callee,
117
+ props: input.props
118
+ };
119
+ }
120
+ function showIR(input) {
121
+ return {
122
+ id: id(),
123
+ kind: "Show",
124
+ ref: input.ref,
125
+ when: input.when,
126
+ children: input.children,
127
+ fallback: input.fallback
128
+ };
129
+ }
130
+ function forIR(input) {
131
+ return {
132
+ id: id(),
133
+ kind: "For",
134
+ ref: input.ref,
135
+ each: input.each,
136
+ by: input.by,
137
+ item: input.item,
138
+ index: input.index,
139
+ body: input.body
140
+ };
141
+ }
142
+ function hostIR(input) {
143
+ return {
144
+ id: id(),
145
+ kind: "Host",
146
+ attrs: input.attrs,
147
+ child: input.child
148
+ };
149
+ }
150
+ function slotIR(input) {
151
+ var _input$fallback;
152
+ return {
153
+ id: id(),
154
+ kind: "Slot",
155
+ ref: input.ref,
156
+ name: input.name,
157
+ fallback: (_input$fallback = input.fallback) !== null && _input$fallback !== void 0 ? _input$fallback : []
158
+ };
159
+ }
160
+ //#endregion
161
+ //#region packages/core/compiler-shared/src/visit.ts
162
+ function visitIR(node, visitor, parent) {
163
+ var _visitor$enter, _visitor$leave;
164
+ (_visitor$enter = visitor.enter) === null || _visitor$enter === void 0 || _visitor$enter.call(visitor, node, parent);
165
+ for (const child of getIRChildren(node)) visitIR(child, visitor, node);
166
+ (_visitor$leave = visitor.leave) === null || _visitor$leave === void 0 || _visitor$leave.call(visitor, node, parent);
167
+ }
168
+ function getIRChildren(node) {
169
+ switch (node.kind) {
170
+ case "Element":
171
+ case "Fragment": return node.children;
172
+ case "Component": return node.props.flatMap((prop) => Array.isArray(prop.value) ? prop.value : []);
173
+ case "Show": return [...node.children, ...Array.isArray(node.fallback) ? node.fallback : []];
174
+ case "For": return node.body;
175
+ case "Slot": return node.fallback;
176
+ case "Host": return node.child ? [node.child] : [];
177
+ case "Text":
178
+ case "DynamicText": return [];
179
+ }
180
+ }
181
+ function getComponentChildren(node) {
182
+ const prop = node.props.find((prop) => prop.name === "children");
183
+ return prop && Array.isArray(prop.value) ? prop.value : [];
184
+ }
185
+ //#endregion
186
+ //#region packages/core/compiler-shared/src/assert.ts
187
+ function assertElementIR(node) {
188
+ if (node.kind !== "Element") throw new Error(`Expected Element IR, received ${node.kind}.`);
189
+ }
190
+ function assertNeverIR(node) {
191
+ throw new Error(`Unhandled IR node ${node.kind}.`);
192
+ }
193
+ //#endregion
194
+ exports.assertElementIR = assertElementIR;
195
+ exports.assertNeverIR = assertNeverIR;
196
+ exports.attrBindingIR = attrBindingIR;
197
+ exports.componentIR = componentIR;
198
+ exports.dynamicTextIR = dynamicTextIR;
199
+ exports.elementIR = elementIR;
200
+ exports.eventBindingIR = eventBindingIR;
201
+ exports.expressionIR = expressionIR;
202
+ exports.forIR = forIR;
203
+ exports.fragmentIR = fragmentIR;
204
+ exports.getComponentChildren = getComponentChildren;
205
+ exports.getIRChildren = getIRChildren;
206
+ exports.hostIR = hostIR;
207
+ exports.id = id;
208
+ exports.identifierIR = identifierIR;
209
+ exports.propBindingIR = propBindingIR;
210
+ exports.ref = ref;
211
+ exports.refBindingIR = refBindingIR;
212
+ exports.showIR = showIR;
213
+ exports.slotIR = slotIR;
214
+ exports.staticAttrIR = staticAttrIR;
215
+ exports.textIR = textIR;
216
+ exports.visitIR = visitIR;
@@ -0,0 +1,216 @@
1
+ /**
2
+ * compiler-shared v0.1.0-beta.9
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ Object.defineProperties(exports, {
7
+ __esModule: { value: true },
8
+ [Symbol.toStringTag]: { value: "Module" }
9
+ });
10
+ //#region packages/core/compiler-shared/src/semanticBuilders.ts
11
+ let nextId = 0;
12
+ function id() {
13
+ return nextId++;
14
+ }
15
+ function ref(name) {
16
+ return { name };
17
+ }
18
+ function expressionIR(code, span) {
19
+ return {
20
+ kind: "Expression",
21
+ code,
22
+ span
23
+ };
24
+ }
25
+ function identifierIR(name, span) {
26
+ return {
27
+ kind: "Identifier",
28
+ name,
29
+ span
30
+ };
31
+ }
32
+ function elementIR(input) {
33
+ var _input$attrs, _input$children;
34
+ return {
35
+ id: id(),
36
+ kind: "Element",
37
+ ref: input.ref,
38
+ tagName: input.tagName,
39
+ attrs: (_input$attrs = input.attrs) !== null && _input$attrs !== void 0 ? _input$attrs : [],
40
+ children: (_input$children = input.children) !== null && _input$children !== void 0 ? _input$children : [],
41
+ flags: {
42
+ isSVG: false,
43
+ isVoid: false,
44
+ isCustomElement: input.tagName.includes("-"),
45
+ ...input.flags
46
+ }
47
+ };
48
+ }
49
+ function textIR(value) {
50
+ return {
51
+ id: id(),
52
+ kind: "Text",
53
+ value
54
+ };
55
+ }
56
+ function dynamicTextIR(expr, nodeRef, once = false) {
57
+ return {
58
+ id: id(),
59
+ kind: "DynamicText",
60
+ expr,
61
+ ref: nodeRef,
62
+ once
63
+ };
64
+ }
65
+ function fragmentIR(children) {
66
+ return {
67
+ id: id(),
68
+ kind: "Fragment",
69
+ children
70
+ };
71
+ }
72
+ function staticAttrIR(name, value) {
73
+ return {
74
+ id: id(),
75
+ kind: "StaticAttribute",
76
+ name,
77
+ value
78
+ };
79
+ }
80
+ function attrBindingIR(name, expr) {
81
+ return {
82
+ id: id(),
83
+ kind: "AttrBinding",
84
+ name,
85
+ expr
86
+ };
87
+ }
88
+ function propBindingIR(name, expr) {
89
+ return {
90
+ id: id(),
91
+ kind: "PropBinding",
92
+ name,
93
+ expr
94
+ };
95
+ }
96
+ function eventBindingIR(eventName, handler) {
97
+ return {
98
+ id: id(),
99
+ kind: "EventBinding",
100
+ eventName,
101
+ handler
102
+ };
103
+ }
104
+ function refBindingIR(expr) {
105
+ return {
106
+ id: id(),
107
+ kind: "RefBinding",
108
+ expr
109
+ };
110
+ }
111
+ function componentIR(input) {
112
+ return {
113
+ id: id(),
114
+ kind: "Component",
115
+ ref: input.ref,
116
+ callee: input.callee,
117
+ props: input.props
118
+ };
119
+ }
120
+ function showIR(input) {
121
+ return {
122
+ id: id(),
123
+ kind: "Show",
124
+ ref: input.ref,
125
+ when: input.when,
126
+ children: input.children,
127
+ fallback: input.fallback
128
+ };
129
+ }
130
+ function forIR(input) {
131
+ return {
132
+ id: id(),
133
+ kind: "For",
134
+ ref: input.ref,
135
+ each: input.each,
136
+ by: input.by,
137
+ item: input.item,
138
+ index: input.index,
139
+ body: input.body
140
+ };
141
+ }
142
+ function hostIR(input) {
143
+ return {
144
+ id: id(),
145
+ kind: "Host",
146
+ attrs: input.attrs,
147
+ child: input.child
148
+ };
149
+ }
150
+ function slotIR(input) {
151
+ var _input$fallback;
152
+ return {
153
+ id: id(),
154
+ kind: "Slot",
155
+ ref: input.ref,
156
+ name: input.name,
157
+ fallback: (_input$fallback = input.fallback) !== null && _input$fallback !== void 0 ? _input$fallback : []
158
+ };
159
+ }
160
+ //#endregion
161
+ //#region packages/core/compiler-shared/src/visit.ts
162
+ function visitIR(node, visitor, parent) {
163
+ var _visitor$enter, _visitor$leave;
164
+ (_visitor$enter = visitor.enter) === null || _visitor$enter === void 0 || _visitor$enter.call(visitor, node, parent);
165
+ for (const child of getIRChildren(node)) visitIR(child, visitor, node);
166
+ (_visitor$leave = visitor.leave) === null || _visitor$leave === void 0 || _visitor$leave.call(visitor, node, parent);
167
+ }
168
+ function getIRChildren(node) {
169
+ switch (node.kind) {
170
+ case "Element":
171
+ case "Fragment": return node.children;
172
+ case "Component": return node.props.flatMap((prop) => Array.isArray(prop.value) ? prop.value : []);
173
+ case "Show": return [...node.children, ...Array.isArray(node.fallback) ? node.fallback : []];
174
+ case "For": return node.body;
175
+ case "Slot": return node.fallback;
176
+ case "Host": return node.child ? [node.child] : [];
177
+ case "Text":
178
+ case "DynamicText": return [];
179
+ }
180
+ }
181
+ function getComponentChildren(node) {
182
+ const prop = node.props.find((prop) => prop.name === "children");
183
+ return prop && Array.isArray(prop.value) ? prop.value : [];
184
+ }
185
+ //#endregion
186
+ //#region packages/core/compiler-shared/src/assert.ts
187
+ function assertElementIR(node) {
188
+ if (node.kind !== "Element") throw new Error(`Expected Element IR, received ${node.kind}.`);
189
+ }
190
+ function assertNeverIR(node) {
191
+ throw new Error(`Unhandled IR node ${node.kind}.`);
192
+ }
193
+ //#endregion
194
+ exports.assertElementIR = assertElementIR;
195
+ exports.assertNeverIR = assertNeverIR;
196
+ exports.attrBindingIR = attrBindingIR;
197
+ exports.componentIR = componentIR;
198
+ exports.dynamicTextIR = dynamicTextIR;
199
+ exports.elementIR = elementIR;
200
+ exports.eventBindingIR = eventBindingIR;
201
+ exports.expressionIR = expressionIR;
202
+ exports.forIR = forIR;
203
+ exports.fragmentIR = fragmentIR;
204
+ exports.getComponentChildren = getComponentChildren;
205
+ exports.getIRChildren = getIRChildren;
206
+ exports.hostIR = hostIR;
207
+ exports.id = id;
208
+ exports.identifierIR = identifierIR;
209
+ exports.propBindingIR = propBindingIR;
210
+ exports.ref = ref;
211
+ exports.refBindingIR = refBindingIR;
212
+ exports.showIR = showIR;
213
+ exports.slotIR = slotIR;
214
+ exports.staticAttrIR = staticAttrIR;
215
+ exports.textIR = textIR;
216
+ exports.visitIR = visitIR;
@@ -0,0 +1,227 @@
1
+ export interface SourcePosition {
2
+ line: number;
3
+ column: number;
4
+ offset?: number;
5
+ }
6
+ export interface SourceSpan {
7
+ start: SourcePosition;
8
+ end: SourcePosition;
9
+ }
10
+ export interface ExpressionIR {
11
+ kind: 'Expression';
12
+ code: string;
13
+ span?: SourceSpan;
14
+ }
15
+ export interface IdentifierIR {
16
+ kind: 'Identifier';
17
+ name: string;
18
+ span?: SourceSpan;
19
+ }
20
+ export interface IRRef {
21
+ name: string;
22
+ }
23
+ export type DomPath = {
24
+ kind: 'Root';
25
+ } | {
26
+ kind: 'FirstChild';
27
+ parent: IRRef;
28
+ } | {
29
+ kind: 'NextSibling';
30
+ previous: IRRef;
31
+ } | {
32
+ kind: 'Child';
33
+ parent: IRRef;
34
+ index: number;
35
+ } | {
36
+ kind: 'Marker';
37
+ parent: IRRef;
38
+ index: number;
39
+ };
40
+ export type PhysicalDomPath = {
41
+ kind: 'Root';
42
+ } | {
43
+ kind: 'FirstChild';
44
+ parent: IRRef;
45
+ } | {
46
+ kind: 'NextSibling';
47
+ previous: IRRef;
48
+ } | {
49
+ kind: 'ChildNode';
50
+ parent: IRRef;
51
+ index: number;
52
+ };
53
+ export interface SemanticBaseIRNode {
54
+ id: number;
55
+ span?: SourceSpan;
56
+ }
57
+ export type ProgramIR = SemanticBaseIRNode & {
58
+ kind: 'Program';
59
+ body: ZeusIRNode[];
60
+ };
61
+ export type ElementIR = SemanticBaseIRNode & {
62
+ kind: 'Element';
63
+ ref: IRRef;
64
+ tagName: string;
65
+ attrs: AttributeIR[];
66
+ children: ZeusIRNode[];
67
+ domPath?: DomPath;
68
+ physicalDomPath?: PhysicalDomPath;
69
+ flags: {
70
+ isSVG: boolean;
71
+ isVoid: boolean;
72
+ isCustomElement: boolean;
73
+ };
74
+ };
75
+ export type TextIR = SemanticBaseIRNode & {
76
+ kind: 'Text';
77
+ value: string;
78
+ };
79
+ export type DynamicTextIR = SemanticBaseIRNode & {
80
+ kind: 'DynamicText';
81
+ expr: ExpressionIR;
82
+ ref: IRRef;
83
+ once?: boolean;
84
+ domPath?: DomPath;
85
+ physicalDomPath?: PhysicalDomPath;
86
+ };
87
+ export type StaticAttributeIR = SemanticBaseIRNode & {
88
+ kind: 'StaticAttribute';
89
+ name: string;
90
+ value: string | true;
91
+ };
92
+ export type AttrBindingIR = SemanticBaseIRNode & {
93
+ kind: 'AttrBinding';
94
+ name: string;
95
+ expr: ExpressionIR;
96
+ };
97
+ export type PropBindingIR = SemanticBaseIRNode & {
98
+ kind: 'PropBinding';
99
+ name: string;
100
+ expr: ExpressionIR;
101
+ };
102
+ export type EventBindingIR = SemanticBaseIRNode & {
103
+ kind: 'EventBinding';
104
+ eventName: string;
105
+ handler: ExpressionIR;
106
+ };
107
+ export type RefBindingIR = SemanticBaseIRNode & {
108
+ kind: 'RefBinding';
109
+ expr: ExpressionIR;
110
+ };
111
+ export type AttributeIR = StaticAttributeIR | AttrBindingIR | PropBindingIR | EventBindingIR | RefBindingIR;
112
+ export interface ComponentPropIR {
113
+ name: string;
114
+ value: ExpressionIR | ZeusIRNode[];
115
+ }
116
+ export type ComponentIR = SemanticBaseIRNode & {
117
+ kind: 'Component';
118
+ ref: IRRef;
119
+ callee: ExpressionIR;
120
+ props: ComponentPropIR[];
121
+ domPath?: DomPath;
122
+ physicalDomPath?: PhysicalDomPath;
123
+ };
124
+ export type FragmentIR = SemanticBaseIRNode & {
125
+ kind: 'Fragment';
126
+ children: ZeusIRNode[];
127
+ };
128
+ export type ShowIR = SemanticBaseIRNode & {
129
+ kind: 'Show';
130
+ ref: IRRef;
131
+ when: ExpressionIR;
132
+ children: ZeusIRNode[];
133
+ fallback?: ExpressionIR | ZeusIRNode[];
134
+ domPath?: DomPath;
135
+ physicalDomPath?: PhysicalDomPath;
136
+ };
137
+ export type ForIR = SemanticBaseIRNode & {
138
+ kind: 'For';
139
+ ref: IRRef;
140
+ each: ExpressionIR;
141
+ by?: ExpressionIR;
142
+ item: IdentifierIR;
143
+ index?: IdentifierIR;
144
+ body: ZeusIRNode[];
145
+ domPath?: DomPath;
146
+ physicalDomPath?: PhysicalDomPath;
147
+ };
148
+ export type HostAttrIR = SemanticBaseIRNode & {
149
+ kind: 'HostAttr';
150
+ name: string;
151
+ expr: ExpressionIR;
152
+ };
153
+ export type HostIR = SemanticBaseIRNode & {
154
+ kind: 'Host';
155
+ attrs: HostAttrIR[];
156
+ child?: ZeusIRNode;
157
+ };
158
+ export type SlotIR = SemanticBaseIRNode & {
159
+ kind: 'Slot';
160
+ ref: IRRef;
161
+ name?: string;
162
+ fallback: ZeusIRNode[];
163
+ domPath?: DomPath;
164
+ physicalDomPath?: PhysicalDomPath;
165
+ };
166
+ export type ZeusIRNode = ElementIR | TextIR | DynamicTextIR | ComponentIR | FragmentIR | ShowIR | ForIR | HostIR | SlotIR;
167
+
168
+ export declare function id(): number;
169
+ export declare function ref(name: string): IRRef;
170
+ export declare function expressionIR(code: string, span?: SourceSpan): ExpressionIR;
171
+ export declare function identifierIR(name: string, span?: SourceSpan): IdentifierIR;
172
+ export declare function elementIR(input: {
173
+ ref: IRRef;
174
+ tagName: string;
175
+ attrs?: ElementIR['attrs'];
176
+ children?: ZeusIRNode[];
177
+ flags?: Partial<ElementIR['flags']>;
178
+ }): ElementIR;
179
+ export declare function textIR(value: string): TextIR;
180
+ export declare function dynamicTextIR(expr: ExpressionIR, nodeRef: IRRef, once?: boolean): DynamicTextIR;
181
+ export declare function fragmentIR(children: ZeusIRNode[]): FragmentIR;
182
+ export declare function staticAttrIR(name: string, value: string | true): StaticAttributeIR;
183
+ export declare function attrBindingIR(name: string, expr: ExpressionIR): AttrBindingIR;
184
+ export declare function propBindingIR(name: string, expr: ExpressionIR): PropBindingIR;
185
+ export declare function eventBindingIR(eventName: string, handler: ExpressionIR): EventBindingIR;
186
+ export declare function refBindingIR(expr: ExpressionIR): RefBindingIR;
187
+ export declare function componentIR(input: {
188
+ ref: IRRef;
189
+ callee: ExpressionIR;
190
+ props: ComponentIR['props'];
191
+ }): ComponentIR;
192
+ export declare function showIR(input: {
193
+ ref: IRRef;
194
+ when: ExpressionIR;
195
+ children: ZeusIRNode[];
196
+ fallback?: ExpressionIR | ZeusIRNode[];
197
+ }): ShowIR;
198
+ export declare function forIR(input: {
199
+ ref: IRRef;
200
+ each: ExpressionIR;
201
+ by?: ExpressionIR;
202
+ item: IdentifierIR;
203
+ index?: IdentifierIR;
204
+ body: ZeusIRNode[];
205
+ }): ForIR;
206
+ export declare function hostIR(input: {
207
+ attrs: HostAttrIR[];
208
+ child?: ZeusIRNode;
209
+ }): HostIR;
210
+ export declare function slotIR(input: {
211
+ ref: IRRef;
212
+ name?: string;
213
+ fallback?: ZeusIRNode[];
214
+ }): SlotIR;
215
+
216
+ export interface IRVisitor {
217
+ enter?: (node: ZeusIRNode, parent?: ZeusIRNode) => void;
218
+ leave?: (node: ZeusIRNode, parent?: ZeusIRNode) => void;
219
+ }
220
+ export declare function visitIR(node: ZeusIRNode, visitor: IRVisitor, parent?: ZeusIRNode): void;
221
+ export declare function getIRChildren(node: ZeusIRNode): ZeusIRNode[];
222
+ export declare function getComponentChildren(node: ComponentIR): ZeusIRNode[];
223
+
224
+ export declare function assertElementIR(node: ZeusIRNode): asserts node is ElementIR;
225
+ export declare function assertNeverIR(node: never): never;
226
+
227
+
@@ -0,0 +1,250 @@
1
+ /**
2
+ * compiler-shared v0.1.0-beta.9
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
10
+ return typeof o;
11
+ } : function(o) {
12
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13
+ }, _typeof(o);
14
+ }
15
+ //#endregion
16
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
17
+ function toPrimitive(t, r) {
18
+ if ("object" != _typeof(t) || !t) return t;
19
+ var e = t[Symbol.toPrimitive];
20
+ if (void 0 !== e) {
21
+ var i = e.call(t, r || "default");
22
+ if ("object" != _typeof(i)) return i;
23
+ throw new TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return ("string" === r ? String : Number)(t);
26
+ }
27
+ //#endregion
28
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
29
+ function toPropertyKey(t) {
30
+ var i = toPrimitive(t, "string");
31
+ return "symbol" == _typeof(i) ? i : i + "";
32
+ }
33
+ //#endregion
34
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
35
+ function _defineProperty(e, r, t) {
36
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
37
+ value: t,
38
+ enumerable: !0,
39
+ configurable: !0,
40
+ writable: !0
41
+ }) : e[r] = t, e;
42
+ }
43
+ //#endregion
44
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/objectSpread2.js
45
+ function ownKeys(e, r) {
46
+ var t = Object.keys(e);
47
+ if (Object.getOwnPropertySymbols) {
48
+ var o = Object.getOwnPropertySymbols(e);
49
+ r && (o = o.filter(function(r) {
50
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
51
+ })), t.push.apply(t, o);
52
+ }
53
+ return t;
54
+ }
55
+ function _objectSpread2(e) {
56
+ for (var r = 1; r < arguments.length; r++) {
57
+ var t = null != arguments[r] ? arguments[r] : {};
58
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
59
+ _defineProperty(e, r, t[r]);
60
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
61
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
62
+ });
63
+ }
64
+ return e;
65
+ }
66
+ //#endregion
67
+ //#region packages/core/compiler-shared/src/semanticBuilders.ts
68
+ let nextId = 0;
69
+ function id() {
70
+ return nextId++;
71
+ }
72
+ function ref(name) {
73
+ return { name };
74
+ }
75
+ function expressionIR(code, span) {
76
+ return {
77
+ kind: "Expression",
78
+ code,
79
+ span
80
+ };
81
+ }
82
+ function identifierIR(name, span) {
83
+ return {
84
+ kind: "Identifier",
85
+ name,
86
+ span
87
+ };
88
+ }
89
+ function elementIR(input) {
90
+ var _input$attrs, _input$children;
91
+ return {
92
+ id: id(),
93
+ kind: "Element",
94
+ ref: input.ref,
95
+ tagName: input.tagName,
96
+ attrs: (_input$attrs = input.attrs) !== null && _input$attrs !== void 0 ? _input$attrs : [],
97
+ children: (_input$children = input.children) !== null && _input$children !== void 0 ? _input$children : [],
98
+ flags: _objectSpread2({
99
+ isSVG: false,
100
+ isVoid: false,
101
+ isCustomElement: input.tagName.includes("-")
102
+ }, input.flags)
103
+ };
104
+ }
105
+ function textIR(value) {
106
+ return {
107
+ id: id(),
108
+ kind: "Text",
109
+ value
110
+ };
111
+ }
112
+ function dynamicTextIR(expr, nodeRef, once = false) {
113
+ return {
114
+ id: id(),
115
+ kind: "DynamicText",
116
+ expr,
117
+ ref: nodeRef,
118
+ once
119
+ };
120
+ }
121
+ function fragmentIR(children) {
122
+ return {
123
+ id: id(),
124
+ kind: "Fragment",
125
+ children
126
+ };
127
+ }
128
+ function staticAttrIR(name, value) {
129
+ return {
130
+ id: id(),
131
+ kind: "StaticAttribute",
132
+ name,
133
+ value
134
+ };
135
+ }
136
+ function attrBindingIR(name, expr) {
137
+ return {
138
+ id: id(),
139
+ kind: "AttrBinding",
140
+ name,
141
+ expr
142
+ };
143
+ }
144
+ function propBindingIR(name, expr) {
145
+ return {
146
+ id: id(),
147
+ kind: "PropBinding",
148
+ name,
149
+ expr
150
+ };
151
+ }
152
+ function eventBindingIR(eventName, handler) {
153
+ return {
154
+ id: id(),
155
+ kind: "EventBinding",
156
+ eventName,
157
+ handler
158
+ };
159
+ }
160
+ function refBindingIR(expr) {
161
+ return {
162
+ id: id(),
163
+ kind: "RefBinding",
164
+ expr
165
+ };
166
+ }
167
+ function componentIR(input) {
168
+ return {
169
+ id: id(),
170
+ kind: "Component",
171
+ ref: input.ref,
172
+ callee: input.callee,
173
+ props: input.props
174
+ };
175
+ }
176
+ function showIR(input) {
177
+ return {
178
+ id: id(),
179
+ kind: "Show",
180
+ ref: input.ref,
181
+ when: input.when,
182
+ children: input.children,
183
+ fallback: input.fallback
184
+ };
185
+ }
186
+ function forIR(input) {
187
+ return {
188
+ id: id(),
189
+ kind: "For",
190
+ ref: input.ref,
191
+ each: input.each,
192
+ by: input.by,
193
+ item: input.item,
194
+ index: input.index,
195
+ body: input.body
196
+ };
197
+ }
198
+ function hostIR(input) {
199
+ return {
200
+ id: id(),
201
+ kind: "Host",
202
+ attrs: input.attrs,
203
+ child: input.child
204
+ };
205
+ }
206
+ function slotIR(input) {
207
+ var _input$fallback;
208
+ return {
209
+ id: id(),
210
+ kind: "Slot",
211
+ ref: input.ref,
212
+ name: input.name,
213
+ fallback: (_input$fallback = input.fallback) !== null && _input$fallback !== void 0 ? _input$fallback : []
214
+ };
215
+ }
216
+ //#endregion
217
+ //#region packages/core/compiler-shared/src/visit.ts
218
+ function visitIR(node, visitor, parent) {
219
+ var _visitor$enter, _visitor$leave;
220
+ (_visitor$enter = visitor.enter) === null || _visitor$enter === void 0 || _visitor$enter.call(visitor, node, parent);
221
+ for (const child of getIRChildren(node)) visitIR(child, visitor, node);
222
+ (_visitor$leave = visitor.leave) === null || _visitor$leave === void 0 || _visitor$leave.call(visitor, node, parent);
223
+ }
224
+ function getIRChildren(node) {
225
+ switch (node.kind) {
226
+ case "Element":
227
+ case "Fragment": return node.children;
228
+ case "Component": return node.props.flatMap((prop) => Array.isArray(prop.value) ? prop.value : []);
229
+ case "Show": return [...node.children, ...Array.isArray(node.fallback) ? node.fallback : []];
230
+ case "For": return node.body;
231
+ case "Slot": return node.fallback;
232
+ case "Host": return node.child ? [node.child] : [];
233
+ case "Text":
234
+ case "DynamicText": return [];
235
+ }
236
+ }
237
+ function getComponentChildren(node) {
238
+ const prop = node.props.find((prop) => prop.name === "children");
239
+ return prop && Array.isArray(prop.value) ? prop.value : [];
240
+ }
241
+ //#endregion
242
+ //#region packages/core/compiler-shared/src/assert.ts
243
+ function assertElementIR(node) {
244
+ if (node.kind !== "Element") throw new Error(`Expected Element IR, received ${node.kind}.`);
245
+ }
246
+ function assertNeverIR(node) {
247
+ throw new Error(`Unhandled IR node ${node.kind}.`);
248
+ }
249
+ //#endregion
250
+ export { assertElementIR, assertNeverIR, attrBindingIR, componentIR, dynamicTextIR, elementIR, eventBindingIR, expressionIR, forIR, fragmentIR, getComponentChildren, getIRChildren, hostIR, id, identifierIR, propBindingIR, ref, refBindingIR, showIR, slotIR, staticAttrIR, textIR, visitIR };
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./dist/compiler-shared.cjs.prod.js')
5
+ } else {
6
+ module.exports = require('./dist/compiler-shared.cjs.js')
7
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@zeus-js/compiler-shared",
3
+ "type": "module",
4
+ "version": "0.1.0-beta.9",
5
+ "description": "Babel-independent Zeus compiler IR contracts",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/baicie/zeus.git",
10
+ "directory": "packages/core/compiler-shared"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "provenance": true
15
+ },
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/compiler-shared.d.ts",
20
+ "module": "./dist/compiler-shared.esm-bundler.js",
21
+ "import": "./dist/compiler-shared.esm-bundler.js",
22
+ "require": "./index.js",
23
+ "node": {
24
+ "production": "./dist/compiler-shared.cjs.prod.js",
25
+ "development": "./dist/compiler-shared.cjs.js",
26
+ "default": "./index.js"
27
+ }
28
+ }
29
+ },
30
+ "files": [
31
+ "index.js",
32
+ "dist"
33
+ ],
34
+ "bugs": {
35
+ "url": "https://github.com/baicie/zeus/issues"
36
+ },
37
+ "buildOptions": {
38
+ "formats": [
39
+ "esm-bundler",
40
+ "cjs"
41
+ ]
42
+ },
43
+ "homepage": "https://github.com/baicie/zeus/tree/main/packages/core/compiler-shared#readme",
44
+ "keywords": [
45
+ "zeus",
46
+ "compiler",
47
+ "ir"
48
+ ],
49
+ "main": "index.js",
50
+ "module": "dist/compiler-shared.esm-bundler.js",
51
+ "types": "dist/compiler-shared.d.ts"
52
+ }