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