babel-plugin-essor 0.0.14 → 0.0.15-beta.1

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/dist/index.cjs CHANGED
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
11
+ var __spreadValues = (a2, b) => {
10
12
  for (var prop in b || (b = {}))
11
13
  if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
14
+ __defNormalProp(a2, prop, b[prop]);
13
15
  if (__getOwnPropSymbols)
14
16
  for (var prop of __getOwnPropSymbols(b)) {
15
17
  if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
18
+ __defNormalProp(a2, prop, b[prop]);
17
19
  }
18
- return a;
20
+ return a2;
19
21
  };
22
+ var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
20
23
  var __export = (target, all) => {
21
24
  for (var name in all)
22
25
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -32,733 +35,2271 @@ var __copyProps = (to, from, except, desc) => {
32
35
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
36
 
34
37
  // src/index.ts
35
- var src_exports = {};
36
- __export(src_exports, {
37
- default: () => src_default
38
+ var index_exports = {};
39
+ __export(index_exports, {
40
+ default: () => index_default
38
41
  });
39
- module.exports = __toCommonJS(src_exports);
42
+ module.exports = __toCommonJS(index_exports);
40
43
 
41
- // src/jsx/index.ts
42
- var import_core3 = require("@babel/core");
44
+ // src/program.ts
45
+ var import_core2 = require("@babel/core");
43
46
 
44
- // ../shared/dist/shared.js
45
- var isArray = Array.isArray;
46
- function isString(val) {
47
- return typeof val === "string";
48
- }
49
- var noop = Function.prototype;
50
- function startsWith(str, searchString) {
51
- if (!isString(str)) {
52
- return false;
53
- }
54
- return str.indexOf(searchString) === 0;
47
+ // src/import.ts
48
+ var import_core = require("@babel/core");
49
+
50
+ // ../shared/dist/shared.esm.js
51
+ var w = (e) => e !== null && typeof e == "object";
52
+ var d = Array.isArray;
53
+ function m(e) {
54
+ return typeof e == "string";
55
55
  }
56
- var cacheStringFunction = (fn) => {
57
- const cache = /* @__PURE__ */ Object.create(null);
58
- return (str) => {
59
- const hit = cache[str];
60
- return hit || (cache[str] = fn(str));
61
- };
56
+ function T(e) {
57
+ return typeof e == "number";
58
+ }
59
+ function y(e) {
60
+ return e === null;
61
+ }
62
+ function A(e) {
63
+ return typeof e == "symbol";
64
+ }
65
+ function E(e) {
66
+ return a.call(e) === "[object Map]";
67
+ }
68
+ function N(e) {
69
+ return e == null;
70
+ }
71
+ var j = (e) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof e) || y(e);
72
+ var P = (e) => a.call(e) === "[object Object]";
73
+ function _(e) {
74
+ return typeof e == "undefined";
75
+ }
76
+ function z(e) {
77
+ return typeof e == "boolean";
78
+ }
79
+ var a = Object.prototype.toString;
80
+ function G(e) {
81
+ return d(e) ? e : [e];
82
+ }
83
+ var V = Function.prototype;
84
+ function q(e, t10) {
85
+ return m(e) ? e.indexOf(t10) === 0 : false;
86
+ }
87
+ var u = (e) => {
88
+ let t10 = /* @__PURE__ */ Object.create(null);
89
+ return ((n) => t10[n] || (t10[n] = e(n)));
62
90
  };
63
- var hyphenateRE = /\B([A-Z])/g;
64
- var kebabCase = cacheStringFunction(
65
- (str) => str.replaceAll(hyphenateRE, "-$1").toLowerCase()
91
+ var W = Object.freeze({});
92
+ var Y = Object.freeze([]);
93
+ var J = /\B([A-Z])/g;
94
+ var Z = u((e) => e.replaceAll(J, "-$1").toLowerCase());
95
+ var Q = /[_-](\w)/g;
96
+ var ee = u((e) => (e = e.replaceAll(/^[_-]+|[_-]+$/g, ""), e = e.replaceAll(/[_-]+/g, "-"), e.replaceAll(Q, (t10, n) => n.toUpperCase())));
97
+ var te = u((e) => e.charAt(0).toUpperCase() + e.slice(1));
98
+ function ne(e, ...t10) {
99
+ console.warn(`[Essor warn]: ${e}`, ...t10);
100
+ }
101
+ function h(e, ...t10) {
102
+ console.error(`[Essor error]: ${e}`, ...t10);
103
+ }
104
+ function o(e) {
105
+ let t10 = /* @__PURE__ */ Object.create(null);
106
+ for (let n of e.split(",")) t10[n] = 1;
107
+ return (n) => n in t10;
108
+ }
109
+ var x = "itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly";
110
+ var pe = o(x);
111
+ var ue = o(`${x},async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
112
+ var he = o("accept,accept-charset,accesskey,action,align,allow,alt,async,autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,border,buffered,capture,challenge,charset,checked,cite,class,code,codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,formaction,formenctype,formmethod,formnovalidate,formtarget,headers,height,hidden,high,href,hreflang,http-equiv,icon,id,importance,inert,integrity,ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,target,title,translate,type,usemap,value,width,wrap");
113
+ var be = o("xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,arabic-form,ascent,attributeName,attributeType,azimuth,baseFrequency,baseline-shift,baseProfile,bbox,begin,bias,by,calcMode,cap-height,class,clip,clipPathUnits,clip-path,clip-rule,color,color-interpolation,color-interpolation-filters,color-profile,color-rendering,contentScriptType,contentStyleType,crossorigin,cursor,cx,cy,d,decelerate,descent,diffuseConstant,direction,display,divisor,dominant-baseline,dur,dx,dy,edgeMode,elevation,enable-background,end,exponent,fill,fill-opacity,fill-rule,filter,filterRes,filterUnits,flood-color,flood-opacity,font-family,font-size,font-size-adjust,font-stretch,font-style,font-variant,font-weight,format,from,fr,fx,fy,g1,g2,glyph-name,glyph-orientation-horizontal,glyph-orientation-vertical,glyphRef,gradientTransform,gradientUnits,hanging,height,href,hreflang,horiz-adv-x,horiz-origin-x,id,ideographic,image-rendering,in,in2,intercept,k,k1,k2,k3,k4,kernelMatrix,kernelUnitLength,kerning,keyPoints,keySplines,keyTimes,lang,lengthAdjust,letter-spacing,lighting-color,limitingConeAngle,local,marker-end,marker-mid,marker-start,markerHeight,markerUnits,markerWidth,mask,maskContentUnits,maskUnits,mathematical,max,media,method,min,mode,name,numOctaves,offset,opacity,operator,order,orient,orientation,origin,overflow,overline-position,overline-thickness,panose-1,paint-order,path,pathLength,patternContentUnits,patternTransform,patternUnits,ping,pointer-events,points,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,preserveAspectRatio,primitiveUnits,r,radius,referrerPolicy,refX,refY,rel,rendering-intent,repeatCount,repeatDur,requiredExtensions,requiredFeatures,restart,result,rotate,rx,ry,scale,seed,shape-rendering,slope,spacing,specularConstant,specularExponent,speed,spreadMethod,startOffset,stdDeviation,stemh,stemv,stitchTiles,stop-color,stop-opacity,strikethrough-position,strikethrough-thickness,string,stroke,stroke-dasharray,stroke-dashoffset,stroke-linecap,stroke-linejoin,stroke-miterlimit,stroke-opacity,stroke-width,style,surfaceScale,systemLanguage,tabindex,tableValues,target,targetX,targetY,text-anchor,text-decoration,text-rendering,textLength,to,transform,transform-origin,type,u1,u2,underline-position,underline-thickness,unicode,unicode-bidi,unicode-range,units-per-em,v-alphabetic,v-hanging,v-ideographic,v-mathematical,values,vector-effect,version,vert-adv-y,vert-origin-x,vert-origin-y,viewBox,viewTarget,visibility,width,widths,word-spacing,writing-mode,x,x-height,x1,x2,xChannelSelector,xlink:actuate,xlink:arcrole,xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xmlns:xlink,xml:base,xml:lang,xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan");
114
+ var ke = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
115
+ var xe = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
116
+ var we = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
117
+ var ve = "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart";
118
+ var Te = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
119
+ var Ae = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
120
+ var Se = o(ke);
121
+ var Me = o(xe);
122
+ var Ce = o(we);
123
+ var Ee = o(Te);
124
+ var Ne = o(Ae);
125
+ var Oe = o(ve);
126
+
127
+ // src/constants.ts
128
+ var DEFAULT_OPTIONS = {
129
+ mode: "client",
130
+ symbol: "$",
131
+ props: true,
132
+ hmr: false,
133
+ styled: false
134
+ };
135
+ var IMPORTS_MAPS = [
136
+ // Reactive API
137
+ "signal",
138
+ "computed",
139
+ "reactive",
140
+ "memoEffect",
141
+ "omitProps",
142
+ // component
143
+ "createComponent",
144
+ "Fragment",
145
+ "For",
146
+ "Suspense",
147
+ "Portal",
148
+ // Template related
149
+ "mapNodes",
150
+ "template",
151
+ "delegateEvents",
152
+ // styled
153
+ "styled",
154
+ // binding related
155
+ "insert",
156
+ "patchStyle",
157
+ "patchClass",
158
+ "patchAttr",
159
+ "bindElement",
160
+ "setSpread",
161
+ "addEventListener",
162
+ // rendering related
163
+ "render",
164
+ "escapeHTML",
165
+ "getHydrationKey"
166
+ ];
167
+ var SSG_IMPORTS_MAPS = {
168
+ createComponent: "createSSGComponent",
169
+ patchAttr: "setSSGAttr"
170
+ };
171
+ var SSR_IMPORTS_MAPS = {
172
+ mapNodes: "mapSSRNodes",
173
+ template: "getElement"
174
+ };
175
+ var TRANSFORM_PROPERTY_NAME = "__props";
176
+
177
+ // src/import.ts
178
+ function createImportIdentifiers(path) {
179
+ const identifiers = IMPORTS_MAPS.reduce((acc, name) => {
180
+ var _a, _b;
181
+ const identifier = (_b = (_a = path.scope) == null ? void 0 : _a.generateUidIdentifier(`${name}$`)) != null ? _b : import_core.types.identifier(`${name}$`);
182
+ if (!identifier) {
183
+ throw new Error(`Failed to generate identifier for ${name}`);
184
+ }
185
+ acc[name] = identifier;
186
+ return acc;
187
+ }, {});
188
+ return identifiers;
189
+ }
190
+ var importMap = IMPORTS_MAPS.reduce(
191
+ (acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: name }),
192
+ {}
66
193
  );
67
- var camelizeRE = /-(\w)/g;
68
- var camelCase = cacheStringFunction((str) => {
69
- return str.replaceAll(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
70
- });
71
- var capitalize = cacheStringFunction(
72
- (str) => {
73
- return str.charAt(0).toUpperCase() + str.slice(1);
194
+ var importedSets = /* @__PURE__ */ new Set();
195
+ function addImport(name) {
196
+ importedSets.add(name);
197
+ }
198
+ function clearImport() {
199
+ importedSets.clear();
200
+ }
201
+ function createImport(path, imports, from) {
202
+ const state = path.state;
203
+ const mode = state.opts.mode;
204
+ if (!importedSets.size) {
205
+ return;
74
206
  }
75
- );
207
+ try {
208
+ const importSpecifiers = Array.from(importedSets).map((name) => {
209
+ const importIdentifier = imports[name];
210
+ if (!importIdentifier) {
211
+ throw new Error(`Import identifier not found for: ${name}`);
212
+ }
213
+ const local = import_core.types.identifier(importIdentifier.name);
214
+ if (mode === "ssg" /* SSG */) {
215
+ name = SSG_IMPORTS_MAPS[name] || name;
216
+ }
217
+ if (mode === "ssr" /* SSR */) {
218
+ name = SSR_IMPORTS_MAPS[name] || name;
219
+ }
220
+ const imported = import_core.types.identifier(name);
221
+ return import_core.types.importSpecifier(local, imported);
222
+ });
223
+ const importDeclaration = import_core.types.importDeclaration(importSpecifiers, import_core.types.stringLiteral(from));
224
+ path.node.body.unshift(importDeclaration);
225
+ } catch (error_) {
226
+ h("Failed to create import declaration:", h);
227
+ throw error_;
228
+ }
229
+ }
76
230
 
77
231
  // src/program.ts
78
- var import_core = require("@babel/core");
79
- var imports = /* @__PURE__ */ new Set();
80
- var defaultOption = {
81
- server: false,
82
- symbol: "$",
83
- props: true
84
- };
85
232
  var transformProgram = {
86
- enter(path, state) {
87
- imports.clear();
88
- state.opts = __spreadValues(__spreadValues({}, defaultOption), state.opts);
89
- path.state = {
90
- h: path.scope.generateUidIdentifier("h$"),
91
- template: path.scope.generateUidIdentifier("template$"),
92
- ssg: path.scope.generateUidIdentifier("ssg$"),
93
- Fragment: path.scope.generateUidIdentifier("fragment$"),
94
- useSignal: path.scope.generateUidIdentifier("useSignal$"),
95
- useComputed: path.scope.generateUidIdentifier("useComputed$"),
96
- useReactive: path.scope.generateUidIdentifier("useReactive$"),
97
- tmplDeclaration: import_core.types.variableDeclaration("const", []),
98
- opts: state.opts
99
- };
233
+ enter: (path, state) => {
234
+ const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), state.opts);
235
+ const imports = createImportIdentifiers(path);
236
+ clearImport();
237
+ path.state = __spreadProps(__spreadValues({}, state), {
238
+ opts,
239
+ imports,
240
+ declarations: [],
241
+ // Collect template declarations during transformation
242
+ filename: state.filename,
243
+ events: /* @__PURE__ */ new Set()
244
+ // Track delegated events for optimization
245
+ });
100
246
  },
101
- exit(path) {
102
- const state = path.state;
103
- if (state.tmplDeclaration.declarations.length > 0) {
104
- const index = path.node.body.findIndex(
105
- (node) => !import_core.types.isImportDeclaration(node) && !import_core.types.isExportDeclaration(node)
106
- );
107
- path.node.body.splice(index, 0, state.tmplDeclaration);
247
+ // eslint-disable-next-line unused-imports/no-unused-vars
248
+ exit: (path, state) => {
249
+ const pluginState = path.state;
250
+ const { imports, declarations, events } = pluginState;
251
+ const insertIndex = path.node.body.findIndex(
252
+ (node) => !import_core2.types.isImportDeclaration(node) && !import_core2.types.isExportDeclaration(node)
253
+ );
254
+ if (declarations == null ? void 0 : declarations.length) {
255
+ const templateDeclaration = import_core2.types.variableDeclaration("const", declarations);
256
+ if (insertIndex !== -1) {
257
+ path.node.body.splice(insertIndex, 0, templateDeclaration);
258
+ } else {
259
+ path.node.body.push(templateDeclaration);
260
+ }
108
261
  }
109
- if (imports.size > 0) {
110
- path.node.body.unshift(createImport(state, "essor"));
262
+ if (events && events.size > 0) {
263
+ const eventsDeclaration = import_core2.types.expressionStatement(
264
+ import_core2.types.callExpression(imports.delegateEvents, [
265
+ import_core2.types.arrayExpression(Array.from(events).map((event) => import_core2.types.stringLiteral(event)))
266
+ ])
267
+ );
268
+ addImport(importMap.delegateEvents);
269
+ path.node.body.push(eventsDeclaration);
111
270
  }
271
+ createImport(path, imports, "essor");
112
272
  }
113
273
  };
114
- function createImport(state, from) {
115
- const ImportSpecifier = [];
116
- imports.forEach((name) => {
117
- const local = import_core.types.identifier(state[name].name);
118
- const imported = import_core.types.identifier(name);
119
- ImportSpecifier.push(import_core.types.importSpecifier(local, imported));
274
+
275
+ // src/signals/props.ts
276
+ var import_core4 = require("@babel/core");
277
+
278
+ // src/signals/utils.ts
279
+ var import_core3 = require("@babel/core");
280
+ function isValidPath(path) {
281
+ return !!(path && path.node);
282
+ }
283
+ function isJSXNode(node) {
284
+ return !!(node && (import_core3.types.isJSXElement(node) || import_core3.types.isJSXFragment(node)));
285
+ }
286
+ function mightReturnJSX(expr) {
287
+ if (isJSXNode(expr)) {
288
+ return true;
289
+ }
290
+ if (import_core3.types.isConditionalExpression(expr)) {
291
+ return mightReturnJSX(expr.consequent) || mightReturnJSX(expr.alternate);
292
+ }
293
+ if (import_core3.types.isLogicalExpression(expr)) {
294
+ return mightReturnJSX(expr.left) || mightReturnJSX(expr.right);
295
+ }
296
+ if (import_core3.types.isSequenceExpression(expr)) {
297
+ return expr.expressions.some(mightReturnJSX);
298
+ }
299
+ if (import_core3.types.isParenthesizedExpression(expr)) {
300
+ return mightReturnJSX(expr.expression);
301
+ }
302
+ return false;
303
+ }
304
+ function checkHasJSXReturn(path) {
305
+ if (!isValidPath(path)) return false;
306
+ try {
307
+ const body = path.get("body");
308
+ if (!isValidPath(body)) return false;
309
+ if (!import_core3.types.isBlockStatement(body.node)) {
310
+ return mightReturnJSX(body.node);
311
+ }
312
+ let hasJSX = false;
313
+ body.traverse({
314
+ "ReturnStatement": function(returnPath) {
315
+ if (!hasJSX && returnPath.node.argument && mightReturnJSX(returnPath.node.argument)) {
316
+ hasJSX = true;
317
+ returnPath.stop();
318
+ }
319
+ },
320
+ "FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": (nestedPath) => {
321
+ nestedPath.skip();
322
+ }
323
+ });
324
+ return hasJSX;
325
+ } catch (e) {
326
+ return false;
327
+ }
328
+ }
329
+ function isMemberAccessingProperty(node, propertyName) {
330
+ if (!node.computed && import_core3.types.isIdentifier(node.property) && node.property.name === propertyName) {
331
+ return true;
332
+ }
333
+ if (node.computed && import_core3.types.isStringLiteral(node.property) && node.property.value === propertyName) {
334
+ return true;
335
+ }
336
+ return false;
337
+ }
338
+
339
+ // src/signals/props.ts
340
+ function transformProperty(path, properties, parentPath, defaultValues = {}) {
341
+ properties.forEach((property, index) => {
342
+ try {
343
+ if (!import_core4.types.isObjectProperty(property)) {
344
+ return;
345
+ }
346
+ if (!import_core4.types.isIdentifier(property.key)) {
347
+ if (true) {
348
+ ne("transformObjectProperties: Skipping computed property", { index });
349
+ }
350
+ return;
351
+ }
352
+ const keyName = property.key.name;
353
+ if (import_core4.types.isIdentifier(property.value)) {
354
+ path.scope.rename(property.value.name, `${parentPath}.${keyName}`);
355
+ } else if (import_core4.types.isAssignmentPattern(property.value)) {
356
+ if (import_core4.types.isIdentifier(property.value.left)) {
357
+ defaultValues[keyName] = property.value.right;
358
+ path.scope.rename(property.value.left.name, `${parentPath}.${keyName}`);
359
+ } else if (import_core4.types.isObjectPattern(property.value.left)) {
360
+ transformProperty(
361
+ path,
362
+ property.value.left.properties,
363
+ `${parentPath}.${keyName}`,
364
+ defaultValues
365
+ );
366
+ defaultValues[keyName] = property.value.right;
367
+ }
368
+ } else if (import_core4.types.isObjectPattern(property.value)) {
369
+ transformProperty(
370
+ path,
371
+ property.value.properties,
372
+ `${parentPath}.${keyName}`,
373
+ defaultValues
374
+ );
375
+ }
376
+ } catch (error) {
377
+ ne("transformProperty", `Failed to process property at index ${index}`, {
378
+ error: error instanceof Error ? error.message : String(error)
379
+ });
380
+ }
381
+ });
382
+ return defaultValues;
383
+ }
384
+ function buildRestVariableDeclaration(state, restName, parentPath, excludeProps) {
385
+ const validExcludeProps = excludeProps.filter(Boolean);
386
+ let init;
387
+ const pathParts = parentPath.split(".").filter((part) => part.length > 0);
388
+ let sourceObject = import_core4.types.identifier(pathParts[0] || "__props");
389
+ for (let i = 1; i < pathParts.length; i++) {
390
+ sourceObject = import_core4.types.memberExpression(sourceObject, import_core4.types.identifier(pathParts[i]));
391
+ }
392
+ if (validExcludeProps.length === 0) {
393
+ init = sourceObject;
394
+ } else {
395
+ init = import_core4.types.callExpression(state.imports.omitProps, [
396
+ sourceObject,
397
+ import_core4.types.arrayExpression(validExcludeProps.map((name) => import_core4.types.stringLiteral(name)))
398
+ ]);
399
+ }
400
+ return import_core4.types.variableDeclaration("const", [import_core4.types.variableDeclarator(import_core4.types.identifier(restName), init)]);
401
+ }
402
+ function transformRestProperties(path, restProperties, notRestNames = [], nestedRestParams = []) {
403
+ if (!import_core4.types.isIdentifier(restProperties.argument)) {
404
+ return;
405
+ }
406
+ const restName = restProperties.argument.name;
407
+ if (notRestNames.length === 0 && nestedRestParams.length === 0) {
408
+ path.node.params[0] = import_core4.types.identifier(restName);
409
+ } else {
410
+ const restDeclarations = [];
411
+ if (nestedRestParams.length > 0) {
412
+ for (const nestedRest of nestedRestParams) {
413
+ const nestedRestDeclaration = buildRestVariableDeclaration(
414
+ path.state,
415
+ nestedRest.name,
416
+ nestedRest.parentPath,
417
+ nestedRest.excludeProps
418
+ );
419
+ restDeclarations.push(nestedRestDeclaration);
420
+ if (nestedRest.excludeProps.length > 0) {
421
+ addImport(importMap.omitProps);
422
+ }
423
+ }
424
+ }
425
+ if (restProperties) {
426
+ const restDeclaration = buildRestVariableDeclaration(
427
+ path.state,
428
+ restName,
429
+ TRANSFORM_PROPERTY_NAME,
430
+ notRestNames
431
+ );
432
+ restDeclarations.push(restDeclaration);
433
+ if (notRestNames.length) {
434
+ addImport(importMap.omitProps);
435
+ }
436
+ }
437
+ for (const declaration of restDeclarations) {
438
+ const body = path.node.body;
439
+ body.body.unshift(declaration);
440
+ }
441
+ }
442
+ }
443
+ function buildDefaultValueObject(defaultValues) {
444
+ if (!P(defaultValues)) {
445
+ return import_core4.types.objectExpression([]);
446
+ }
447
+ const properties = [];
448
+ for (const [key, value] of Object.entries(defaultValues)) {
449
+ if (!key) {
450
+ continue;
451
+ }
452
+ let propertyValue;
453
+ if (P(value) && !import_core4.types.isNode(value)) {
454
+ propertyValue = buildDefaultValueObject(value);
455
+ } else if (import_core4.types.isExpression(value)) {
456
+ propertyValue = value;
457
+ } else {
458
+ continue;
459
+ }
460
+ properties.push(import_core4.types.objectProperty(import_core4.types.identifier(key), propertyValue));
461
+ }
462
+ return import_core4.types.objectExpression(properties);
463
+ }
464
+ function buildDefaultValue(path, defaultValues) {
465
+ const propsParam = Object.keys(defaultValues).length > 0 ? import_core4.types.assignmentPattern(
466
+ import_core4.types.identifier(TRANSFORM_PROPERTY_NAME),
467
+ buildDefaultValueObject(defaultValues)
468
+ ) : import_core4.types.identifier(TRANSFORM_PROPERTY_NAME);
469
+ path.node.params[0] = propsParam;
470
+ }
471
+ function transformProps(path) {
472
+ const firstParam = path.node.params[0];
473
+ if (!firstParam || !import_core4.types.isObjectPattern(firstParam) || !checkHasJSXReturn(path)) {
474
+ return;
475
+ }
476
+ const state = path.state;
477
+ const properties = firstParam.properties;
478
+ const signalPrefix = state.opts.symbol || "$";
479
+ const notRestProperties = properties.filter((prop) => !import_core4.types.isRestElement(prop));
480
+ const restProperties = properties.find((prop) => import_core4.types.isRestElement(prop));
481
+ const notRestNames = notRestProperties.map((prop) => import_core4.types.isIdentifier(prop.key) ? prop.key.name : null).filter((name) => name !== null);
482
+ if (true) {
483
+ if (notRestNames.some((name) => q(name, signalPrefix))) {
484
+ ne(
485
+ "transformProps",
486
+ "Property names cannot start with signal prefix",
487
+ notRestNames.filter((name) => q(name, signalPrefix))
488
+ );
489
+ }
490
+ }
491
+ if (notRestProperties.length) {
492
+ const defaultValues = transformProperty(path, notRestProperties, TRANSFORM_PROPERTY_NAME);
493
+ buildDefaultValue(path, defaultValues);
494
+ }
495
+ if (restProperties) {
496
+ transformRestProperties(path, restProperties, notRestNames);
497
+ }
498
+ }
499
+
500
+ // src/jsx/context.ts
501
+ var contextStack = [];
502
+ function getContext() {
503
+ if (!contextStack.length) {
504
+ throw new Error("No active context found. Ensure setContext has been called.");
505
+ }
506
+ return contextStack[contextStack.length - 1];
507
+ }
508
+ function setContext(context) {
509
+ contextStack.push(context);
510
+ }
511
+ function resetContext() {
512
+ contextStack.pop();
513
+ }
514
+
515
+ // src/jsx/client.ts
516
+ var import_core8 = require("@babel/core");
517
+
518
+ // src/signals/symbol.ts
519
+ var import_core5 = require("@babel/core");
520
+ function isSignal(name) {
521
+ return !!name && name.startsWith("$");
522
+ }
523
+ function replaceSymbol(path) {
524
+ const { init, id } = path.node;
525
+ if (!import_core5.types.isIdentifier(id)) {
526
+ return;
527
+ }
528
+ const variableName = id.name;
529
+ if (!isSignal(variableName)) {
530
+ return;
531
+ }
532
+ if (isAlreadySignalCall(init)) {
533
+ return;
534
+ }
535
+ const isComputed = init && (import_core5.types.isFunctionExpression(init) || import_core5.types.isArrowFunctionExpression(init)) && path.parent.kind === "const";
536
+ const importName = isComputed ? "computed" : "signal";
537
+ const state = path.state;
538
+ const args = init ? [init] : [];
539
+ const newInit = import_core5.types.callExpression(import_core5.types.identifier(state.imports[importName].name), args);
540
+ addImport(importName);
541
+ path.node.init = newInit;
542
+ }
543
+ function isAlreadySignalCall(init) {
544
+ if (!init || !import_core5.types.isCallExpression(init) || !import_core5.types.isIdentifier(init.callee)) {
545
+ return false;
546
+ }
547
+ const calleeName = init.callee.name;
548
+ return calleeName === "signal" || calleeName === "computed" || calleeName.includes("signal") || calleeName.includes("computed");
549
+ }
550
+ function symbolIdentifier(path) {
551
+ if (!isValidPath(path)) {
552
+ return;
553
+ }
554
+ const name = path.node.name;
555
+ if (!isSignal(name)) {
556
+ return;
557
+ }
558
+ if (!shouldProcessIdentifier(path, path.parentPath)) {
559
+ return;
560
+ }
561
+ if (isAlreadyValueAccess(path)) {
562
+ return;
563
+ }
564
+ path.replaceWith(import_core5.types.memberExpression(import_core5.types.identifier(name), import_core5.types.identifier("value")));
565
+ }
566
+ function shouldProcessIdentifier(path, parentPath) {
567
+ if (!parentPath) {
568
+ return false;
569
+ }
570
+ const parent = parentPath.node;
571
+ const currentNode = path.node;
572
+ if (import_core5.types.isVariableDeclarator(parent) || import_core5.types.isArrayPattern(parent) || import_core5.types.isObjectPattern(parent)) {
573
+ return false;
574
+ }
575
+ if (import_core5.types.isImportSpecifier(parent) || import_core5.types.isImportDefaultSpecifier(parent) || import_core5.types.isImportNamespaceSpecifier(parent)) {
576
+ return false;
577
+ }
578
+ if (import_core5.types.isFunctionDeclaration(parent) || import_core5.types.isFunctionExpression(parent) || import_core5.types.isArrowFunctionExpression(parent)) {
579
+ return false;
580
+ }
581
+ if (import_core5.types.isClassDeclaration(parent) && parent.id === currentNode) {
582
+ return false;
583
+ }
584
+ if (import_core5.types.isObjectMethod(parent) || import_core5.types.isClassMethod(parent)) {
585
+ return false;
586
+ }
587
+ if (import_core5.types.isObjectProperty(parent) && parent.key === currentNode) {
588
+ return false;
589
+ }
590
+ if (import_core5.types.isLabeledStatement(parent) && parent.label === currentNode) {
591
+ return false;
592
+ }
593
+ if ((import_core5.types.isBreakStatement(parent) || import_core5.types.isContinueStatement(parent)) && parent.label === currentNode) {
594
+ return false;
595
+ }
596
+ return true;
597
+ }
598
+ function isAlreadyValueAccess(path) {
599
+ const parent = path.parent;
600
+ if (import_core5.types.isMemberExpression(parent) && parent.object === path.node) {
601
+ return isMemberAccessingProperty(parent, "value");
602
+ }
603
+ if (!import_core5.types.isParenthesizedExpression(parent) && !import_core5.types.isTSAsExpression(parent) && !import_core5.types.isTSNonNullExpression(parent)) {
604
+ return false;
605
+ }
606
+ const ancestorCheck = path.findParent((p) => {
607
+ if (!p.isMemberExpression()) {
608
+ return false;
609
+ }
610
+ const memberExpr = p.node;
611
+ return memberExpr.object === path.node && isMemberAccessingProperty(memberExpr, "value");
120
612
  });
121
- const importSource = import_core.types.stringLiteral(from);
122
- return import_core.types.importDeclaration(ImportSpecifier, importSource);
613
+ return !!ancestorCheck;
614
+ }
615
+ function symbolAssignment(path) {
616
+ if (!isValidPath(path)) {
617
+ return;
618
+ }
619
+ const { left } = path.node;
620
+ if (!import_core5.types.isIdentifier(left)) {
621
+ return;
622
+ }
623
+ const name = left.name;
624
+ if (!isSignal(name)) {
625
+ return;
626
+ }
627
+ if (isAlreadyValueAssignment(left)) {
628
+ return;
629
+ }
630
+ path.node.left = import_core5.types.memberExpression(import_core5.types.identifier(name), import_core5.types.identifier("value"));
631
+ }
632
+ function isAlreadyValueAssignment(left) {
633
+ return import_core5.types.isMemberExpression(left) && isMemberAccessingProperty(left, "value");
634
+ }
635
+ function symbolUpdate(path) {
636
+ if (!isValidPath(path)) {
637
+ return;
638
+ }
639
+ const { argument } = path.node;
640
+ if (!import_core5.types.isIdentifier(argument)) {
641
+ return;
642
+ }
643
+ const name = argument.name;
644
+ if (!isSignal(name)) {
645
+ return;
646
+ }
647
+ if (isAlreadyValueUpdate(argument)) {
648
+ return;
649
+ }
650
+ path.node.argument = import_core5.types.memberExpression(import_core5.types.identifier(name), import_core5.types.identifier("value"));
651
+ }
652
+ function isAlreadyValueUpdate(argument) {
653
+ return import_core5.types.isMemberExpression(argument) && isMemberAccessingProperty(argument, "value");
654
+ }
655
+ function symbolObjectPattern(path) {
656
+ if (!isValidPath(path)) {
657
+ return;
658
+ }
659
+ const properties = path.node.properties;
660
+ if (!Array.isArray(properties) || properties.length === 0) {
661
+ return;
662
+ }
663
+ for (const property of properties) {
664
+ if (!property) continue;
665
+ if (import_core5.types.isObjectProperty(property)) {
666
+ handleObjectProperty(property, path);
667
+ } else if (import_core5.types.isRestElement(property)) {
668
+ handleRestElement(property, path);
669
+ }
670
+ }
671
+ }
672
+ function handleObjectProperty(property, parentPath) {
673
+ if (!property || !property.value) {
674
+ return;
675
+ }
676
+ const value = property.value;
677
+ if (import_core5.types.isObjectPattern(value)) {
678
+ const mockPath = {
679
+ node: value,
680
+ state: parentPath.state,
681
+ parentPath
682
+ };
683
+ symbolObjectPattern(mockPath);
684
+ } else if (import_core5.types.isArrayPattern(value)) {
685
+ const mockPath = {
686
+ node: value,
687
+ state: parentPath.state,
688
+ parentPath
689
+ };
690
+ symbolArrayPattern(mockPath);
691
+ } else if (import_core5.types.isAssignmentPattern(value)) {
692
+ handleAssignmentPattern(value, parentPath);
693
+ }
694
+ }
695
+ function handleAssignmentPattern(pattern, parentPath) {
696
+ const left = pattern.left;
697
+ if (import_core5.types.isObjectPattern(left)) {
698
+ const mockPath = {
699
+ node: left,
700
+ state: parentPath.state,
701
+ parentPath
702
+ };
703
+ symbolObjectPattern(mockPath);
704
+ } else if (import_core5.types.isArrayPattern(left)) {
705
+ const mockPath = {
706
+ node: left,
707
+ state: parentPath.state,
708
+ parentPath
709
+ };
710
+ symbolArrayPattern(mockPath);
711
+ }
712
+ }
713
+ function handleRestElement(restElement, parentPath) {
714
+ if (!restElement || !restElement.argument) {
715
+ return;
716
+ }
717
+ const argument = restElement.argument;
718
+ if (import_core5.types.isObjectPattern(argument)) {
719
+ const mockPath = {
720
+ node: argument,
721
+ state: parentPath.state,
722
+ parentPath
723
+ };
724
+ symbolObjectPattern(mockPath);
725
+ } else if (import_core5.types.isArrayPattern(argument)) {
726
+ const mockPath = {
727
+ node: argument,
728
+ state: parentPath.state,
729
+ parentPath
730
+ };
731
+ symbolArrayPattern(mockPath);
732
+ }
733
+ }
734
+ function symbolArrayPattern(path) {
735
+ if (!isValidPath(path)) {
736
+ return;
737
+ }
738
+ const elements = path.node.elements;
739
+ if (!Array.isArray(elements) || elements.length === 0) {
740
+ return;
741
+ }
742
+ for (const element of elements) {
743
+ if (!element) continue;
744
+ if (import_core5.types.isAssignmentPattern(element)) {
745
+ handleAssignmentPattern(element, path);
746
+ } else if (import_core5.types.isRestElement(element)) {
747
+ handleArrayRestElement(element, path);
748
+ } else if (import_core5.types.isObjectPattern(element)) {
749
+ const mockPath = {
750
+ node: element,
751
+ state: path.state,
752
+ parentPath: path
753
+ };
754
+ symbolObjectPattern(mockPath);
755
+ } else if (import_core5.types.isArrayPattern(element)) {
756
+ const mockPath = {
757
+ node: element,
758
+ state: path.state,
759
+ parentPath: path
760
+ };
761
+ symbolArrayPattern(mockPath);
762
+ }
763
+ }
764
+ }
765
+ function handleArrayRestElement(restElement, parentPath) {
766
+ if (!restElement || !restElement.argument) {
767
+ return;
768
+ }
769
+ const argument = restElement.argument;
770
+ if (import_core5.types.isArrayPattern(argument)) {
771
+ const mockPath = {
772
+ node: argument,
773
+ state: parentPath.state,
774
+ parentPath
775
+ };
776
+ symbolArrayPattern(mockPath);
777
+ } else if (import_core5.types.isObjectPattern(argument)) {
778
+ const mockPath = {
779
+ node: argument,
780
+ state: parentPath.state,
781
+ parentPath
782
+ };
783
+ symbolObjectPattern(mockPath);
784
+ }
123
785
  }
124
786
 
787
+ // src/jsx/constants.ts
788
+ var CLASS_NAME = "class";
789
+ var STYLE_NAME = "style";
790
+ var EVENT_ATTR_NAME = "on";
791
+ var UPDATE_PREFIX = "update";
792
+ var FRAGMENT_NAME = "Fragment";
793
+ var CHILDREN_NAME = "children";
794
+ var SPREAD_NAME = "_$spread$";
795
+ var CREATE_COMPONENT_NAME = "createComponent";
796
+ var BIND_REG = /^bind:.+/;
797
+ var BUILT_IN_COMPONENTS = ["Fragment", "Portal", "Suspense", "For"];
798
+
125
799
  // src/jsx/shared.ts
126
- var import_core2 = require("@babel/core");
127
- function createClientResult() {
800
+ var import_core7 = require("@babel/core");
801
+
802
+ // src/jsx/tree.ts
803
+ var import_core6 = require("@babel/core");
804
+ function createDefaultTree() {
128
805
  return {
806
+ root: true,
807
+ type: 0 /* NORMAL */,
808
+ tag: "",
809
+ props: {},
810
+ children: [],
129
811
  index: 1,
812
+ parentIndex: null,
130
813
  isLastChild: false,
131
- parentIndex: 0,
132
- props: {},
133
- template: ""
814
+ selfClosing: false,
815
+ _isTreeNode: true
134
816
  };
135
817
  }
136
- function createServerResult() {
137
- return {
138
- index: 1,
139
- isLastChild: false,
140
- parentIndex: 0,
141
- props: {},
142
- template: []
818
+ function isTreeNode(node) {
819
+ return !!(node && node._isTreeNode);
820
+ }
821
+ var treeIndex = 1;
822
+ function createTree(path, parentNode) {
823
+ const treeNode = createDefaultTree();
824
+ if (parentNode) {
825
+ const nodeInfo = path.node;
826
+ const isBuiltInComponent = BUILT_IN_COMPONENTS.includes(parentNode.tag);
827
+ const isComponentOrFragment = isComponentName(getTagName(nodeInfo));
828
+ if (!isComponentOrFragment && !isBuiltInComponent) {
829
+ treeNode.index = ++treeIndex;
830
+ }
831
+ if (isBuiltInComponent) {
832
+ treeIndex = 1;
833
+ }
834
+ treeNode.parentIndex = treeIndex;
835
+ } else {
836
+ treeNode.root = true;
837
+ treeIndex = 1;
838
+ }
839
+ if (import_core6.types.isJSXText(path.node)) {
840
+ return processJSXText(path, treeNode);
841
+ }
842
+ if (import_core6.types.isJSXElement(path.node) || import_core6.types.isJSXFragment(path.node)) {
843
+ return processJSXElement(path, treeNode);
844
+ }
845
+ return treeNode;
846
+ }
847
+ function processJSXElement(path, treeNode) {
848
+ const tagName = getTagName(path.node);
849
+ treeNode.tag = tagName;
850
+ treeNode.type = determineNodeType(tagName);
851
+ treeNode.selfClosing = Ne(tagName);
852
+ if (!path.isJSXFragment()) {
853
+ treeNode.props = processProps(path);
854
+ }
855
+ if (!treeNode.selfClosing) {
856
+ processChildren(path, treeNode);
857
+ }
858
+ return treeNode;
859
+ }
860
+ function processProps(path) {
861
+ const props = {};
862
+ const attributes = path.get("openingElement.attributes");
863
+ if (!attributes.length) {
864
+ return props;
865
+ }
866
+ attributes.forEach((attribute) => {
867
+ if (import_core6.types.isJSXAttribute(attribute.node)) {
868
+ const name = getAttrName(attribute.node);
869
+ const value = attribute.get("value");
870
+ if (!value.node) {
871
+ props[name] = true;
872
+ } else if (value) {
873
+ if (value.isJSXExpressionContainer()) {
874
+ const expression = value.get("expression");
875
+ if (expression.isStringLiteral() || expression.isNumericLiteral()) {
876
+ props[name] = expression.node.value;
877
+ } else if (expression.isJSXElement() || expression.isJSXFragment()) {
878
+ props[name] = expression.node;
879
+ } else if (expression.isExpression()) {
880
+ processPropsExpression(expression, name, props, path);
881
+ }
882
+ } else if (value.isStringLiteral() || value.isNumericLiteral()) {
883
+ props[name] = value.node.value;
884
+ } else if (value.isJSXElement() || value.isJSXFragment()) {
885
+ props[name] = value.node;
886
+ } else if (value.isExpression()) {
887
+ processPropsExpression(value, name, props, path);
888
+ }
889
+ }
890
+ } else if (import_core6.types.isJSXSpreadAttribute(attribute.node)) {
891
+ props[SPREAD_NAME] = attribute.get("argument").node;
892
+ }
893
+ });
894
+ return props;
895
+ }
896
+ function processPropsExpression(expression, name, props, path) {
897
+ if (BIND_REG.test(name)) {
898
+ processPropsBind(name, expression, props, path);
899
+ } else {
900
+ props[name] = expression.node;
901
+ }
902
+ }
903
+ function processPropsBind(name, expression, props, path) {
904
+ const value = path.scope.generateUidIdentifier("value");
905
+ const bindName = name.slice(5).toLowerCase();
906
+ props[`${UPDATE_PREFIX}:${bindName}`] = [
907
+ expression.node,
908
+ // Getter: the bound variable
909
+ import_core6.types.arrowFunctionExpression(
910
+ [value],
911
+ // Type guard: expression.node must be LVal for bind directive
912
+ import_core6.types.isLVal(expression.node) ? import_core6.types.assignmentExpression("=", expression.node, value) : import_core6.types.assignmentExpression("=", import_core6.types.identifier("_"), value)
913
+ // Fallback for invalid LVal
914
+ )
915
+ ];
916
+ }
917
+ function processChildren(path, treeNode) {
918
+ const children = path.node.children;
919
+ if (!children || !children.length) {
920
+ return;
921
+ }
922
+ const optimizedChildren = optimizeChildNodes(path.get("children"));
923
+ optimizedChildren.forEach((child) => {
924
+ processChild(child, treeNode, optimizedChildren.length === 1);
925
+ });
926
+ }
927
+ function processChild(child, treeNode, isLastChild) {
928
+ if (import_core6.types.isJSXElement(child.node) || import_core6.types.isJSXFragment(child.node)) {
929
+ const childNode = createTree(child, treeNode);
930
+ childNode.isLastChild = isLastChild;
931
+ treeNode.children.push(childNode);
932
+ return;
933
+ }
934
+ if (import_core6.types.isJSXExpressionContainer(child.node)) {
935
+ processChildExpressionContainer(
936
+ child,
937
+ treeNode,
938
+ isLastChild
939
+ );
940
+ return;
941
+ }
942
+ if (import_core6.types.isJSXText(child.node)) {
943
+ processJSXChildText(child, treeNode, isLastChild);
944
+ return;
945
+ }
946
+ if (import_core6.types.isJSXSpreadChild(child.node)) {
947
+ processChildSpread(child, treeNode, isLastChild);
948
+ return;
949
+ }
950
+ }
951
+ function processChildExpressionContainer(child, treeNode, isLastChild) {
952
+ const expression = child.get("expression");
953
+ if (expression.isStringLiteral() || expression.isNumericLiteral()) {
954
+ treeNode.children.push({
955
+ type: 2 /* TEXT */,
956
+ children: [String(expression.node.value)],
957
+ index: ++treeIndex,
958
+ // Static text increments index
959
+ parentIndex: treeNode.index,
960
+ isLastChild,
961
+ _isTreeNode: true
962
+ });
963
+ } else if (expression.isJSXElement() || expression.isJSXFragment()) {
964
+ const childNode = createTree(child, treeNode);
965
+ childNode.isLastChild = isLastChild;
966
+ treeNode.children.push(childNode);
967
+ } else if (expression.isExpression()) {
968
+ treeNode.children.push({
969
+ type: 4 /* EXPRESSION */,
970
+ index: treeIndex,
971
+ // Expression doesn't update index because it's dynamic content
972
+ isLastChild,
973
+ // Type guard: expression.node is Expression in JSXExpressionContainer
974
+ children: import_core6.types.isExpression(expression.node) ? [expression.node] : [],
975
+ parentIndex: treeNode.index,
976
+ _isTreeNode: true
977
+ });
978
+ }
979
+ }
980
+ function shouldInsertComment(childrenLength, previousNode) {
981
+ return !!(childrenLength >= 2 && // At least two child nodes
982
+ previousNode && // Previous node exists
983
+ previousNode.type !== 6 /* COMMENT */ && // Previous node is not a comment
984
+ // Previous node is dynamic content
985
+ (previousNode.type === 4 /* EXPRESSION */ || previousNode.type === 1 /* COMPONENT */));
986
+ }
987
+ function processJSXChildText(child, treeNode, isLastChild) {
988
+ const text = textTrim(child.node);
989
+ if (!text) {
990
+ return;
991
+ }
992
+ const childrenLength = treeNode.children.length;
993
+ const previousNode = treeNode.children[childrenLength - 1];
994
+ if (shouldInsertComment(childrenLength, previousNode)) {
995
+ const commentNode = {
996
+ type: 6 /* COMMENT */,
997
+ children: [],
998
+ index: ++treeIndex,
999
+ _isTreeNode: true
1000
+ };
1001
+ treeNode.children.push(commentNode);
1002
+ }
1003
+ const textNode = {
1004
+ type: 2 /* TEXT */,
1005
+ children: [text],
1006
+ index: ++treeIndex,
1007
+ isLastChild,
1008
+ _isTreeNode: true
1009
+ };
1010
+ treeNode.children.push(textNode);
1011
+ }
1012
+ function processChildSpread(child, treeNode, isLastChild) {
1013
+ const spreadExpression = child.get("expression");
1014
+ treeNode.children.push({
1015
+ type: 7 /* SPREAD */,
1016
+ // Type guard: spreadExpression.node is Expression in JSXSpreadChild
1017
+ children: import_core6.types.isExpression(spreadExpression.node) ? [spreadExpression.node] : [],
1018
+ index: treeIndex,
1019
+ // Note: doesn't increment here because this is dynamic content
1020
+ parentIndex: treeNode.index,
1021
+ isLastChild,
1022
+ _isTreeNode: true
1023
+ });
1024
+ }
1025
+ function determineNodeType(tagName) {
1026
+ const isComponent = isComponentName(tagName);
1027
+ if (isComponent) {
1028
+ return 1 /* COMPONENT */;
1029
+ }
1030
+ if (Me(tagName)) {
1031
+ return 5 /* SVG */;
1032
+ }
1033
+ return 0 /* NORMAL */;
1034
+ }
1035
+ function processJSXText(path, treeNode) {
1036
+ treeNode.type = 2 /* TEXT */;
1037
+ try {
1038
+ const textValue = textTrim(path.node);
1039
+ treeNode.children = textValue ? [textValue] : [];
1040
+ } catch (error) {
1041
+ ne(`Text node processing failed: ${error}`);
1042
+ treeNode.children = [];
1043
+ }
1044
+ return treeNode;
1045
+ }
1046
+
1047
+ // src/jsx/shared.ts
1048
+ function isComponentName(tagName) {
1049
+ if (!tagName) {
1050
+ return false;
1051
+ }
1052
+ const firstCharCode = tagName.charCodeAt(0);
1053
+ if (firstCharCode >= 65 && firstCharCode <= 90) {
1054
+ return true;
1055
+ }
1056
+ const dotIndex = tagName.indexOf(".");
1057
+ const colonIndex = tagName.indexOf(":");
1058
+ if (dotIndex !== -1 || colonIndex !== -1) {
1059
+ const segments = tagName.split(/[:.]/);
1060
+ const len = segments.length;
1061
+ for (let i = 0; i < len; i++) {
1062
+ const segment = segments[i];
1063
+ if (segment.length > 0) {
1064
+ const segmentCharCode = segment.charCodeAt(0);
1065
+ if (segmentCharCode >= 65 && segmentCharCode <= 90) {
1066
+ return true;
1067
+ }
1068
+ }
1069
+ }
1070
+ }
1071
+ return !(firstCharCode >= 97 && firstCharCode <= 122);
1072
+ }
1073
+ var getTagName = (node) => {
1074
+ if (import_core7.types.isJSXFragment(node)) {
1075
+ return FRAGMENT_NAME;
1076
+ }
1077
+ const tag = node.openingElement.name;
1078
+ return jsxElementNameToString(tag);
1079
+ };
1080
+ function jsxElementNameToString(node) {
1081
+ var _a, _b, _c, _d;
1082
+ if (import_core7.types.isJSXMemberExpression(node)) {
1083
+ return `${jsxElementNameToString(node.object)}.${jsxElementNameToString(node.property)}`;
1084
+ }
1085
+ if (import_core7.types.isMemberExpression(node)) {
1086
+ const objectName = jsxElementNameToString(
1087
+ node.object
1088
+ );
1089
+ const propertyName = jsxElementNameToString(
1090
+ node.property
1091
+ );
1092
+ return `${objectName}.${propertyName}`;
1093
+ }
1094
+ if (import_core7.types.isJSXIdentifier(node) || import_core7.types.isIdentifier(node)) {
1095
+ return node.name;
1096
+ }
1097
+ const namespace = (_b = (_a = node.namespace) == null ? void 0 : _a.name) != null ? _b : "";
1098
+ const name = (_d = (_c = node.name) == null ? void 0 : _c.name) != null ? _d : "";
1099
+ if (!namespace) {
1100
+ return name;
1101
+ }
1102
+ if (!name) {
1103
+ return namespace;
1104
+ }
1105
+ return `${namespace}:${name}`;
1106
+ }
1107
+ function textTrim(node) {
1108
+ if (!node || !node.value) return "";
1109
+ return node.value.trim();
1110
+ }
1111
+ function isValidChild(path) {
1112
+ const regex = /^\s*$/;
1113
+ if (import_core7.types.isStringLiteral(path.node)) {
1114
+ return !regex.test(path.node.value);
1115
+ }
1116
+ if (import_core7.types.isJSXText(path.node)) {
1117
+ return !regex.test(path.node.value);
1118
+ }
1119
+ return Object.keys(path.node).length > 0;
1120
+ }
1121
+ function getRawNodeText(path) {
1122
+ if (path.isJSXText()) {
1123
+ return path.node.value || "";
1124
+ }
1125
+ if (path.isJSXExpressionContainer()) {
1126
+ const expression = path.get("expression");
1127
+ if (expression.isStringLiteral() || expression.isNumericLiteral()) {
1128
+ return String(expression.node.value);
1129
+ }
1130
+ }
1131
+ return "";
1132
+ }
1133
+ function setNodeText(path, text) {
1134
+ if (path.isJSXText()) {
1135
+ path.node.value = text;
1136
+ }
1137
+ if (path.isJSXExpressionContainer()) {
1138
+ const expression = path.get("expression");
1139
+ if (expression.isStringLiteral() || expression.isNumericLiteral()) {
1140
+ expression.replaceWith(import_core7.types.stringLiteral(text));
1141
+ }
1142
+ }
1143
+ }
1144
+ function optimizeChildNodes(children) {
1145
+ const mergedWithExpression = /* @__PURE__ */ new WeakSet();
1146
+ return children.reduce((acc, cur) => {
1147
+ var _a, _b, _c, _d;
1148
+ if (isValidChild(cur)) {
1149
+ const lastChild = acc.at(-1);
1150
+ if (!lastChild) {
1151
+ acc.push(cur);
1152
+ return acc;
1153
+ }
1154
+ const lastIsPlainText = (_b = (_a = lastChild.isJSXText) == null ? void 0 : _a.call(lastChild)) != null ? _b : false;
1155
+ const currentIsPlainText = (_d = (_c = cur.isJSXText) == null ? void 0 : _c.call(cur)) != null ? _d : false;
1156
+ if (lastIsPlainText && import_core7.types.isJSXExpressionContainer(cur.node) && (cur.get("expression").isStringLiteral() || cur.get("expression").isNumericLiteral()) && !mergedWithExpression.has(lastChild)) {
1157
+ const mergedText = getRawNodeText(lastChild) + getRawNodeText(cur);
1158
+ setNodeText(lastChild, mergedText);
1159
+ mergedWithExpression.add(lastChild);
1160
+ return acc;
1161
+ }
1162
+ if (lastIsPlainText && currentIsPlainText && !mergedWithExpression.has(lastChild)) {
1163
+ const mergedText = getRawNodeText(lastChild) + getRawNodeText(cur);
1164
+ setNodeText(lastChild, mergedText);
1165
+ return acc;
1166
+ }
1167
+ acc.push(cur);
1168
+ }
1169
+ return acc;
1170
+ }, []);
1171
+ }
1172
+ function deepCheckObjectDynamic(node) {
1173
+ if (!import_core7.types.isObjectExpression(node)) return false;
1174
+ let dynamic = false;
1175
+ function walk(current) {
1176
+ if (dynamic) return;
1177
+ if (import_core7.types.isIdentifier(current) || import_core7.types.isCallExpression(current) || import_core7.types.isMemberExpression(current) || import_core7.types.isConditionalExpression(current) || import_core7.types.isTemplateLiteral(current) || import_core7.types.isBinaryExpression(current) || import_core7.types.isUpdateExpression(current) || import_core7.types.isUnaryExpression(current) || import_core7.types.isAwaitExpression(current) || import_core7.types.isYieldExpression(current) || import_core7.types.isTaggedTemplateExpression(current)) {
1178
+ dynamic = true;
1179
+ return;
1180
+ }
1181
+ if (import_core7.types.isObjectExpression(current)) {
1182
+ current.properties.forEach((prop) => {
1183
+ if (import_core7.types.isObjectProperty(prop)) walk(prop.value);
1184
+ if (import_core7.types.isSpreadElement(prop)) walk(prop.argument);
1185
+ });
1186
+ return;
1187
+ }
1188
+ if (import_core7.types.isArrayExpression(current)) {
1189
+ current.elements.forEach((el) => el && walk(el));
1190
+ return;
1191
+ }
1192
+ }
1193
+ walk(node);
1194
+ return dynamic;
1195
+ }
1196
+ function processObjectExpression(propName, objectExpr, propsCollection, isClassOrStyleAttr = false) {
1197
+ let classStyleString = "";
1198
+ if (deepCheckObjectDynamic(objectExpr)) {
1199
+ propsCollection[propName] = objectExpr;
1200
+ } else if (isClassOrStyleAttr) {
1201
+ classStyleString = objectExpr.properties.filter((property) => import_core7.types.isObjectProperty(property)).reduce((acc, property) => {
1202
+ const key = import_core7.types.isIdentifier(property.key) ? property.key.name : import_core7.types.isStringLiteral(property.key) ? property.key.value : String(property.key);
1203
+ if (import_core7.types.isStringLiteral(property.value)) {
1204
+ return `${acc}${key}:${property.value.value};`;
1205
+ }
1206
+ return acc;
1207
+ }, "");
1208
+ delete propsCollection[propName];
1209
+ }
1210
+ return classStyleString;
1211
+ }
1212
+ function getAttrName(attribute) {
1213
+ if (import_core7.types.isJSXIdentifier(attribute.name)) {
1214
+ return attribute.name.name;
1215
+ }
1216
+ if (import_core7.types.isJSXNamespacedName(attribute.name)) {
1217
+ return `${attribute.name.namespace.name}:${attribute.name.name.name}`;
1218
+ }
1219
+ return "";
1220
+ }
1221
+ function serializeAttributes(attributes) {
1222
+ if (!attributes || !w(attributes)) {
1223
+ return "";
1224
+ }
1225
+ let attributesString = "";
1226
+ let classNames = "";
1227
+ let styleString = "";
1228
+ for (const [attrName, attrValue] of Object.entries(attributes)) {
1229
+ if (attrName === CLASS_NAME && m(attrValue)) {
1230
+ classNames += ` ${attrValue}`;
1231
+ delete attributes[attrName];
1232
+ } else if (attrName === STYLE_NAME && m(attrValue)) {
1233
+ styleString += `${attrValue}${attrValue.at(-1) === ";" ? "" : ";"}`;
1234
+ delete attributes[attrName];
1235
+ } else if (attrValue === true) {
1236
+ attributesString += ` ${attrName}`;
1237
+ delete attributes[attrName];
1238
+ } else if (attrValue === false) {
1239
+ delete attributes[attrName];
1240
+ } else if (m(attrValue) || T(attrValue)) {
1241
+ attributesString += ` ${attrName}="${attrValue}"`;
1242
+ delete attributes[attrName];
1243
+ } else if (import_core7.types.isConditionalExpression(attrValue)) {
1244
+ attributes[attrName] = attrValue;
1245
+ } else if (import_core7.types.isObjectExpression(attrValue)) {
1246
+ const result = processObjectExpression(
1247
+ attrName,
1248
+ attrValue,
1249
+ attributes,
1250
+ attrName === CLASS_NAME || attrName === STYLE_NAME
1251
+ );
1252
+ if (result) {
1253
+ if (attrName === CLASS_NAME) {
1254
+ classNames += ` ${result}`;
1255
+ }
1256
+ if (attrName === STYLE_NAME) {
1257
+ styleString += `${result}${result.at(-1) === ";" ? "" : ";"}`;
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ if (classNames.trim()) {
1263
+ attributesString += ` ${CLASS_NAME}="${classNames.trim()}"`;
1264
+ }
1265
+ if (styleString.trim()) {
1266
+ attributesString += ` ${STYLE_NAME}="${styleString.trim()}"`;
1267
+ }
1268
+ return attributesString;
1269
+ }
1270
+ function findBeforeIndex(currentNode, parentNode) {
1271
+ var _a;
1272
+ if (!((_a = parentNode == null ? void 0 : parentNode.children) == null ? void 0 : _a.length) || currentNode.isLastChild) {
1273
+ return null;
1274
+ }
1275
+ const children = parentNode.children;
1276
+ const childrenLength = children.length;
1277
+ let nodeIndex = -1;
1278
+ for (let i = 0; i < childrenLength; i++) {
1279
+ if (children[i] === currentNode) {
1280
+ nodeIndex = i;
1281
+ break;
1282
+ }
1283
+ }
1284
+ if (nodeIndex === -1 || nodeIndex === childrenLength - 1) {
1285
+ return null;
1286
+ }
1287
+ for (let searchIndex = nodeIndex + 1; searchIndex < childrenLength; searchIndex++) {
1288
+ const siblingNode = children[searchIndex];
1289
+ const siblingType = siblingNode.type;
1290
+ if (siblingType !== 4 /* EXPRESSION */ && siblingType !== 3 /* FRAGMENT */ && siblingType !== 1 /* COMPONENT */) {
1291
+ return siblingNode.index;
1292
+ }
1293
+ }
1294
+ return null;
1295
+ }
1296
+ function findIndexPosition(targetIndex, indexMap) {
1297
+ if (d(indexMap)) {
1298
+ return indexMap.indexOf(targetIndex);
1299
+ }
1300
+ if (E(indexMap)) {
1301
+ const position = indexMap.get(targetIndex);
1302
+ return T(position) ? position : -1;
1303
+ }
1304
+ return -1;
1305
+ }
1306
+ function normalizeProps(raw) {
1307
+ const normalized = {};
1308
+ const classBuffer = [];
1309
+ const styleBuffer = [];
1310
+ for (const [key, value] of Object.entries(raw)) {
1311
+ if (key === CLASS_NAME || key === "className") {
1312
+ if (m(value)) classBuffer.push(value);
1313
+ else {
1314
+ normalized[CLASS_NAME] = value;
1315
+ }
1316
+ continue;
1317
+ }
1318
+ if (key === STYLE_NAME) {
1319
+ if (m(value)) styleBuffer.push(value);
1320
+ else normalized[STYLE_NAME] = value;
1321
+ continue;
1322
+ }
1323
+ if (key === SPREAD_NAME) {
1324
+ if (!normalized[SPREAD_NAME]) normalized[SPREAD_NAME] = [];
1325
+ normalized[SPREAD_NAME].push(value);
1326
+ continue;
1327
+ }
1328
+ normalized[key] = value;
1329
+ }
1330
+ if (classBuffer.length) normalized[CLASS_NAME] = classBuffer.join(" ").trim();
1331
+ if (styleBuffer.length) {
1332
+ const s = styleBuffer.map((str) => str.endsWith(";") ? str : `${str};`).join("");
1333
+ normalized[STYLE_NAME] = s;
1334
+ }
1335
+ return normalized;
1336
+ }
1337
+ function createPropsObjectExpression(propsData, transformJSX2) {
1338
+ const objectProperties = [];
1339
+ const propsToProcess = normalizeProps(propsData);
1340
+ for (const propName in propsToProcess) {
1341
+ const propValue = propsToProcess[propName];
1342
+ if (propName === CHILDREN_NAME && (!propValue || d(propValue) && !propValue.length)) {
1343
+ continue;
1344
+ }
1345
+ const astValue = convertValueToASTNode(propValue, transformJSX2);
1346
+ if (propName === SPREAD_NAME) {
1347
+ objectProperties.push(import_core7.types.spreadElement(astValue));
1348
+ } else {
1349
+ objectProperties.push(import_core7.types.objectProperty(import_core7.types.stringLiteral(propName), astValue));
1350
+ }
1351
+ }
1352
+ return import_core7.types.objectExpression(objectProperties);
1353
+ }
1354
+ function convertValueToASTNode(value, transformJSX2) {
1355
+ if (import_core7.types.isExpression(value)) {
1356
+ return value;
1357
+ }
1358
+ if (d(value)) {
1359
+ return import_core7.types.arrayExpression(value.map((item) => convertValueToASTNode(item, transformJSX2)));
1360
+ }
1361
+ if (w(value)) {
1362
+ if (isTreeNode(value) && hasPureStringChildren(value)) {
1363
+ const stringContent = extractStringChildren(value);
1364
+ return import_core7.types.stringLiteral(stringContent);
1365
+ }
1366
+ if (value.type === 1 /* COMPONENT */ || value.type === 0 /* NORMAL */ || value.type === 2 /* TEXT */ || value.type === 5 /* SVG */) {
1367
+ const { path } = getContext();
1368
+ return transformJSX2(path, value);
1369
+ }
1370
+ if (value.type === 4 /* EXPRESSION */ && value.children && d(value.children) && value.children.length > 0) {
1371
+ return convertValueToASTNode(value.children[0], transformJSX2);
1372
+ }
1373
+ if (import_core7.types.isJSXElement(value) || import_core7.types.isJSXFragment(value)) {
1374
+ const { path } = getContext();
1375
+ const mockNodePath = {
1376
+ node: value,
1377
+ parentPath: path,
1378
+ // Keep parent path reference
1379
+ scope: path.scope
1380
+ // Keep scope reference
1381
+ };
1382
+ const tree = createTree(mockNodePath);
1383
+ return transformJSX2(path, tree);
1384
+ }
1385
+ return createPropsObjectExpression(value, transformJSX2);
1386
+ }
1387
+ if (m(value)) {
1388
+ return import_core7.types.stringLiteral(value);
1389
+ }
1390
+ if (T(value)) {
1391
+ return import_core7.types.numericLiteral(value);
1392
+ }
1393
+ if (z(value)) {
1394
+ return import_core7.types.booleanLiteral(value);
1395
+ }
1396
+ if (_(value)) {
1397
+ return import_core7.types.identifier("undefined");
1398
+ }
1399
+ if (y(value)) {
1400
+ return import_core7.types.nullLiteral();
1401
+ }
1402
+ return value;
1403
+ }
1404
+ function getSetFunctionForAttribute(attrName) {
1405
+ const { state } = getContext();
1406
+ switch (attrName) {
1407
+ case CLASS_NAME:
1408
+ return {
1409
+ name: "patchClass",
1410
+ value: state.imports.patchClass
1411
+ };
1412
+ case STYLE_NAME:
1413
+ return { name: "patchStyle", value: state.imports.patchStyle };
1414
+ default:
1415
+ return { name: "patchAttr", value: state.imports.patchAttr };
1416
+ }
1417
+ }
1418
+ function isDynamicExpression(node) {
1419
+ if (!node) return false;
1420
+ if (import_core7.types.isIdentifier(node) || import_core7.types.isMemberExpression(node) || import_core7.types.isOptionalMemberExpression(node) || import_core7.types.isCallExpression(node) || import_core7.types.isOptionalCallExpression(node) || import_core7.types.isConditionalExpression(node) || import_core7.types.isLogicalExpression(node) || import_core7.types.isTemplateLiteral(node) || import_core7.types.isTaggedTemplateExpression(node) || import_core7.types.isBinaryExpression(node) || import_core7.types.isUnaryExpression(node) || import_core7.types.isUpdateExpression(node) || import_core7.types.isAwaitExpression(node) || import_core7.types.isYieldExpression(node) || import_core7.types.isAssignmentExpression(node) || import_core7.types.isSequenceExpression(node) || import_core7.types.isArrowFunctionExpression(node) || import_core7.types.isFunctionExpression(node)) {
1421
+ return true;
1422
+ }
1423
+ if (import_core7.types.isObjectExpression(node)) {
1424
+ return deepCheckObjectDynamic(node);
1425
+ }
1426
+ if (import_core7.types.isArrayExpression(node)) {
1427
+ return node.elements.some((el) => el != null && import_core7.types.isNode(el) && isDynamicExpression(el));
1428
+ }
1429
+ if (import_core7.types.isStringLiteral(node) || import_core7.types.isNumericLiteral(node) || import_core7.types.isBooleanLiteral(node) || import_core7.types.isNullLiteral(node) || import_core7.types.isRegExpLiteral(node)) {
1430
+ return false;
1431
+ }
1432
+ return import_core7.types.isExpression(node);
1433
+ }
1434
+ function hasPureStringChildren(node) {
1435
+ if (!node.children || node.children.length === 0) {
1436
+ return false;
1437
+ }
1438
+ return node.children.every((child) => {
1439
+ if (m(child)) {
1440
+ return true;
1441
+ }
1442
+ if (isTreeNode(child) && child.type === 2 /* TEXT */) {
1443
+ return true;
1444
+ }
1445
+ return false;
1446
+ });
1447
+ }
1448
+ function extractStringChildren(node) {
1449
+ if (!node.children || node.children.length === 0) {
1450
+ return "";
1451
+ }
1452
+ return node.children.map((child) => {
1453
+ if (m(child)) {
1454
+ return child;
1455
+ }
1456
+ if (isTreeNode(child) && child.type === 2 /* TEXT */ && child.children) {
1457
+ return child.children.join("");
1458
+ }
1459
+ return "";
1460
+ }).join("");
1461
+ }
1462
+
1463
+ // src/jsx/client.ts
1464
+ function transformJSXToClient(path, node) {
1465
+ const state = path.state;
1466
+ if (node.type === 1 /* COMPONENT */) {
1467
+ const props = __spreadProps(__spreadValues({}, node.props), { children: node.children });
1468
+ return createComponentExpression(node, props);
1469
+ }
1470
+ const staticTemplate = generateStaticTemplate(node);
1471
+ const dynamicCollection = generateDynamic(node);
1472
+ const indexMap = generateIndexMap(dynamicCollection);
1473
+ const elementId = path.scope.generateUidIdentifier("_$el");
1474
+ const nodesId = path.scope.generateUidIdentifier("_$nodes");
1475
+ const statements = [];
1476
+ if (staticTemplate) {
1477
+ addImport(importMap.template);
1478
+ const tmplId = path.scope.generateUidIdentifier("_$tmpl");
1479
+ state.declarations.push(
1480
+ import_core8.types.variableDeclarator(
1481
+ tmplId,
1482
+ import_core8.types.callExpression(state.imports.template, G(staticTemplate).map(import_core8.types.stringLiteral))
1483
+ )
1484
+ );
1485
+ statements.push(
1486
+ import_core8.types.variableDeclaration("const", [
1487
+ import_core8.types.variableDeclarator(elementId, import_core8.types.callExpression(tmplId, []))
1488
+ ])
1489
+ );
1490
+ }
1491
+ if (dynamicCollection.children.length || dynamicCollection.props.length) {
1492
+ addImport(importMap.mapNodes);
1493
+ statements.push(
1494
+ import_core8.types.variableDeclaration("const", [
1495
+ import_core8.types.variableDeclarator(
1496
+ nodesId,
1497
+ import_core8.types.callExpression(state.imports.mapNodes, [
1498
+ elementId,
1499
+ import_core8.types.arrayExpression(indexMap.map((idx) => import_core8.types.numericLiteral(idx)))
1500
+ ])
1501
+ )
1502
+ ])
1503
+ );
1504
+ if (dynamicCollection.children.length) {
1505
+ generateDynamicChildrenCode(dynamicCollection.children, statements, state, nodesId, indexMap);
1506
+ }
1507
+ if (dynamicCollection.props.length) {
1508
+ generateDynamicPropsCode(dynamicCollection.props, statements, state, nodesId, indexMap);
1509
+ }
1510
+ if (dynamicCollection.operations.length) {
1511
+ generateUnifiedMemoizedEffect(
1512
+ dynamicCollection.operations,
1513
+ statements,
1514
+ state,
1515
+ nodesId,
1516
+ indexMap
1517
+ );
1518
+ }
1519
+ }
1520
+ statements.push(import_core8.types.returnStatement(elementId));
1521
+ return import_core8.types.callExpression(import_core8.types.arrowFunctionExpression([], import_core8.types.blockStatement(statements)), []);
1522
+ }
1523
+ function generatePropKey(attrName = "attr") {
1524
+ const { operationIndex } = getContext();
1525
+ const keyMap = {
1526
+ [CLASS_NAME]: "c",
1527
+ [STYLE_NAME]: "s",
1528
+ name: "n",
1529
+ attr: "a"
143
1530
  };
1531
+ const baseKey = keyMap[attrName] || attrName.charAt(0);
1532
+ setContext(__spreadProps(__spreadValues({}, getContext()), { operationIndex: operationIndex + 1 }));
1533
+ setContext(__spreadProps(__spreadValues({}, getContext()), { operationIndex: operationIndex + 1 }));
1534
+ return `${baseKey}${operationIndex}`;
144
1535
  }
145
- function hasSiblingElement(path) {
146
- const siblings = path.getAllPrevSiblings().concat(path.getAllNextSiblings());
147
- const hasSibling = siblings.some(
148
- (siblingPath) => siblingPath.isJSXElement() || siblingPath.isJSXExpressionContainer()
149
- );
150
- return hasSibling;
1536
+ function transformJSXClientChildren(path, treeNode) {
1537
+ return transformJSXToClient(path, treeNode);
151
1538
  }
152
- function getAttrName(attribute) {
153
- if (import_core2.types.isJSXIdentifier(attribute.name)) {
154
- return attribute.name.name;
155
- }
156
- if (import_core2.types.isJSXNamespacedName(attribute.name)) {
157
- return `${attribute.name.namespace.name}:${attribute.name.name.name}`;
1539
+ function createComponentExpression(node, componentProps) {
1540
+ const { state } = getContext();
1541
+ addImport(importMap.createComponent);
1542
+ const isBuiltIn = BUILT_IN_COMPONENTS.includes(node.tag);
1543
+ if (isBuiltIn) {
1544
+ addImport(importMap[node.tag]);
158
1545
  }
159
- throw new Error("Unsupported attribute type");
160
- }
161
- function getTagName(node) {
162
- const tag = node.openingElement.name;
163
- return jsxElementNameToString(tag);
1546
+ const argTag = isBuiltIn ? state.imports[node.tag] : import_core8.types.identifier(node.tag);
1547
+ const propsObj = createPropsObjectExpression(componentProps, transformJSXClientChildren);
1548
+ const args = [argTag, propsObj];
1549
+ return import_core8.types.callExpression(state.imports[CREATE_COMPONENT_NAME], args);
164
1550
  }
165
- function jsxElementNameToString(node) {
166
- if (import_core2.types.isJSXMemberExpression(node)) {
167
- return `${jsxElementNameToString(node.object)}.${jsxElementNameToString(node.property)}`;
1551
+ function generateIndexMap({
1552
+ props,
1553
+ children,
1554
+ operations = []
1555
+ }) {
1556
+ const indexSet = /* @__PURE__ */ new Set();
1557
+ for (const item of children) {
1558
+ if (!N(item.parentIndex)) {
1559
+ indexSet.add(item.parentIndex);
1560
+ }
1561
+ if (!N(item.before)) {
1562
+ indexSet.add(item.before);
1563
+ }
168
1564
  }
169
- if (import_core2.types.isJSXIdentifier(node) || import_core2.types.isIdentifier(node)) {
170
- return node.name;
1565
+ for (const item of props) {
1566
+ if (!N(item.parentIndex)) {
1567
+ indexSet.add(item.parentIndex);
1568
+ }
171
1569
  }
172
- return `${node.namespace.name}:${node.name.name}`;
173
- }
174
- function isComponentName(tagName) {
175
- return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-z]/i.test(tagName[0]);
176
- }
177
- function isTextChild(path) {
178
- if (path.isJSXExpressionContainer()) {
179
- const expression = path.get("expression");
180
- if (expression.isJSXText() || expression.isStringLiteral() || expression.isNumericLiteral()) {
181
- return true;
1570
+ if (operations && operations.length > 0) {
1571
+ for (const item of operations) {
1572
+ if (!N(item.nodeIndex)) {
1573
+ indexSet.add(item.nodeIndex);
1574
+ }
182
1575
  }
183
1576
  }
184
- if (path.isJSXText() || path.isStringLiteral() || path.isNullLiteral()) {
185
- return true;
1577
+ const indexMap = Array.from(indexSet).sort((a2, b) => a2 - b);
1578
+ if (true) {
1579
+ for (const index of indexMap) {
1580
+ if (!Number.isInteger(index) || index < 1) {
1581
+ ne(`Invalid index in index map: ${index}. All indices must be positive integers.`);
1582
+ }
1583
+ }
186
1584
  }
187
- return false;
1585
+ return indexMap;
188
1586
  }
189
- function setNodeText(path, text) {
190
- if (path.isJSXText()) {
191
- path.node.value = text;
1587
+ function createAttributeStatement(functionIdentifier, nodesId, nodeIndex, value, key) {
1588
+ const args = [import_core8.types.memberExpression(nodesId, import_core8.types.numericLiteral(nodeIndex), true)];
1589
+ if (key) {
1590
+ args.push(key);
192
1591
  }
193
- if (path.isJSXExpressionContainer()) {
194
- const expression = path.get("expression");
195
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
196
- expression.replaceWith(import_core2.types.stringLiteral(text));
1592
+ if (value) {
1593
+ if (d(value)) {
1594
+ args.push(...value);
1595
+ } else {
1596
+ args.push(value);
197
1597
  }
198
1598
  }
1599
+ const functionCall = import_core8.types.callExpression(functionIdentifier, args);
1600
+ return import_core8.types.expressionStatement(functionCall);
199
1601
  }
200
- function replaceSpace(node) {
201
- return node.value.replaceAll(/\s+/g, " ").trim();
202
- }
203
- function isValidChild(path) {
204
- const regex = /^\s*$/;
205
- if (path.isStringLiteral() || path.isJSXText()) {
206
- return !regex.test(path.node.value);
1602
+ function addEventListenerStatement(attrName, attrValue, nodesId, nodeIndex, statements, state) {
1603
+ var _a;
1604
+ const eventName = attrName.slice(2).toLowerCase();
1605
+ if (Oe(eventName)) {
1606
+ const activeContext = getContext();
1607
+ if (!activeContext) {
1608
+ ne("Missing active context, unable to handle delegated events");
1609
+ return;
1610
+ }
1611
+ const elementRef = import_core8.types.memberExpression(nodesId, import_core8.types.numericLiteral(nodeIndex), true);
1612
+ const eventProperty = import_core8.types.memberExpression(elementRef, import_core8.types.stringLiteral(`_$${eventName}`), true);
1613
+ const assignmentStmt = import_core8.types.expressionStatement(
1614
+ import_core8.types.assignmentExpression("=", eventProperty, attrValue)
1615
+ );
1616
+ statements.push(assignmentStmt);
1617
+ (_a = state.events) == null ? void 0 : _a.add(eventName);
1618
+ return;
207
1619
  }
208
- return Object.keys(path.node).length > 0;
209
- }
210
- function hasObjectExpression(prop, value, props, state, isCt = false) {
211
- let ct = "";
212
- const hasConditional = value.properties.some(
213
- (property) => import_core2.types.isObjectProperty(property) && import_core2.types.isConditionalExpression(property.value)
1620
+ addImport(importMap.addEventListener);
1621
+ const eventListenerStmt = createAttributeStatement(
1622
+ state.imports.addEventListener,
1623
+ nodesId,
1624
+ nodeIndex,
1625
+ attrValue,
1626
+ import_core8.types.stringLiteral(eventName)
214
1627
  );
215
- if (hasConditional) {
216
- imports.add("useComputed");
217
- props[prop] = import_core2.types.callExpression(state.useComputed, [import_core2.types.arrowFunctionExpression([], value)]);
218
- } else if (isCt) {
219
- value.properties.forEach((property) => {
220
- if (import_core2.types.isObjectProperty(property)) {
221
- ct += `${property.key.name || property.key.value}:${property.value.value};`;
1628
+ statements.push(eventListenerStmt);
1629
+ }
1630
+ function generateSpecificAttributeCode(attributeName, attributeValue, nodesId, nodeIndex, statements, state) {
1631
+ switch (attributeName) {
1632
+ case CLASS_NAME:
1633
+ addImport(importMap.patchClass);
1634
+ statements.push(
1635
+ createAttributeStatement(state.imports.patchClass, nodesId, nodeIndex, attributeValue)
1636
+ );
1637
+ break;
1638
+ case SPREAD_NAME:
1639
+ addImport(importMap.setSpread);
1640
+ statements.push(
1641
+ createAttributeStatement(state.imports.setSpread, nodesId, nodeIndex, attributeValue)
1642
+ );
1643
+ break;
1644
+ case STYLE_NAME:
1645
+ addImport(importMap.patchStyle);
1646
+ statements.push(
1647
+ createAttributeStatement(state.imports.patchStyle, nodesId, nodeIndex, attributeValue)
1648
+ );
1649
+ break;
1650
+ default:
1651
+ if (q(attributeName, `${UPDATE_PREFIX}:`)) {
1652
+ addImport(importMap.bindElement);
1653
+ const attrName = attributeName.split(":")[1];
1654
+ statements.push(
1655
+ createAttributeStatement(
1656
+ state.imports.bindElement,
1657
+ nodesId,
1658
+ nodeIndex,
1659
+ attributeValue,
1660
+ import_core8.types.stringLiteral(attrName)
1661
+ )
1662
+ );
1663
+ return;
222
1664
  }
223
- });
224
- delete props[prop];
1665
+ addImport(importMap.patchAttr);
1666
+ statements.push(
1667
+ createAttributeStatement(
1668
+ state.imports.patchAttr,
1669
+ nodesId,
1670
+ nodeIndex,
1671
+ attributeValue,
1672
+ import_core8.types.stringLiteral(attributeName)
1673
+ )
1674
+ );
1675
+ break;
225
1676
  }
226
- return ct;
227
1677
  }
228
- function getNodeText(path) {
229
- if (path.isJSXText()) {
230
- return replaceSpace(path.node);
231
- }
232
- if (path.isJSXExpressionContainer()) {
233
- const expression = path.get("expression");
234
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
235
- return String(expression.node.value);
1678
+ function processIIFEExpression(node) {
1679
+ if (import_core8.types.isCallExpression(node) && (import_core8.types.isArrowFunctionExpression(node.callee) || import_core8.types.isFunctionExpression(node.callee)) && node.arguments.length === 0) {
1680
+ const callee = node.callee;
1681
+ const body = callee.body;
1682
+ if (import_core8.types.isBlockStatement(body)) {
1683
+ if (body.body.length === 1) {
1684
+ const statement = body.body[0];
1685
+ if (import_core8.types.isReturnStatement(statement) && statement.argument) {
1686
+ return statement.argument;
1687
+ }
1688
+ }
1689
+ } else if (import_core8.types.isExpression(body)) {
1690
+ return body;
236
1691
  }
237
1692
  }
238
- return "";
1693
+ return node;
239
1694
  }
240
-
241
- // src/jsx/constants.ts
242
- var selfClosingTags = [
243
- "area",
244
- "base",
245
- "br",
246
- "col",
247
- "embed",
248
- "hr",
249
- "img",
250
- "input",
251
- "link",
252
- "meta",
253
- "param",
254
- "source",
255
- "track",
256
- "wbr"
257
- ];
258
- var svgTags = [
259
- "circle",
260
- "clipPath",
261
- "defs",
262
- "ellipse",
263
- "filter",
264
- "g",
265
- "line",
266
- "linearGradient",
267
- "mask",
268
- "path",
269
- "pattern",
270
- "polygon",
271
- "polyline",
272
- "radialGradient",
273
- "rect",
274
- "stop",
275
- "symbol",
276
- "text",
277
- "use"
278
- ];
279
-
280
- // src/jsx/index.ts
281
- var currentResult;
282
- var isServer = false;
283
- function addTemplate(content, join = false) {
284
- if (isServer) {
285
- if (join && currentResult.template.length > 0) {
286
- currentResult.template[currentResult.template.length - 1] += content;
287
- } else {
288
- currentResult.template.push(content);
289
- }
290
- } else {
291
- currentResult.template += content;
1695
+ function createInsertArguments(dynamicContent, nodesIdentifier, indexMap) {
1696
+ if (N(dynamicContent.parentIndex)) {
1697
+ throw new Error("Dynamic content missing valid parent node index");
292
1698
  }
293
- }
294
- function transformJSX(path) {
295
- var _a, _b;
296
- isServer = (_b = (_a = path.state) == null ? void 0 : _a.opts) == null ? void 0 : _b.server;
297
- const preCurrentResult = currentResult;
298
- currentResult = isServer ? createServerResult() : createClientResult();
299
- transformJSXElement(path, isServer, true);
300
- path.replaceWith(isServer ? createServerNode(path) : createClientNode(path));
301
- currentResult = preCurrentResult;
302
- }
303
- function createClientNode(path) {
304
- var _a, _b;
305
- const state = path.state;
306
- const isJSXFragment = path.isJSXFragment();
307
- const isComponent = path.isJSXElement() && isComponentName(getTagName(path.node));
308
- const tmpl = isComponent ? import_core3.types.identifier(getTagName(path.node)) : path.scope.generateUidIdentifier("_tmpl$");
309
- let templateNode;
310
- if (!isComponent) {
311
- templateNode = import_core3.types.callExpression(state.template, [
312
- import_core3.types.stringLiteral(currentResult.template)
313
- ]);
314
- state.tmplDeclaration.declarations.push(import_core3.types.variableDeclarator(tmpl, templateNode));
315
- imports.add("template");
1699
+ const parentPosition = findIndexPosition(dynamicContent.parentIndex, indexMap);
1700
+ if (parentPosition === -1) {
1701
+ throw new Error(
1702
+ `Cannot find parent node index in index mapping: ${dynamicContent.parentIndex}`
1703
+ );
316
1704
  }
317
- const key = (_b = currentResult.props.key) != null ? _b : (_a = currentResult.props[0]) == null ? void 0 : _a.key;
318
- const propsArg = createProps(currentResult.props);
319
- const args = isComponent && getTagName(path.node) === "Fragment" ? [import_core3.types.stringLiteral(""), propsArg] : [tmpl, propsArg];
320
- if (key) {
321
- args.push(key);
1705
+ const argExpressions = [
1706
+ // Target parent node reference: nodes[parentPosition]
1707
+ import_core8.types.memberExpression(nodesIdentifier, import_core8.types.numericLiteral(parentPosition), true),
1708
+ // CallExpression not be use call function
1709
+ // Content lazy function: () => dynamicContent (implements on-demand calculation)
1710
+ import_core8.types.isCallExpression(dynamicContent.node) || import_core8.types.isArrowFunctionExpression(dynamicContent.node) || import_core8.types.isFunctionExpression(dynamicContent.node) ? dynamicContent.node : import_core8.types.arrowFunctionExpression([], dynamicContent.node)
1711
+ ];
1712
+ if (dynamicContent.before !== null) {
1713
+ const beforePosition = findIndexPosition(dynamicContent.before, indexMap);
1714
+ if (beforePosition === -1) {
1715
+ throw new Error(`Cannot find before node index in index mapping: ${dynamicContent.before}`);
1716
+ }
1717
+ argExpressions.push(
1718
+ import_core8.types.memberExpression(nodesIdentifier, import_core8.types.numericLiteral(beforePosition), true)
1719
+ );
322
1720
  }
323
- const fnName = isJSXFragment || isComponent && getTagName(path.node) === "Fragment" ? "Fragment" : "h";
324
- imports.add(fnName);
325
- return import_core3.types.callExpression(state[fnName], args);
1721
+ return argExpressions;
326
1722
  }
327
- function createServerNode(path) {
328
- var _a, _b;
329
- const state = path.state;
330
- const isComponent = path.isJSXElement() && isComponentName(getTagName(path.node));
331
- const tmpl = isComponent ? import_core3.types.identifier(getTagName(path.node)) : path.scope.generateUidIdentifier("_tmpl$");
332
- let templateNode;
333
- if (!isComponent) {
334
- templateNode = import_core3.types.arrayExpression(currentResult.template.map(import_core3.types.stringLiteral));
335
- state.tmplDeclaration.declarations.push(import_core3.types.variableDeclarator(tmpl, templateNode));
336
- }
337
- const key = (_b = currentResult.props.key) != null ? _b : (_a = currentResult.props[0]) == null ? void 0 : _a.key;
338
- const propsArg = createProps(currentResult.props);
339
- const args = isComponent && getTagName(path.node) === "Fragment" ? [import_core3.types.stringLiteral(""), propsArg] : [tmpl, propsArg];
340
- if (key) {
341
- args.push(key);
1723
+ function generateDynamicChildrenCode(dynamicChildren, statements, state, nodesId, indexMap) {
1724
+ addImport(importMap.insert);
1725
+ for (const dynamicContent of dynamicChildren) {
1726
+ const processedNode = processIIFEExpression(dynamicContent.node);
1727
+ const insertArgs = createInsertArguments(
1728
+ __spreadProps(__spreadValues({}, dynamicContent), { node: processedNode }),
1729
+ nodesId,
1730
+ indexMap
1731
+ );
1732
+ const insertCall = import_core8.types.callExpression(state.imports.insert, insertArgs);
1733
+ statements.push(import_core8.types.expressionStatement(insertCall));
342
1734
  }
343
- const fnName = "ssg";
344
- imports.add(fnName);
345
- return import_core3.types.callExpression(state[fnName], args);
346
1735
  }
347
- function transformJSXElement(path, isServer2 = false, isRoot = false) {
348
- const state = path.state;
349
- if (path.isJSXElement()) {
350
- const tagName = getTagName(path.node);
351
- const tagIsComponent = isComponentName(tagName);
352
- const isSelfClose = !tagIsComponent && selfClosingTags.includes(tagName);
353
- const isSvg = svgTags.includes(tagName) && currentResult.index === 1;
354
- const { props, hasExpression } = getAttrProps(path, state);
355
- if (tagIsComponent) {
356
- if (isRoot) {
357
- currentResult.props = props;
358
- const children = getChildren(path);
359
- if (children.length > 0) {
360
- const childrenGenerator = children.length === 1 ? children[0] : import_core3.types.arrayExpression(children);
361
- if (import_core3.types.isConditionalExpression(childrenGenerator)) {
362
- currentResult.props.children = import_core3.types.arrowFunctionExpression([], childrenGenerator);
363
- } else {
364
- currentResult.props.children = childrenGenerator;
1736
+ function generateDynamicPropsCode(dynamicProps, statements, state, nodesId, indexMap) {
1737
+ for (const propItem of dynamicProps) {
1738
+ const { parentIndex, props } = propItem;
1739
+ if (parentIndex === null) {
1740
+ continue;
1741
+ }
1742
+ const parentIndexPosition = indexMap.indexOf(parentIndex);
1743
+ if (parentIndexPosition === -1) {
1744
+ ne(`Cannot find parent node index: ${parentIndex}`);
1745
+ continue;
1746
+ }
1747
+ for (const [attrName, attrValue] of Object.entries(props)) {
1748
+ try {
1749
+ if (attrName.startsWith(`${UPDATE_PREFIX}:`) && Array.isArray(attrValue)) {
1750
+ if (attrValue.length === 2 && import_core8.types.isExpression(attrValue[0]) && import_core8.types.isExpression(attrValue[1])) {
1751
+ generateSpecificAttributeCode(
1752
+ attrName,
1753
+ attrValue,
1754
+ // Pass array as-is, createAttributeStatement will spread it
1755
+ nodesId,
1756
+ parentIndexPosition,
1757
+ statements,
1758
+ state
1759
+ );
365
1760
  }
1761
+ continue;
366
1762
  }
367
- } else {
368
- transformJSX(path);
369
- replaceChild(path.node);
370
- }
371
- } else {
372
- if (isSvg) {
373
- currentResult.template = isServer2 ? [`<svg _svg_ data-hk="${currentResult.index}">`] : `<svg _svg_ >`;
374
- }
375
- addTemplate(`<${tagName}${isServer2 ? ` data-hk="${currentResult.index}"` : ""}`, true);
376
- handleAttributes(props, state);
377
- addTemplate(isSelfClose ? "/>" : ">", !hasExpression);
378
- if (!isSelfClose) {
379
- transformChildren(path);
380
- if (hasSiblingElement(path) || isServer2) {
381
- addTemplate(`</${tagName}>`);
1763
+ if (!import_core8.types.isExpression(attrValue)) {
1764
+ continue;
1765
+ }
1766
+ if (attrName.startsWith("on")) {
1767
+ addEventListenerStatement(
1768
+ attrName,
1769
+ attrValue,
1770
+ nodesId,
1771
+ parentIndexPosition,
1772
+ statements,
1773
+ state
1774
+ );
1775
+ } else {
1776
+ generateSpecificAttributeCode(
1777
+ attrName,
1778
+ attrValue,
1779
+ nodesId,
1780
+ parentIndexPosition,
1781
+ statements,
1782
+ state
1783
+ );
382
1784
  }
1785
+ } catch (error) {
1786
+ ne(`Attribute processing failed (${attrName}): ${error}`);
383
1787
  }
384
1788
  }
385
- } else {
386
- currentResult.index--;
387
- transformChildren(path);
388
1789
  }
389
1790
  }
390
- function getAttrProps(path, state) {
391
- const props = {};
392
- let hasExpression = false;
393
- path.get("openingElement").get("attributes").forEach((attribute) => {
394
- if (attribute.isJSXAttribute()) {
395
- const name = getAttrName(attribute.node);
396
- const value = attribute.get("value");
397
- if (!value.node) {
398
- props[name] = true;
399
- } else if (value.isStringLiteral()) {
400
- props[name] = value.node.value;
401
- } else {
402
- if (value.isJSXExpressionContainer()) {
403
- const expression = value.get("expression");
404
- if (expression.isStringLiteral()) {
405
- props[name] = expression.node.value;
406
- } else if (expression.isNumericLiteral()) {
407
- props[name] = expression.node.value;
408
- } else if (expression.isJSXElement() || expression.isJSXFragment()) {
409
- transformJSX(expression);
410
- props[name] = expression.node;
411
- } else if (expression.isExpression()) {
412
- hasExpression = true;
413
- if (/^key|ref|on.+$/.test(name)) {
414
- props[name] = expression.node;
415
- } else if (/^bind:.+/.test(name)) {
416
- const value2 = path.scope.generateUidIdentifier("value");
417
- const bindName = name.slice(5).toLocaleLowerCase();
418
- props[bindName] = expression.node;
419
- props[`update${capitalize(bindName)}`] = import_core3.types.arrowFunctionExpression(
420
- [value2],
421
- import_core3.types.assignmentExpression("=", expression.node, value2)
422
- );
423
- } else {
424
- if (expression.isConditionalExpression()) {
425
- imports.add("useComputed");
426
- props[name] = import_core3.types.callExpression(state.useComputed, [
427
- import_core3.types.arrowFunctionExpression([], expression.node)
428
- ]);
429
- } else {
430
- props[name] = expression.node;
431
- }
432
- }
433
- }
434
- } else if (value.isJSXElement() || value.isJSXFragment()) {
435
- transformJSX(value);
436
- props[name] = value.node;
437
- }
438
- }
439
- } else if (attribute.isJSXSpreadAttribute()) {
440
- props._$spread$ = attribute.get("argument").node;
441
- hasExpression = true;
442
- } else {
443
- throw new Error("Unsupported attribute type");
1791
+ function generateUnifiedMemoizedEffect(reactiveOperations, statements, state, nodesId, indexMap) {
1792
+ addImport(importMap.memoEffect);
1793
+ const variableDeclarations = reactiveOperations.map((op, index) => {
1794
+ let attrValue = op.attrValue;
1795
+ if (import_core8.types.isIdentifier(op.attrValue) && isSignal(op.attrValue.name)) {
1796
+ attrValue = import_core8.types.memberExpression(attrValue, import_core8.types.identifier("value"));
444
1797
  }
1798
+ return import_core8.types.variableDeclarator(import_core8.types.identifier(`_v$${index}`), attrValue);
445
1799
  });
446
- return {
447
- props,
448
- hasExpression
449
- };
450
- }
451
- function getChildren(path) {
452
- return path.get("children").filter((child) => isValidChild(child)).map((child) => {
453
- if (child.isJSXElement() || child.isJSXFragment()) {
454
- transformJSX(child);
455
- } else if (child.isJSXExpressionContainer()) {
456
- child.replaceWith(child.get("expression"));
457
- } else if (child.isJSXText()) {
458
- child.replaceWith(import_core3.types.stringLiteral(replaceSpace(child.node)));
1800
+ const updateStatements = reactiveOperations.map((op, index) => {
1801
+ const parentPosition = findIndexPosition(op.nodeIndex, indexMap);
1802
+ if (parentPosition === -1) {
1803
+ throw new Error(`Cannot find parent node index in index mapping: ${op.nodeIndex}`);
1804
+ }
1805
+ const varName = import_core8.types.identifier(`_v$${index}`);
1806
+ const elementRef = import_core8.types.memberExpression(nodesId, import_core8.types.numericLiteral(parentPosition), true);
1807
+ let domOperationCall;
1808
+ if (op.setFunction.name === "patchAttr") {
1809
+ domOperationCall = import_core8.types.callExpression(op.setFunction.value, [
1810
+ elementRef,
1811
+ import_core8.types.stringLiteral(op.attrName),
1812
+ import_core8.types.memberExpression(import_core8.types.identifier("_p$"), import_core8.types.identifier(op.propKey)),
1813
+ import_core8.types.assignmentExpression(
1814
+ "=",
1815
+ import_core8.types.memberExpression(import_core8.types.identifier("_p$"), import_core8.types.identifier(op.propKey)),
1816
+ varName
1817
+ )
1818
+ ]);
459
1819
  } else {
460
- throw new Error("Unsupported child type");
1820
+ domOperationCall = import_core8.types.callExpression(op.setFunction.value, [
1821
+ elementRef,
1822
+ import_core8.types.memberExpression(import_core8.types.identifier("_p$"), import_core8.types.identifier(op.propKey)),
1823
+ import_core8.types.assignmentExpression(
1824
+ "=",
1825
+ import_core8.types.memberExpression(import_core8.types.identifier("_p$"), import_core8.types.identifier(op.propKey)),
1826
+ varName
1827
+ )
1828
+ ]);
461
1829
  }
462
- return child.node;
1830
+ return import_core8.types.expressionStatement(
1831
+ import_core8.types.logicalExpression(
1832
+ "&&",
1833
+ import_core8.types.binaryExpression(
1834
+ "!==",
1835
+ varName,
1836
+ import_core8.types.memberExpression(import_core8.types.identifier("_p$"), import_core8.types.identifier(op.propKey))
1837
+ ),
1838
+ domOperationCall
1839
+ )
1840
+ );
463
1841
  });
464
- }
465
- function replaceChild(node) {
466
- var _a, _b, _c, _d, _e;
467
- if (currentResult.isLastChild) {
468
- currentResult.index--;
469
- } else {
470
- addTemplate("<!>");
471
- }
472
- (_c = (_a = currentResult.props)[_b = currentResult.parentIndex]) != null ? _c : _a[_b] = {};
473
- (_e = (_d = currentResult.props[currentResult.parentIndex]).children) != null ? _e : _d.children = [];
474
- currentResult.props[currentResult.parentIndex].children.push(
475
- import_core3.types.arrayExpression([
476
- import_core3.types.arrowFunctionExpression([], node),
477
- currentResult.isLastChild ? import_core3.types.nullLiteral() : import_core3.types.identifier(String(currentResult.index))
478
- ])
1842
+ const effectBody = import_core8.types.blockStatement([
1843
+ // var _v$0 = expr1, _v$1 = expr2, ...;
1844
+ import_core8.types.variableDeclaration("var", variableDeclarations),
1845
+ // All update statements
1846
+ ...updateStatements,
1847
+ // return _p$;
1848
+ import_core8.types.returnStatement(import_core8.types.identifier("_p$"))
1849
+ ]);
1850
+ const effectFunction = import_core8.types.arrowFunctionExpression([import_core8.types.identifier("_p$")], effectBody);
1851
+ const initialStateProperties = reactiveOperations.map(
1852
+ (op) => import_core8.types.objectProperty(import_core8.types.identifier(op.propKey), import_core8.types.identifier("undefined"))
479
1853
  );
1854
+ const initialState = import_core8.types.objectExpression(initialStateProperties);
1855
+ const memoizedEffectCall = import_core8.types.callExpression(state.imports.memoEffect, [
1856
+ effectFunction,
1857
+ initialState
1858
+ ]);
1859
+ statements.push(import_core8.types.expressionStatement(memoizedEffectCall));
480
1860
  }
481
- function handleAttributes(props, state) {
482
- let klass = "";
483
- let style = "";
484
- for (const [prop, value] of Object.entries(props)) {
485
- if (prop === "class" && typeof value === "string") {
486
- klass += ` ${value}`;
487
- delete props[prop];
488
- } else if (prop === "style" && typeof value === "string") {
489
- style += `${value}${value.at(-1) === ";" ? "" : ";"}`;
490
- delete props[prop];
491
- } else if (value === true) {
492
- addTemplate(` ${prop}`);
493
- delete props[prop];
494
- } else if (value === false) {
495
- delete props[prop];
496
- } else if (typeof value === "string" || typeof value === "number") {
497
- addTemplate(` ${prop}="${value}"`);
498
- delete props[prop];
499
- } else if (import_core3.types.isConditionalExpression(value)) {
500
- imports.add("useComputed");
501
- props[prop] = import_core3.types.callExpression(state.useComputed, [import_core3.types.arrowFunctionExpression([], value)]);
502
- } else if (import_core3.types.isObjectExpression(value)) {
503
- const val = hasObjectExpression(
504
- prop,
505
- value,
506
- props,
507
- state,
508
- prop === "class" || prop === "style"
509
- );
510
- if (val) {
511
- if (prop === "class") {
512
- klass += ` ${val}`;
513
- }
514
- if (prop === "style") {
515
- style += `${val}${val.at(-1) === ";" ? "" : ";"}`;
516
- }
517
- }
518
- }
1861
+ function generateStaticTemplate(node) {
1862
+ if (!node || node.type === 1 /* COMPONENT */) {
1863
+ return "";
519
1864
  }
520
- if (Object.keys(props).length > 0) {
521
- currentResult.props[currentResult.index] = props;
1865
+ switch (node.type) {
1866
+ case 2 /* TEXT */:
1867
+ return Array.isArray(node.children) ? node.children.join("") : "";
1868
+ case 6 /* COMMENT */:
1869
+ return "<!>";
1870
+ case 0 /* NORMAL */:
1871
+ case 5 /* SVG */:
1872
+ return gstForNormal(node);
1873
+ default:
1874
+ return gstForChildren(node);
522
1875
  }
523
- if (klass.trim()) {
524
- addTemplate(` class="${klass.trim()}"`);
1876
+ }
1877
+ function gstForNormal(node) {
1878
+ if (!node.tag) {
1879
+ return gstForChildren(node);
525
1880
  }
526
- if (style.trim()) {
527
- addTemplate(` style="${style.trim()}"`);
1881
+ const attributes = serializeAttributes(node.props);
1882
+ const startTag = `<${node.tag}${attributes ? ` ${attributes}` : ""}`;
1883
+ if (node.selfClosing) {
1884
+ return `${startTag}/>`;
528
1885
  }
1886
+ return `${startTag}>${gstForChildren(node)}</${node.tag}>`;
529
1887
  }
530
- function transformChildren(path) {
531
- const parentIndex = currentResult.index;
532
- path.get("children").reduce((pre, cur) => {
533
- if (isValidChild(cur)) {
534
- const lastChild = pre.at(-1);
535
- if (lastChild && isTextChild(cur) && isTextChild(lastChild)) {
536
- setNodeText(lastChild, getNodeText(lastChild) + getNodeText(cur));
537
- } else {
538
- pre.push(cur);
539
- }
540
- }
541
- return pre;
542
- }, []).forEach((child, i, arr) => {
543
- currentResult.parentIndex = parentIndex;
544
- currentResult.isLastChild = i === arr.length - 1;
545
- transformChild(child);
546
- });
547
- }
548
- function transformChild(child) {
549
- currentResult.index++;
550
- if (child.isJSXElement() || child.isJSXFragment()) {
551
- transformJSXElement(child, false);
552
- } else if (child.isJSXExpressionContainer()) {
553
- const expression = child.get("expression");
554
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
555
- addTemplate(`${expression.node.value}`, true);
556
- } else if (expression.isExpression()) {
557
- replaceChild(expression.node);
558
- } else if (import_core3.types.isJSXEmptyExpression(expression.node)) {
559
- } else {
560
- throw new Error("Unsupported child type");
1888
+ function gstForChildren(node) {
1889
+ if (!node.children || !node.children.length) {
1890
+ return "";
1891
+ }
1892
+ const childTemplates = [];
1893
+ for (const child of node.children) {
1894
+ if (w(child)) {
1895
+ const childTemplate = generateStaticTemplate(child);
1896
+ childTemplates.push(childTemplate);
1897
+ } else if (m(child)) {
1898
+ childTemplates.push(child);
561
1899
  }
562
- } else if (child.isJSXText()) {
563
- addTemplate(replaceSpace(child.node), true);
564
- } else {
565
- throw new Error("Unsupported child type");
566
1900
  }
1901
+ return childTemplates.join("");
567
1902
  }
568
- function createProps(props) {
569
- const result = [];
570
- for (const prop in props) {
571
- let value = props[prop];
572
- if (prop === "key") {
573
- continue;
574
- }
575
- if (Array.isArray(value)) {
576
- value = import_core3.types.arrayExpression(value);
577
- }
578
- if (typeof value === "object" && value !== null && !import_core3.types.isNode(value)) {
579
- value = createProps(value);
580
- }
581
- if (typeof value === "string") {
582
- value = import_core3.types.stringLiteral(value);
583
- }
584
- if (typeof value === "number") {
585
- value = import_core3.types.numericLiteral(value);
586
- }
587
- if (typeof value === "boolean") {
588
- value = import_core3.types.booleanLiteral(value);
589
- }
590
- if (value === void 0) {
591
- value = import_core3.types.tsUndefinedKeyword();
1903
+ function generateDynamic(node) {
1904
+ const dynamicCollection = {
1905
+ props: [],
1906
+ children: [],
1907
+ operations: []
1908
+ };
1909
+ function walk(node2, parentNode) {
1910
+ processNodeDynamic(dynamicCollection, node2, parentNode);
1911
+ if (node2.type === 1 /* COMPONENT */ || node2.type === 3 /* FRAGMENT */) {
1912
+ return;
592
1913
  }
593
- if (value === null) {
594
- value = import_core3.types.nullLiteral();
1914
+ if (node2.children && node2.children.length) {
1915
+ node2.children.forEach((child) => {
1916
+ if (isTreeNode(child)) {
1917
+ walk(child, node2);
1918
+ }
1919
+ });
595
1920
  }
596
- if (prop === "_$spread$") {
597
- result.push(import_core3.types.spreadElement(value));
598
- } else {
599
- result.push(import_core3.types.objectProperty(import_core3.types.stringLiteral(prop), value));
1921
+ }
1922
+ walk(node);
1923
+ return dynamicCollection;
1924
+ }
1925
+ function processNodeDynamic(dynamicCollection, node, parentNode) {
1926
+ var _a, _b, _c, _d;
1927
+ const { children, props, operations } = dynamicCollection;
1928
+ switch (node.type) {
1929
+ case 1 /* COMPONENT */: {
1930
+ const componentProps = __spreadProps(__spreadValues({}, node.props), { children: node.children });
1931
+ const componentExpr = createComponentExpression(node, componentProps);
1932
+ children.push({
1933
+ index: node.index,
1934
+ node: componentExpr,
1935
+ before: findBeforeIndex(node, parentNode),
1936
+ parentIndex: (_a = parentNode == null ? void 0 : parentNode.index) != null ? _a : null
1937
+ });
1938
+ break;
600
1939
  }
1940
+ case 4 /* EXPRESSION */:
1941
+ if (node.children && node.children.length > 0) {
1942
+ const firstChild = node.children[0];
1943
+ if (w(firstChild) && import_core8.types.isNode(firstChild) && import_core8.types.isExpression(firstChild)) {
1944
+ children.push({
1945
+ index: node.index,
1946
+ node: import_core8.types.arrowFunctionExpression([], firstChild),
1947
+ before: findBeforeIndex(node, parentNode),
1948
+ parentIndex: (_b = parentNode == null ? void 0 : parentNode.index) != null ? _b : null
1949
+ });
1950
+ } else if (w(firstChild) && import_core8.types.isNode(firstChild) && import_core8.types.isJSXElement(firstChild)) {
1951
+ children.push({
1952
+ index: node.index,
1953
+ node: createComponentExpression(node, { children: [firstChild] }),
1954
+ before: findBeforeIndex(node, parentNode),
1955
+ parentIndex: (_c = parentNode == null ? void 0 : parentNode.index) != null ? _c : null
1956
+ });
1957
+ }
1958
+ }
1959
+ break;
1960
+ // Text nodes don't need dynamic processing (already handled in template stage)
1961
+ case 2 /* TEXT */:
1962
+ break;
1963
+ default:
1964
+ if (node.props && Object.keys(node.props).length > 0) {
1965
+ const currentProps = {};
1966
+ for (const [attrName, attrValue] of Object.entries(node.props)) {
1967
+ const isReactive = import_core8.types.isNode(attrValue) && isDynamicExpression(attrValue) && !q(attrName, `${UPDATE_PREFIX}:`) && !q(attrName, EVENT_ATTR_NAME);
1968
+ if (q(attrName, `${UPDATE_PREFIX}:`)) {
1969
+ const name = attrName.split(":")[1];
1970
+ const setFunction = getSetFunctionForAttribute();
1971
+ addImport(importMap[setFunction.name]);
1972
+ operations.push({
1973
+ nodeIndex: node == null ? void 0 : node.index,
1974
+ attrName: name,
1975
+ attrValue: attrValue[0],
1976
+ setFunction,
1977
+ propKey: generatePropKey()
1978
+ });
1979
+ }
1980
+ if (isReactive && import_core8.types.isExpression(attrValue)) {
1981
+ const setFunction = getSetFunctionForAttribute(attrName);
1982
+ addImport(importMap[setFunction.name]);
1983
+ operations.push({
1984
+ nodeIndex: node == null ? void 0 : node.index,
1985
+ attrName,
1986
+ attrValue,
1987
+ setFunction,
1988
+ propKey: generatePropKey(attrName)
1989
+ });
1990
+ } else {
1991
+ currentProps[attrName] = attrValue;
1992
+ }
1993
+ }
1994
+ if (Object.keys(currentProps).length > 0) {
1995
+ props.push({
1996
+ props: currentProps,
1997
+ parentIndex: (_d = node == null ? void 0 : node.index) != null ? _d : null
1998
+ });
1999
+ }
2000
+ }
2001
+ break;
601
2002
  }
602
- return import_core3.types.objectExpression(result);
603
2003
  }
604
2004
 
605
- // src/signal/symbol.ts
606
- var import_core5 = require("@babel/core");
607
-
608
- // src/shared.ts
609
- var import_core4 = require("@babel/core");
610
- function isSymbolStart(path, name) {
611
- const state = path.state;
612
- const { symbol } = (state == null ? void 0 : state.opts) || "$";
613
- return startsWith(name, symbol);
2005
+ // src/jsx/ssg.ts
2006
+ var import_core9 = require("@babel/core");
2007
+ function transformJSXToSSG(path, treeNode) {
2008
+ const { state } = getContext();
2009
+ const result = transformTemplate(treeNode);
2010
+ const { templates, dynamics } = result;
2011
+ if (treeNode.type === 1 /* COMPONENT */ || treeNode.type === 3 /* FRAGMENT */) {
2012
+ const componentProps = __spreadProps(__spreadValues({}, treeNode.props), { children: treeNode.children });
2013
+ addImport(importMap.createComponent);
2014
+ return import_core9.types.callExpression(state.imports.createComponent, [
2015
+ import_core9.types.identifier(treeNode.tag),
2016
+ createPropsObjectExpression(componentProps, transformJSXToSSG)
2017
+ ]);
2018
+ }
2019
+ const args = [];
2020
+ if (templates && templates.length > 0) {
2021
+ addImport(importMap.template);
2022
+ const tmplId = path.scope.generateUidIdentifier("_tmpl$");
2023
+ const templateNode = import_core9.types.arrayExpression(templates.map((str) => import_core9.types.stringLiteral(str)));
2024
+ state.declarations.push(import_core9.types.variableDeclarator(tmplId, templateNode));
2025
+ args.push(tmplId);
2026
+ }
2027
+ args.push(import_core9.types.callExpression(state.imports.getHydrationKey, []));
2028
+ addImport(importMap.render);
2029
+ addImport(importMap.getHydrationKey);
2030
+ const textDynamics = dynamics.filter((d2) => d2.type === "text");
2031
+ const attrDynamics = dynamics.filter((d2) => d2.type === "attr");
2032
+ attrDynamics.forEach((dynamic) => {
2033
+ args.push(dynamic.node);
2034
+ });
2035
+ textDynamics.forEach((dynamic) => {
2036
+ args.push(dynamic.node);
2037
+ });
2038
+ return import_core9.types.callExpression(state.imports.render, args);
614
2039
  }
615
-
616
- // src/signal/symbol.ts
617
- function replaceSymbol(path) {
618
- const { init, id } = path.node;
619
- const variableName = id.name;
620
- if (import_core5.types.isObjectPattern(id) || import_core5.types.isArrayPattern(id) || !isSymbolStart(path, variableName)) return;
621
- const isComputed = init && (import_core5.types.isFunctionExpression(init) || import_core5.types.isArrowFunctionExpression(init)) && path.parent.kind === "const";
622
- const hookName = isComputed ? "useComputed" : "useSignal";
623
- const newInit = import_core5.types.callExpression(import_core5.types.identifier(path.state[hookName].name), init ? [init] : []);
624
- imports.add(hookName);
625
- path.node.init = newInit;
2040
+ function transformTemplate(treeNode) {
2041
+ const result = {
2042
+ templates: [],
2043
+ dynamics: []
2044
+ };
2045
+ walkTreeNode(treeNode, result);
2046
+ return result;
626
2047
  }
627
- function symbolIdentifier(path) {
628
- const parentPath = path.parentPath;
629
- if (!shouldProcessIdentifier(parentPath)) return;
630
- const { node } = path;
631
- if (!isSymbolStart(path, node.name)) return;
632
- if (!path.findParent((p) => p.isMemberExpression() && p.node.property.name === "value")) {
633
- path.replaceWith(import_core5.types.memberExpression(import_core5.types.identifier(node.name), import_core5.types.identifier("value")));
2048
+ function walkTreeNode(treeNode, result) {
2049
+ if (!treeNode) {
2050
+ return;
2051
+ }
2052
+ switch (treeNode.type) {
2053
+ case 1 /* COMPONENT */:
2054
+ case 3 /* FRAGMENT */:
2055
+ handleComponent(treeNode, result);
2056
+ break;
2057
+ case 4 /* EXPRESSION */:
2058
+ handleExpression(treeNode, result);
2059
+ break;
2060
+ case 2 /* TEXT */:
2061
+ handleText(treeNode, result);
2062
+ break;
2063
+ case 0 /* NORMAL */:
2064
+ case 5 /* SVG */:
2065
+ handleElement(treeNode, result);
2066
+ break;
2067
+ case 6 /* COMMENT */:
2068
+ addTemplate(result, "<!>", true);
2069
+ break;
2070
+ default:
2071
+ if (treeNode.children && treeNode.children.length > 0) {
2072
+ processChildren2(treeNode.children, result);
2073
+ }
2074
+ break;
634
2075
  }
635
2076
  }
636
- function shouldProcessIdentifier(parentPath) {
637
- return parentPath && !import_core5.types.isVariableDeclarator(parentPath) && !import_core5.types.isImportSpecifier(parentPath) && !import_core5.types.isObjectProperty(parentPath) && !import_core5.types.isArrayPattern(parentPath) && !import_core5.types.isObjectPattern(parentPath);
638
- }
639
- function symbolObjectPattern(path) {
640
- path.node.properties.forEach((property) => {
641
- if (import_core5.types.isObjectProperty(property) && import_core5.types.isIdentifier(property.key) && isSymbolStart(path, property.key.name)) {
642
- property.key = import_core5.types.identifier(property.key.name);
2077
+ var addTemplate = (result, content, join = false) => {
2078
+ if (result.templates.length === 0) {
2079
+ result.templates.push(content);
2080
+ } else {
2081
+ if (join) {
2082
+ result.templates[result.templates.length - 1] += content;
2083
+ } else {
2084
+ result.templates.push(content);
643
2085
  }
2086
+ }
2087
+ };
2088
+ var handleComponent = (node, result) => {
2089
+ result.templates.push("");
2090
+ const { state } = getContext();
2091
+ const componentProps = __spreadValues({}, node.props);
2092
+ if (node.children.length) {
2093
+ componentProps.children = node.children;
2094
+ }
2095
+ addImport(importMap.createComponent);
2096
+ const componentExpr = import_core9.types.callExpression(state.imports.createComponent, [
2097
+ import_core9.types.identifier(node.tag),
2098
+ createPropsObjectExpression(componentProps, transformJSXToSSG)
2099
+ ]);
2100
+ result.dynamics.push({
2101
+ type: "text",
2102
+ node: componentExpr
644
2103
  });
645
- }
646
- function symbolArrayPattern(path) {
647
- path.node.elements.forEach((element) => {
648
- if (import_core5.types.isIdentifier(element) && element.name.startsWith("$")) {
649
- element.name = import_core5.types.identifier(element.name).name;
650
- } else if (import_core5.types.isObjectPattern(element)) {
651
- symbolObjectPattern({ node: element });
2104
+ };
2105
+ var handleExpression = (node, result) => {
2106
+ if (!node.children || node.children.length === 0) {
2107
+ return;
2108
+ }
2109
+ const firstChild = node.children[0];
2110
+ result.templates.push("");
2111
+ if (j(firstChild)) {
2112
+ const { state } = getContext();
2113
+ addImport(importMap.escapeHTML);
2114
+ result.dynamics.push({
2115
+ type: "text",
2116
+ node: import_core9.types.callExpression(state.imports.escapeHTML, [import_core9.types.valueToNode(firstChild)])
2117
+ });
2118
+ } else if (w(firstChild)) {
2119
+ const exprNode = firstChild;
2120
+ if (import_core9.types.isCallExpression(exprNode) && import_core9.types.isMemberExpression(exprNode.callee) && exprNode.arguments.length > 0) {
2121
+ const mapCallback = exprNode.arguments[0];
2122
+ if ((import_core9.types.isArrowFunctionExpression(mapCallback) || import_core9.types.isFunctionExpression(mapCallback)) && mapCallback.body) {
2123
+ let jsxElement = void 0;
2124
+ if (import_core9.types.isJSXElement(mapCallback.body)) {
2125
+ jsxElement = mapCallback.body;
2126
+ } else if (import_core9.types.isBlockStatement(mapCallback.body)) {
2127
+ const returnStmt = mapCallback.body.body.find((stmt) => import_core9.types.isReturnStatement(stmt));
2128
+ if (returnStmt && import_core9.types.isReturnStatement(returnStmt) && returnStmt.argument && import_core9.types.isJSXElement(returnStmt.argument)) {
2129
+ jsxElement = returnStmt.argument;
2130
+ }
2131
+ } else if (import_core9.types.isParenthesizedExpression(mapCallback.body) && import_core9.types.isJSXElement(mapCallback.body.expression)) {
2132
+ jsxElement = mapCallback.body.expression;
2133
+ }
2134
+ if (jsxElement) {
2135
+ const { state } = getContext();
2136
+ const tagName = jsxElement.openingElement.name.type === "JSXIdentifier" ? jsxElement.openingElement.name.name : "";
2137
+ const props = {};
2138
+ jsxElement.openingElement.attributes.forEach((attr) => {
2139
+ if (import_core9.types.isJSXAttribute(attr)) {
2140
+ const name = attr.name.name;
2141
+ if (import_core9.types.isJSXExpressionContainer(attr.value)) {
2142
+ props[name] = attr.value.expression;
2143
+ } else if (import_core9.types.isStringLiteral(attr.value)) {
2144
+ props[name] = attr.value.value;
2145
+ } else if (attr.value === null) {
2146
+ props[name] = true;
2147
+ }
2148
+ } else if (import_core9.types.isJSXSpreadAttribute(attr)) {
2149
+ props._$spread$ = attr.argument;
2150
+ }
2151
+ });
2152
+ if (tagName === FRAGMENT_NAME) {
2153
+ addImport(importMap.Fragment);
2154
+ const newCallback = import_core9.types.arrowFunctionExpression(
2155
+ mapCallback.params,
2156
+ import_core9.types.callExpression(state.imports.Fragment, [
2157
+ createPropsObjectExpression(props, transformJSXToSSG)
2158
+ ])
2159
+ );
2160
+ exprNode.arguments[0] = newCallback;
2161
+ } else if (tagName && tagName[0] === tagName[0].toUpperCase()) {
2162
+ addImport(importMap.createComponent);
2163
+ const newCallback = import_core9.types.arrowFunctionExpression(
2164
+ mapCallback.params,
2165
+ import_core9.types.callExpression(state.imports.createComponent, [
2166
+ import_core9.types.identifier(tagName),
2167
+ createPropsObjectExpression(props, transformJSXToSSG)
2168
+ ])
2169
+ );
2170
+ exprNode.arguments[0] = newCallback;
2171
+ }
2172
+ }
2173
+ }
652
2174
  }
653
- });
654
- }
655
-
656
- // src/signal/import.ts
657
- var import_core6 = require("@babel/core");
658
- function replaceImportDeclaration(path) {
659
- path.node.specifiers.forEach((specifier) => {
660
- const variableName = specifier.local.name;
661
- if (startsWith(variableName, "$") && !isVariableUsedAsObject(path, variableName)) {
662
- path.scope.rename(variableName, `${variableName}.value`);
663
- specifier.local.name = variableName;
2175
+ result.dynamics.push({
2176
+ type: "text",
2177
+ node: exprNode
2178
+ });
2179
+ }
2180
+ };
2181
+ var handleText = (node, result) => {
2182
+ if (node.children && node.children.length > 0) {
2183
+ addTemplate(result, node.children.join(""), true);
2184
+ }
2185
+ };
2186
+ var handleElement = (node, result) => {
2187
+ let openTag = `<${node.tag} data-idx="${node.index}"`;
2188
+ const { staticAttrs, dynamicAttrs } = processAttributes(node.props || {});
2189
+ openTag += staticAttrs;
2190
+ addTemplate(result, openTag, true);
2191
+ addTemplate(result, node.selfClosing ? "/>" : ">", dynamicAttrs.length === 0);
2192
+ if (!node.selfClosing && node.children && node.children.length > 0) {
2193
+ processChildren2(node.children, result);
2194
+ }
2195
+ if (!node.selfClosing) {
2196
+ addTemplate(result, `</${node.tag}>`, true);
2197
+ }
2198
+ processDynamicAttributes(dynamicAttrs, result);
2199
+ };
2200
+ var processChildren2 = (children, result) => {
2201
+ children.forEach((child) => {
2202
+ if (isTreeNode(child)) {
2203
+ walkTreeNode(child, result);
2204
+ } else if (m(child)) {
2205
+ addTemplate(result, child, true);
664
2206
  }
665
2207
  });
666
- }
667
- function isVariableUsedAsObject(path, variableName) {
668
- var _a;
669
- const binding = path.scope.getBinding(variableName);
670
- return ((_a = binding == null ? void 0 : binding.referencePaths) == null ? void 0 : _a.some((referencePath) => {
671
- if (import_core6.types.isMemberExpression(referencePath.parent)) {
672
- const { object, property } = referencePath.parent;
673
- if (import_core6.types.isIdentifier(object, { name: variableName })) {
674
- referencePath.parentPath.replaceWith(
675
- import_core6.types.memberExpression(import_core6.types.memberExpression(object, import_core6.types.identifier("value")), property)
676
- );
677
- return true;
2208
+ };
2209
+ function processAttributes(props) {
2210
+ let staticAttrs = "";
2211
+ const dynamicAttrs = [];
2212
+ for (const [prop, value] of Object.entries(props)) {
2213
+ if (prop.startsWith(EVENT_ATTR_NAME) || prop.startsWith(UPDATE_PREFIX)) {
2214
+ continue;
2215
+ }
2216
+ if (j(value)) {
2217
+ if (value === true) {
2218
+ staticAttrs += ` ${prop}`;
2219
+ } else if (A(value)) {
2220
+ staticAttrs += ` ${prop}="${value.toString()}"`;
2221
+ } else if (value !== false) {
2222
+ staticAttrs += ` ${prop}="${value}"`;
678
2223
  }
2224
+ } else if (import_core9.types.isExpression(value)) {
2225
+ dynamicAttrs.push({ name: prop, value });
679
2226
  }
680
- return false;
681
- })) || false;
2227
+ }
2228
+ return { staticAttrs, dynamicAttrs };
682
2229
  }
683
-
684
- // src/signal/props.ts
685
- var import_core7 = require("@babel/core");
686
- function replaceProps(path) {
687
- var _a;
688
- const state = path.state;
689
- const firstParam = path.node.params[0];
690
- if (!firstParam || !import_core7.types.isObjectPattern(firstParam)) return;
691
- const returnStatement = path.get("body").get("body").find((statement) => statement.isReturnStatement());
692
- if (!returnStatement || !import_core7.types.isJSXElement((_a = returnStatement.node) == null ? void 0 : _a.argument)) return;
693
- const replaceProperties = (properties2, parentPath) => {
694
- properties2.forEach((property) => {
695
- if (import_core7.types.isObjectProperty(property) && import_core7.types.isIdentifier(property.key)) {
696
- const keyName = property.key.name;
697
- if (import_core7.types.isIdentifier(property.value)) {
698
- path.scope.rename(property.value.name, `${parentPath}${keyName}`);
699
- } else if (import_core7.types.isObjectPattern(property.value)) {
700
- replaceProperties(property.value.properties, `${parentPath}${keyName}.`);
701
- }
702
- }
2230
+ var processDynamicAttributes = (dynamicAttrs, result) => {
2231
+ dynamicAttrs.forEach((attr) => {
2232
+ const { state } = getContext();
2233
+ addImport(importMap.patchAttr);
2234
+ addImport(importMap.escapeHTML);
2235
+ result.dynamics.push({
2236
+ type: "attr",
2237
+ node: import_core9.types.callExpression(state.imports.patchAttr, [
2238
+ import_core9.types.stringLiteral(attr.name),
2239
+ import_core9.types.callExpression(state.imports.escapeHTML, [attr.value]),
2240
+ import_core9.types.booleanLiteral(false)
2241
+ ]),
2242
+ attrName: attr.name
703
2243
  });
704
- };
705
- const properties = firstParam.properties;
706
- const notRestProperties = properties.filter(
707
- (property) => !import_core7.types.isRestElement(property)
708
- );
709
- replaceProperties(notRestProperties, "__props.");
710
- const notRestNames = notRestProperties.map((property) => property.key.name);
711
- if (notRestNames.some((name) => startsWith(name, "$"))) {
712
- console.warn("props name can not start with $");
713
- return;
2244
+ });
2245
+ };
2246
+
2247
+ // src/jsx/index.ts
2248
+ var transformStrategies = {
2249
+ ["client" /* CLIENT */]: transformJSXToClient,
2250
+ ["ssr" /* SSR */]: transformJSXToClient,
2251
+ ["ssg" /* SSG */]: transformJSXToSSG
2252
+ };
2253
+ var getRenderingStrategy = (mode) => {
2254
+ const strategy = transformStrategies[mode];
2255
+ if (!strategy) {
2256
+ throw new Error(`Unsupported render mode: ${mode}`);
714
2257
  }
715
- handleRestElement(path, state, properties, notRestNames);
716
- }
717
- function handleRestElement(path, state, properties, notRestNames) {
718
- const restElement = properties.find((property) => import_core7.types.isRestElement(property));
719
- path.node.params[0] = import_core7.types.identifier("__props");
720
- if (restElement) {
721
- const restName = restElement.argument.name;
722
- if (notRestNames.length === 0) {
723
- path.node.params[0] = import_core7.types.identifier(restName);
724
- } else {
725
- const restVariableDeclaration = createRestVariableDeclaration(state, restName, notRestNames);
726
- imports.add("useReactive");
727
- path.node.body.body.unshift(restVariableDeclaration);
728
- }
2258
+ return strategy;
2259
+ };
2260
+ function transformJSX(path) {
2261
+ var _a, _b;
2262
+ try {
2263
+ const mode = ((_b = (_a = path.state) == null ? void 0 : _a.opts) == null ? void 0 : _b.mode) || "client" /* CLIENT */;
2264
+ const strategy = getRenderingStrategy(mode);
2265
+ const tree = createTree(path);
2266
+ setContext({ state: path.state, path, operationIndex: 0 });
2267
+ const result = strategy(path, tree);
2268
+ path.replaceWith(result);
2269
+ resetContext();
2270
+ } catch (error_) {
2271
+ console.warn("JSX transformation failed in test:", { error_ });
2272
+ resetContext();
2273
+ throw error_;
729
2274
  }
730
2275
  }
731
- function createRestVariableDeclaration(state, restName, notRestNames) {
732
- return import_core7.types.variableDeclaration("const", [
733
- import_core7.types.variableDeclarator(
734
- import_core7.types.identifier(restName),
735
- import_core7.types.callExpression(state.useReactive, [
736
- import_core7.types.identifier("__props"),
737
- import_core7.types.arrayExpression(notRestNames.map((name) => import_core7.types.stringLiteral(name)))
738
- ])
739
- )
740
- ]);
741
- }
742
2276
 
743
2277
  // src/index.ts
744
- function src_default() {
2278
+ function index_default() {
745
2279
  return {
746
2280
  name: "babel-plugin-essor",
747
- manipulateOptions({ filename }, parserOpts) {
748
- if (filename.endsWith(".ts") || filename.endsWith(".tsx")) {
749
- parserOpts.plugins.push("typescript");
750
- }
2281
+ manipulateOptions(_2, parserOpts) {
751
2282
  parserOpts.plugins.push("jsx");
752
2283
  },
753
2284
  visitor: {
754
2285
  Program: transformProgram,
755
- FunctionDeclaration: replaceProps,
756
- ArrowFunctionExpression: replaceProps,
2286
+ // props
2287
+ FunctionDeclaration: transformProps,
2288
+ ArrowFunctionExpression: transformProps,
2289
+ // Symbol
757
2290
  VariableDeclarator: replaceSymbol,
758
- ImportDeclaration: replaceImportDeclaration,
2291
+ // let $x = 0 → let $x = signal(0)
759
2292
  Identifier: symbolIdentifier,
2293
+ // $x → $x.value
2294
+ AssignmentExpression: symbolAssignment,
2295
+ // $x = 1 → $x.value = 1
2296
+ UpdateExpression: symbolUpdate,
2297
+ // $x++ → $x.value++
760
2298
  ObjectPattern: symbolObjectPattern,
2299
+ // { $x } → handle nested patterns
761
2300
  ArrayPattern: symbolArrayPattern,
2301
+ // [$x] → handle nested patterns
2302
+ // JSX
762
2303
  JSXElement: transformJSX,
763
2304
  JSXFragment: transformJSX
764
2305
  }