what-compiler 0.11.7 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var he=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),xe=new Set(["once","capture","passive"]),ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Se=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),M=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),ne=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),ye=new Set(["what-framework/server","what-server","what-server/actions"]);function be(e){let y=0xcbf29ce484222325n;for(let w=0;w<e.length;w++)y^=BigInt(e.charCodeAt(w)),y=BigInt.asUintN(64,y*0x100000001b3n);return y.toString(36)}function ve(e,y){let w=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),A=String(y||"").replace(/\\/g,"/").replace(/\/+$/,"");return A&&w.startsWith(`${A}/`)?w.slice(A.length+1):w.replace(/^\.\//,"")}function J(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let y=e.split(/\r\n|\n|\r/),w=-1;for(let g=0;g<y.length;g++)/[^ \t]/.test(y[g])&&(w=g);if(w===-1)return"";let A="";for(let g=0;g<y.length;g++){let b=y[g].replace(/\t/g," "),L=g===0,I=g===y.length-1;L||(b=b.replace(/^ +/,"")),I||(b=b.replace(/ +$/,"")),b&&(g!==w&&(b+=" "),A+=b)}return A}function we({types:e}){let y=new Set,w=new Set;function A(n,i){return!(!n.includes("__")||!n.startsWith("on")||n.split("__").slice(1).filter(t=>t!=="").length===0)}function g(n){let i=n.includes("|")?"|":"__",r=n.split(i),s=r[0],t=r.slice(1).filter(o=>he.has(o));return{eventName:s,modifiers:t}}function b(n){return n.startsWith("bind:")}function L(n){return n.slice(5)}function I(n){return/^[A-Z]/.test(n)}function re(n){return ge.has(String(n).toLowerCase())}function $(n){return n?e.isJSXExpressionContainer(n)?n.expression:e.isStringLiteral(n)?n:e.stringLiteral(n.value||""):e.booleanLiteral(!0)}function W(n){return n==="className"?"class":n==="htmlFor"?"for":n}function C(n){return e.isJSXNamespacedName(n.name)?`${n.name.namespace.name}:${n.name.name.name}`:typeof n.name.name=="string"?n.name.name:String(n.name.name)}function B(n,i){if(i.length===0)return n;let r=n;for(let s of i)switch(s){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function k(n,i){return i.has(n)}function H(n){let i=new Set;function r(t){let o=t.init;if(!o||!e.isCallExpression(o))return;let a=o.callee,p="";if(e.isIdentifier(a)?p=a.name:e.isMemberExpression(a)&&e.isIdentifier(a.property)&&(p=a.property.name),ne.has(p)){let c=t.id;if(e.isIdentifier(c))i.add(c.name);else if(e.isArrayPattern(c))for(let f of c.elements)e.isIdentifier(f)&&i.add(f.name);else if(e.isObjectPattern(c))for(let f of c.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&i.add(f.value.name)}}let s=n.scope;for(;s;){for(let o of Object.values(s.bindings))o.path.isVariableDeclarator()&&r(o.path.node);let t=s.path&&s.path.node;if(t&&t.params){for(let o of t.params)if(e.isObjectPattern(o))for(let a of o.properties)e.isObjectProperty(a)&&e.isIdentifier(a.value)?i.add(a.value.name):e.isRestElement(a)&&e.isIdentifier(a.argument)&&i.add(a.argument.name)}s=s.parent}return i}function $e(n){return H(n)}function U(n){if(!e.isCallExpression(n))return!1;let i=n.callee;return e.isMemberExpression(i)&&e.isIdentifier(i.object)?M.has(i.object.name):e.isIdentifier(i)?M.has(i.name):!1}function z(n,i,r){if(!i)return!1;if(e.isCallExpression(n)){if(e.isIdentifier(n.callee)&&k(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!M.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&k(n.callee.object.name,i)||U(n))return!1;if(n.arguments.some(s=>S(s,i,r)))return!0}return!1}function S(n,i,r){return i||(i=new Set),e.isCallExpression(n)?e.isIdentifier(n.callee)&&k(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!M.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&k(n.callee.object.name,i)?!0:U(n)?n.arguments.some(s=>S(s,i,r)):e.isIdentifier(n.callee)?n.arguments.some(s=>S(s,i,r)):S(n.callee,i,r)||n.arguments.some(s=>S(s,i,r)):e.isIdentifier(n)?k(n.name,i)||r&&r.has(n.name):e.isMemberExpression(n)?S(n.object,i,r):e.isConditionalExpression(n)?S(n.test,i,r)||S(n.consequent,i,r)||S(n.alternate,i,r):e.isBinaryExpression(n)||e.isLogicalExpression(n)?S(n.left,i,r)||S(n.right,i,r):e.isUnaryExpression(n)?S(n.argument,i,r):e.isTemplateLiteral(n)?n.expressions.some(s=>S(s,i,r)):e.isObjectExpression(n)?n.properties.some(s=>e.isObjectProperty(s)&&S(s.value,i,r)):e.isArrayExpression(n)?n.elements.some(s=>s&&S(s,i,r)):(e.isArrowFunctionExpression(n)||e.isFunctionExpression(n),!1)}function q(n,i){let r=n,s=!1;if(e.isArrowFunctionExpression(n)&&n.params.length===0&&(r=n.body,s=!0),e.isConditionalExpression(r)){let o=D(r.consequent,i),a=D(r.alternate,i);if(o||a){let p=e.conditionalExpression(r.test,o||r.consequent,a||r.alternate);return s?e.arrowFunctionExpression([],p):p}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let o=D(r.right,i);if(o){let a=e.logicalExpression(r.operator,r.left,o);return s?e.arrowFunctionExpression([],a):a}return null}return D(r,i)}function D(n,i){if(!e.isCallExpression(n)||!e.isMemberExpression(n.callee)||!e.isIdentifier(n.callee.property,{name:"map"})||n.arguments.length<1)return null;let r=n.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let s=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))s=r.body;else if(e.isBlockStatement(r.body)){let l=r.body.body.find(d=>e.isReturnStatement(d));l&&(s=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(d=>e.isReturnStatement(d));l&&(s=l.argument)}if(!s||!e.isJSXElement(s))return null;let t=s.openingElement.attributes,o=null;for(let l of t)if(e.isJSXAttribute(l)&&C(l)==="key"){o=l;break}if(!o)return null;let a=$(o.value);if(!a)return null;s.openingElement.attributes=t.filter(l=>l!==o);let p=n.callee.object,c=e.arrowFunctionExpression([],p),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),u=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[c,r,e.objectExpression([e.objectProperty(e.identifier("key"),u),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function P(n){if(e.isJSXText(n))return!0;if(e.isJSXExpressionContainer(n))return!1;if(e.isJSXElement(n)){let i=n.openingElement,r=i.name.name;if(I(r))return!1;for(let s of i.attributes){if(e.isJSXSpreadAttribute(s))return!1;let t=s.value;if(e.isJSXExpressionContainer(t))return!1}return n.children.every(P)}return!1}function G(n){return e.isJSXSpreadAttribute(n)?!0:n.value?e.isJSXExpressionContainer(n.value):!1}function O(n){if(e.isJSXText(n)){let o=J(n.value);return o?Z(o):""}if(e.isJSXExpressionContainer(n))return e.isJSXEmptyExpression(n.expression)?"":"<!--$-->";if(!e.isJSXElement(n))return"";let i=n.openingElement,r=i.name.name;if(I(r))return"";let s=`<${r}`;for(let o of i.attributes){if(e.isJSXSpreadAttribute(o))continue;let a=C(o);if(a==="key"||a.startsWith("on")||a.startsWith("bind:")||a.includes("|"))continue;let p=a;if(a==="className"&&(p="class"),a==="htmlFor"&&(p="for"),!o.value)s+=` ${p}`;else if(e.isStringLiteral(o.value))s+=` ${p}="${se(o.value.value)}"`;else if(e.isJSXExpressionContainer(o.value))continue}let t=n.openingElement.selfClosing;if(t&&re(r))return s+=">",s;if(t)return s+=`></${r}>`,s;s+=">";for(let o of n.children)if(e.isJSXText(o)){let a=J(o.value);a&&(s+=Z(a))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||(s+="<!--$-->"):e.isJSXElement(o)&&(I(o.openingElement.name.name)?s+="<!--$-->":s+=O(o));return s+=`</${r}>`,s}function Z(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function se(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function N(n,i){let{node:r}=n,s=r.openingElement,t=s.name.name;if(t==="For")return ae(n,i);if(t==="Show")return le(n,i);if(I(t))return te(n,i);let o=s.attributes,a=r.children,p=a.every(P),c=o.every(E=>!G(E)),f=o.every(E=>{if(e.isJSXSpreadAttribute(E))return!1;let h=C(E);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(p&&c&&f){let E=O(r);if(E){let h=Y(i,E);return i.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let u=O(r);if(!u){let E=r.loc,h=i.filename||i.file?.opts?.filename||"<unknown>",x=E?`:${E.start.line}:${E.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${h}${x}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),i.needsH=!0,T(n,i)}let l=Y(i,u);i.needsTemplate=!0;let d=i.nextVarId(),m=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.callExpression(e.identifier(l),[]))])];return K(m,d,o,i,t),Q(m,d,a,r,i),i._pendingSetup||(i._pendingSetup=[]),i._pendingSetup.push(...m),e.identifier(d)}function T(n,i){let{node:r}=n,s=r.openingElement,t=s.name.name,o=s.attributes,a=r.children,p=[];for(let u of o){if(e.isJSXSpreadAttribute(u))continue;let l=C(u),d=$(u.value),m=W(l);p.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(m)?e.identifier(m):e.stringLiteral(m),d))}let c=[];for(let u of a)if(e.isJSXText(u)){let l=J(u.value);l&&c.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||c.push(u.expression):e.isJSXElement(u)?c.push(N({node:u},i)):e.isJSXFragment(u)&&c.push(j({node:u},i));let f=p.length>0?e.objectExpression(p):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),f,...c])}let oe=new Set(["input","textarea","select","option"]);function K(n,i,r,s,t){function o(c,f){return c==="class"?(s.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(i),f])):c==="style"?(s.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(i),f])):c==="value"&&t&&oe.has(t)?(s.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(i),f])):c==="checked"&&t==="input"?(s.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(i),f])):c.startsWith("data-")||c.startsWith("aria-")?(s.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(i),e.stringLiteral(c),f])):(s.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(i),e.stringLiteral(c),f]))}let a=!1;function p(){a||(a=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let c of r){if(e.isJSXSpreadAttribute(c)){s.needsSpread=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(i),c.argument])));continue}let f=C(c);if(f!=="key"){if(f==="ref"){let u=$(c.value);n.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(i)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(i)))));continue}if(f.startsWith("on")&&!f.includes("|")&&!A(f,s)){let u=f.slice(2).toLowerCase(),l=$(c.value);Se.has(u)?(s.needsDelegation=!0,s.delegatedEvents||(s.delegatedEvents=new Set),s.delegatedEvents.add(u),p(),n.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier(`$$${u}`)),l)))):n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral(u),l])));continue}if(f.startsWith("on")&&(f.includes("|")||A(f,s))){let{eventName:u,modifiers:l}=g(f),d=$(c.value),m=B(d,l),E=u.slice(2).toLowerCase(),h=l.filter(v=>xe.has(v)),x=[e.stringLiteral(E),m];if(h.length>0){let v=h.map(_=>e.objectProperty(e.identifier(_),e.booleanLiteral(!0)));x.push(e.objectExpression(v))}n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),x)));continue}if(b(f)){let u=L(f),l=c.value.expression;s.needsEffect=!0,u==="value"?(n.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier("value")),e.callExpression(e.cloneNode(l),[])))]))),n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(s.needsEffect=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier("checked")),e.callExpression(e.cloneNode(l),[])))]))),n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(c.value)){let u=c.value.expression,l=W(f);if(S(u,s.signalNames,s.importedIdentifiers)){s.needsEffect=!0;let d=e.isIdentifier(u)&&(k(u.name,s.signalNames)||s.importedIdentifiers&&s.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,m=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],o(l,d))]);z(u,s.signalNames,s.importedIdentifiers)&&e.addComment(m,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(m))}else n.push(e.expressionStatement(o(l,u)))}}}}function R(n){if(!n||typeof n!="object")return!1;if(Array.isArray(n))return n.some(R);if(n.type==="JSXElement"||n.type==="JSXFragment"||n.type==="CallExpression"&&n.callee&&n.callee.type==="Identifier"&&(n.callee.name==="_$mapArray"||n.callee.name==="mapArray"))return!0;for(let i of Object.keys(n)){if(i==="loc"||i==="start"||i==="end"||i==="leadingComments"||i==="trailingComments"||i==="innerComments")continue;let r=n[i];if(r&&typeof r=="object"&&R(r))return!0}return!1}function F(n,i,r){let s=null,t=!1;if(e.isConditionalExpression(n))s=n.test,t=!0;else if(e.isLogicalExpression(n)&&(n.operator==="&&"||n.operator==="||"))s=n.left;else return n;if(!S(s,r.signalNames,r.importedIdentifiers)||!(t?[n.consequent,n.alternate]:[n.right]).some(R))return n;let a=r.nextMemoId();r.needsMemo=!0;let p=t?e.unaryExpression("!",e.unaryExpression("!",s)):s;i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],p)]))]));let c=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(c,n.consequent,n.alternate):e.logicalExpression(n.operator,c,n.right)}function Q(n,i,r,s,t){let o=[],a=0;for(let l of r){if(e.isJSXText(l)){J(l.value)&&a++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;o.push({type:"expression",child:l,childIndex:a}),a++;continue}if(e.isJSXElement(l)){let d=l.openingElement.name.name;if(I(d)||d==="For"||d==="Show")o.push({type:"component",child:l,childIndex:a}),a++;else{let m=l.openingElement.attributes.some(G)||l.openingElement.attributes.some(E=>!e.isJSXSpreadAttribute(E)&&C(E)?.startsWith("on"))||!l.children.every(P);o.push({type:"static",child:l,childIndex:a,hasAnythingDynamic:m}),a++}continue}e.isJSXFragment(l)&&o.push({type:"fragment",child:l})}let p=o.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),c=p.length>=2,f=new Map;if(c){let l=null,d=0;for(let m of p){let E=m.childIndex,h=t.nextVarId();f.set(E,h);let x;if(l===null)x=V(i,E);else{x=e.identifier(l);for(let v=d;v<E;v++)x=e.memberExpression(x,e.identifier("nextSibling"))}n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),x)])),l=h,d=E}}function u(l){return f.has(l)?e.identifier(f.get(l)):V(i,l)}for(let l of o){if(l.type==="expression"){let d=l.child.expression,m=u(l.childIndex);t.needsInsert=!0;let E=q(d,t);if(E){t.needsMapArray=!0;let x=e.isCallExpression(E)&&e.isIdentifier(E.callee)&&(E.callee.name==="_$mapArray"||E.callee.name==="mapArray"),v=e.isArrowFunctionExpression(E);v&&e.isExpression(E.body)?E.body=F(E.body,n,t):!x&&!v&&(E=F(E,n,t));let _=x||v?E:e.arrowFunctionExpression([],E);n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),_,m])));continue}if(e.isCallExpression(d)&&e.isIdentifier(d.callee)&&(d.callee.name==="mapArray"||d.callee.name==="_$mapArray")){t.needsMapArray=!0,d.callee.name==="mapArray"&&(d.callee.name="_$mapArray"),n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),d,m])));continue}if(S(d,t.signalNames,t.importedIdentifiers)){d=F(d,n,t);let x=e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],d),m]);z(d,t.signalNames,t.importedIdentifiers)&&e.addComment(x,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(x))}else n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),d,m])));continue}if(l.type==="component"){let d=N({node:l.child},t),m=u(l.childIndex);t.needsInsert=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),d,m])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let d;f.has(l.childIndex)?d=f.get(l.childIndex):(d=t.nextVarId(),n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),V(i,l.childIndex))]))),K(n,d,l.child.openingElement.attributes,t,l.child.openingElement.name.name),Q(n,d,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let d of l.child.children)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){t.needsInsert=!0;let m=d.expression;S(m,t.signalNames,t.importedIdentifiers)?(m=F(m,n,t),n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],m)])))):n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),m])))}}}}function V(n,i){if(i===0)return e.memberExpression(e.identifier(n),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(n),e.identifier("firstChild"));for(let s=0;s<i;s++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function te(n,i){let{node:r}=n,s=r.openingElement,t=s.name.name,o=s.attributes,a=r.children,p=null,c=[];for(let h of o){if(e.isJSXAttribute(h)){let x;if(e.isJSXNamespacedName(h.name)?x=`${h.name.namespace.name}:${h.name.name.name}`:x=h.name.name,x&&typeof x=="string"&&x.startsWith("client:")){let v=x.slice(7);h.value?p={type:v,value:h.value.value}:p={type:v};continue}}c.push(h)}if(p){i.needsCreateComponent=!0,i.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),e.identifier(t)),e.objectProperty(e.identifier("mode"),e.stringLiteral(p.type))];p.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(p.value)));for(let x of c){if(e.isJSXSpreadAttribute(x))continue;let v=C(x),_=$(x.value);h.push(e.objectProperty(e.identifier(v),_))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(h),e.arrayExpression([])])}i.needsCreateComponent=!0;let f=[],u=!1,l=null;for(let h of c){if(e.isJSXSpreadAttribute(h)){u=!0,l=h.argument;continue}let x=C(h);if(x==="key")continue;if(b(x)){let _=L(x),X=h.value.expression;_==="value"?(f.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(X),[]))),f.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(X),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):_==="checked"&&(f.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(X),[]))),f.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(X),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(x.startsWith("on")&&(x.includes("|")||A(x,i))){let{eventName:_,modifiers:X}=g(x),me=$(h.value),Ee=B(me,X);f.push(e.objectProperty(e.identifier(_),Ee));continue}let v=$(h.value);f.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(x)?e.identifier(x):e.stringLiteral(x),v))}let d=[];for(let h of a)if(e.isJSXText(h)){let x=J(h.value);x&&d.push(e.stringLiteral(x))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||d.push(h.expression):e.isJSXElement(h)?d.push(N({node:h},i)):e.isJSXFragment(h)&&d.push(j({node:h},i));let m;u?f.length>0?m=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),l,e.objectExpression(f)]):m=l:f.length>0?m=e.objectExpression(f):m=e.nullLiteral();let E=d.length>0?e.arrayExpression(d):e.arrayExpression([]);return e.callExpression(e.identifier("_$createComponent"),[e.identifier(t),m,E])}function ae(n,i){let{node:r}=n,s=r.openingElement.attributes,t=r.children,o=null,a=null;for(let f of s)if(e.isJSXAttribute(f)){let u=C(f);u==="each"?o=$(f.value):u==="key"&&(a=$(f.value))}if(!o)return console.warn('[what-compiler] <For> element missing "each" attribute.'),i.needsH=!0,T(n,i);let p=null;for(let f of t)if(e.isJSXExpressionContainer(f)&&!e.isJSXEmptyExpression(f.expression)){p=f.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),i.needsH=!0,T(n,i);i.needsMapArray=!0;let c=[o,p];return a&&c.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),c)}function le(n,i){let{node:r}=n,s=r.openingElement.attributes,t=r.children,o=null,a=null;for(let m of s)if(e.isJSXAttribute(m)){let E=C(m);E==="when"?o=$(m.value):E==="fallback"&&(a=$(m.value))}if(!o)throw n.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let p=null;for(let m of t)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){p=m.expression;break}if(!p){let m=[];for(let E of t)if(e.isJSXText(E)){let h=J(E.value);h&&m.push(e.stringLiteral(h))}else e.isJSXElement(E)&&m.push(N({node:E},i));m.length===1?p=m[0]:m.length>1?p=e.arrayExpression(m):p=e.nullLiteral()}let c;e.isCallExpression(o)?c=o:e.isArrowFunctionExpression(o)&&e.isExpression(o.body)?c=o.body:e.isIdentifier(o)&&(i.signalNames&&k(o.name,i.signalNames)||i.importedIdentifiers&&i.importedIdentifiers.has(o.name))?c=e.callExpression(o,[]):c=o;let f=n.scope?n.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(p),l=u?e.callExpression(p,[e.cloneNode(f)]):p,d=a||e.nullLiteral();if(S(c,i.signalNames,i.importedIdentifiers)){let m=i.nextMemoId();i.needsMemo=!0;let E=u?c:e.unaryExpression("!",e.unaryExpression("!",c));i._pendingSetup||(i._pendingSetup=[]),i._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],E)]))])),c=e.callExpression(e.identifier(m),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(f,c)]),e.returnStatement(e.conditionalExpression(e.cloneNode(f),l,d))]))}function ce(n,i){i._pendingSetup||(i._pendingSetup=[]);let r=i._pendingSetup,s=q(n,i);if(s){i.needsMapArray=!0;let o=e.isCallExpression(s)&&e.isIdentifier(s.callee)&&(s.callee.name==="_$mapArray"||s.callee.name==="mapArray");if(e.isArrowFunctionExpression(s)&&e.isExpression(s.body))return s.body=F(s.body,r,i),s;if(o)return s;let p=F(s,r,i);return e.arrowFunctionExpression([],p)}return e.isCallExpression(n)&&e.isIdentifier(n.callee)&&(n.callee.name==="mapArray"||n.callee.name==="_$mapArray")?(i.needsMapArray=!0,n.callee.name==="mapArray"&&(n.callee.name="_$mapArray"),n):S(n,i.signalNames,i.importedIdentifiers)?(n=F(n,r,i),e.arrowFunctionExpression([],n)):n}function j(n,i){let{node:r}=n,s=r.children,t=[];for(let o of s)if(e.isJSXText(o)){let a=J(o.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||t.push(ce(o.expression,i)):e.isJSXElement(o)?t.push(N({node:o},i)):e.isJSXFragment(o)&&t.push(j({node:o},i));return t.length===1?t[0]:e.arrayExpression(t)}function Y(n,i){if(n.templateMap.has(i))return n.templateMap.get(i);let r=`_tmpl$${n.templateCount++}`;return n.templateMap.set(i,r),n.templates.push({id:r,html:i}),r}function ee(n,i,r){let s=n.scope,t=i._signalNamesCache;t||(t=i._signalNamesCache=new WeakMap);let o=t.get(s);o||(o=H(n),t.set(s,o)),i.signalNames=o,i._pendingSetup=[];let a=r(n,i),p=i._pendingSetup;if(i._pendingSetup=[],p.length>0){let c=n,f=!1;for(;c&&!c.isStatement();)(c.isArrowFunctionExpression()||c.isFunctionExpression())&&(f=!0),c=c.parentPath;c&&c.isStatement()&&(c.listKey==="body"||c.listKey==="consequent")&&Array.isArray(c.container)&&!f?(c.insertBefore(p),n.replaceWith(a)):(p.push(e.returnStatement(a)),n.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(p)),[])))}else n.replaceWith(a)}function fe(n){let i=n.parentPath;if(i?.isVariableDeclarator()&&e.isIdentifier(i.node.id))return i.node.id.name;if(i?.isAssignmentExpression()&&e.isIdentifier(i.node.left))return i.node.left.name;if(i?.isExportDefaultDeclaration())return"default";if(i?.isObjectProperty()&&!i.node.computed){if(e.isIdentifier(i.node.key))return i.node.key.name;if(e.isStringLiteral(i.node.key))return i.node.key.value}return null}function pe(n,i){let r=n.node.callee;return e.isIdentifier(r)?i.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&i.serverActionNamespaces.has(r.object.name)}function ue(n){if(!e.isObjectExpression(n))return{property:null,value:null};for(let i of n.properties)if(!(!e.isObjectProperty(i)||(e.isIdentifier(i.key)&&!i.computed?i.key.name:e.isStringLiteral(i.key)?i.key.value:null)!=="id"))return e.isStringLiteral(i.value)?{property:i,value:i.value.value}:e.isTemplateLiteral(i.value)&&i.value.expressions.length===0?{property:i,value:i.value.quasis[0]?.value.cooked||""}:{property:i,value:null};return{property:null,value:null}}function ie(n,i,r,s,t){let o=n.node.loc?.start||{line:0,column:0},a=`${t}:${o.line}:${o.column+1}`,p=`${t}#${s}`,c=i.serverActionIds.get(r);if(c)throw n.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${c.bindingName}" at ${c.source}; conflicts with "${s}" at ${a}.`);let f={id:r,key:p,bindingName:s,filename:t,source:a,loc:o};if(i.serverActionIds.set(r,f),typeof i.opts?.onActionId=="function")try{i.opts.onActionId(f)}catch(u){throw n.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function de(n,i){if(!pe(n,i))return;let r=fe(n);if(!r){i.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${i.serverActionFilename}:${n.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let s=n.node.arguments[1],t=ue(s);if(t.property){t.value!==null&&ie(n,i,t.value,r,i.serverActionFilename);return}let o=`wa1_${be(`${i.serverActionFilename}#${r}`)}`;ie(n,i,o,r,i.serverActionFilename);let a=e.objectProperty(e.identifier("id"),e.stringLiteral(o));s?e.isObjectExpression(s)?s.properties.unshift(a):n.node.arguments[1]=e.objectExpression([a,e.spreadElement(s)]):n.node.arguments.push(e.objectExpression([a]))}return{name:"what-jsx-transform",visitor:{Program:{enter(n,i){i.needsTemplate=!1,i.needsInsert=!1,i.needsEffect=!1,i.needsMapArray=!1,i.needsSpread=!1,i.needsSetProp=!1,i.needsMemo=!1,i.needsSetClass=!1,i.needsSetStyle=!1,i.needsSetAttr=!1,i.needsSetValue=!1,i.needsSetChecked=!1,i.needsH=!1,i.needsCreateComponent=!1,i.needsFragment=!1,i.needsIsland=!1,i.needsDelegation=!1,i.delegatedEvents=new Set,i.templates=[],i.templateMap=new Map,i.templateCount=0,i._varCounter=0,i._memoCounter=0,i._pendingSetup=[],i.nextVarId=()=>`_el$${i._varCounter++}`,i.nextMemoId=()=>`_c$${i._memoCounter++}`,i.serverActionBindings=new Set,i.serverActionNamespaces=new Set,i.serverActionIds=new Map,i.serverActionFilename=ve(i.file?.opts?.filename,i.opts?.projectRoot||i.file?.opts?.cwd),i.signalNames=new Set,i.importedIdentifiers=new Set;for(let r of n.node.body)if(e.isImportDeclaration(r)){let s=r.source.value,t=s==="what-framework"||s.startsWith("what-framework/")||s==="what-core"||s.startsWith("what-core/")||s.startsWith("./")||s.startsWith("../");for(let o of r.specifiers){let a=null;(e.isImportSpecifier(o)&&e.isIdentifier(o.local)||e.isImportDefaultSpecifier(o)&&e.isIdentifier(o.local)||e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local))&&(a=o.local.name),a&&(t||/^(use|create)[A-Z]/.test(a))&&i.importedIdentifiers.add(a),ye.has(s)&&(e.isImportSpecifier(o)&&e.isIdentifier(o.imported,{name:"action"})&&e.isIdentifier(o.local)?i.serverActionBindings.add(o.local.name):e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local)&&i.serverActionNamespaces.add(o.local.name))}}n.traverse({CallExpression(r){de(r,i)},VariableDeclarator(r){let s=r.node.init;if(!s||!e.isCallExpression(s))return;let t=s.callee,o="";if(e.isIdentifier(t)?o=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(o=t.property.name),ne.has(o)){let a=r.node.id;if(e.isIdentifier(a))i.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let p of a.elements)e.isIdentifier(p)&&i.signalNames.add(p.name);else if(e.isObjectPattern(a))for(let p of a.properties)e.isObjectProperty(p)&&e.isIdentifier(p.value)&&i.signalNames.add(p.value.name)}}})},exit(n,i){for(let t of i.templates.reverse()){let o=e.callExpression(e.identifier("_$template"),[e.stringLiteral(t.html)]);e.addComment(o,"leading"," @__PURE__ "),n.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t.id),o)]))}let r=[];i.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),i.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),i.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),i.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),i.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),i.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),i.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),i.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),i.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),i.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),i.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),i.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),i.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),i.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let s=[];if(i.needsH&&s.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),i.needsFragment&&s.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),i.needsIsland&&s.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let t=null;for(let o of n.node.body)if(e.isImportDeclaration(o)&&(o.source.value==="what-framework/render"||o.source.value==="what-core/render")){t=o;break}if(t){let o=new Set(t.specifiers.filter(a=>e.isImportSpecifier(a)).map(a=>a.imported.name));for(let a of r)o.has(a.imported.name)||t.specifiers.push(a)}else n.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(s.length>0&&Ae(n,e,s),i.needsDelegation&&i.delegatedEvents&&i.delegatedEvents.size>0){let t=e.arrayExpression([...i.delegatedEvents].map(a=>e.stringLiteral(a))),o=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));n.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),o])}}},JSXElement(n,i){ee(n,i,N)},JSXFragment(n,i){ee(n,i,j)}}}}function Ae(e,y,w){let A=null;for(let g of e.node.body)if(y.isImportDeclaration(g)&&(g.source.value==="what-core"||g.source.value==="what-framework")){A=g;break}if(A){let g=new Set(A.specifiers.filter(b=>y.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of w)g.has(b.imported.name)||A.specifiers.push(b)}else{let g=y.importDeclaration(w,y.stringLiteral("what-framework"));e.unshiftContainer("body",g)}}export{we as default};
1
+ var Ce=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),$e=new Set(["once","capture","passive"]),Ie=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ke=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),T=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),le=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),Fe=new Set(["For","Show","Switch","Match"]),Je=new Set(["what-framework/server","what-server","what-server/actions"]);function Xe(e){let v=0xcbf29ce484222325n;for(let _=0;_<e.length;_++)v^=BigInt(e.charCodeAt(_)),v=BigInt.asUintN(64,v*0x100000001b3n);return v.toString(36)}function Me(e,v){let _=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(v||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&_.startsWith(`${C}/`)?_.slice(C.length+1):_.replace(/^\.\//,"")}function F(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let v=e.split(/\r\n|\n|\r/),_=-1;for(let b=0;b<v.length;b++)/[^ \t]/.test(v[b])&&(_=b);if(_===-1)return"";let C="";for(let b=0;b<v.length;b++){let A=v[b].replace(/\t/g," "),j=b===0,O=b===v.length-1;j||(A=A.replace(/^ +/,"")),O||(A=A.replace(/ +$/,"")),A&&(b!==_&&(A+=" "),C+=A)}return C}function Le({types:e}){let v=new Set,_=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function b(i){let n=i.includes("|")?"|":"__",r=i.split(n),s=r[0],t=r.slice(1).filter(a=>Ce.has(a));return{eventName:s,modifiers:t}}function A(i){return i.startsWith("bind:")}function j(i){return i.slice(5)}function O(i){return/^[A-Z]/.test(i)}function L(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&O(n.name)}function D(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function ce(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function fe(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function U(i){return e.isJSXMemberExpression(i)?e.memberExpression(U(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function pe(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],s=-1;for(let c=0;c<r.properties.length;c++){let d=r.properties[c];if(e.isRestElement(d))return;if(e.isObjectProperty(d)&&!d.computed&&e.isIdentifier(d.key,{name:"children"})){if(s!==-1||!e.isIdentifier(d.value))return;s=c}}if(s===-1)return;let t=i.scope.getBinding(r.properties[s].value.name);if(!t||t.constantViolations.length>0||t.referencePaths.length===0||!t.referencePaths.every(c=>{let d=c.parentPath;if(!d||!d.isJSXExpressionContainer())return!1;let f=d.parentPath;if(!f||!f.isJSXElement()||!L(f.node))return!1;let l=f.node.openingElement.name;return!(e.isJSXIdentifier(l)&&Fe.has(l.name))}))return;let o=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(o.typeAnnotation=r.typeAnnotation),n[0]=o;let u=r.properties.filter((c,d)=>d!==s);if(u.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let c=e.objectPattern(u);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(c,e.cloneNode(o))])),i.node._whatMovedProps=c}for(let c of t.referencePaths)c.replaceWith(e.memberExpression(e.cloneNode(o),e.identifier("children")));i.scope.crawl()}function ue(i){return Ie.has(String(i).toLowerCase())}function $(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function G(i){return i==="className"?"class":i==="htmlFor"?"for":i}function I(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function de(i){return!!i&&i.length>2&&/^on/i.test(i)}function z(i,n){if(n.length===0)return i;let r=i;for(let s of n)switch(s){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function J(i,n){return n.has(i)}function q(i){let n=new Set;function r(a){let o=a.init;if(!o||!e.isCallExpression(o))return;let u=o.callee,c="";if(e.isIdentifier(u)?c=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(c=u.property.name),le.has(c)){let d=a.id;if(e.isIdentifier(d))n.add(d.name);else if(e.isArrayPattern(d))for(let f of d.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(d))for(let f of d.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function s(a){if(e.isObjectPattern(a))for(let o of a.properties)e.isObjectProperty(o)&&e.isIdentifier(o.value)?n.add(o.value.name):e.isRestElement(o)&&e.isIdentifier(o.argument)&&n.add(o.argument.name)}let t=i.scope;for(;t;){for(let o of Object.values(t.bindings))o.path.isVariableDeclarator()&&r(o.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let o of a.params)s(o);a._whatMovedProps&&s(a._whatMovedProps)}t=t.parent}return n}function je(i){return q(i)}function Z(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?T.has(n.object.name):e.isIdentifier(n)?T.has(n.name):!1}function K(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)||Z(i))return!1;if(i.arguments.some(s=>y(s,n,r)))return!0}return!1}function y(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)?!0:Z(i)?i.arguments.some(s=>y(s,n,r)):e.isIdentifier(i.callee)?i.arguments.some(s=>y(s,n,r)):y(i.callee,n,r)||i.arguments.some(s=>y(s,n,r)):e.isIdentifier(i)?J(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?y(i.object,n,r):e.isConditionalExpression(i)?y(i.test,n,r)||y(i.consequent,n,r)||y(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?y(i.left,n,r)||y(i.right,n,r):e.isUnaryExpression(i)?y(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(s=>y(s,n,r)):e.isObjectExpression(i)?i.properties.some(s=>e.isObjectProperty(s)&&y(s.value,n,r)):e.isArrayExpression(i)?i.elements.some(s=>s&&y(s,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function Q(i,n){let r=i,s=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,s=!0),e.isConditionalExpression(r)){let a=P(r.consequent,n),o=P(r.alternate,n);if(a||o){let u=e.conditionalExpression(r.test,a||r.consequent,o||r.alternate);return s?e.arrowFunctionExpression([],u):u}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=P(r.right,n);if(a){let o=e.logicalExpression(r.operator,r.left,a);return s?e.arrowFunctionExpression([],o):o}return null}return P(r,n)}function P(i,n){if(!e.isCallExpression(i)||!e.isMemberExpression(i.callee)||!e.isIdentifier(i.callee.property,{name:"map"})||i.arguments.length<1)return null;let r=i.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let s=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))s=r.body;else if(e.isBlockStatement(r.body)){let l=r.body.body.find(E=>e.isReturnStatement(E));l&&(s=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(E=>e.isReturnStatement(E));l&&(s=l.argument)}if(!s||!e.isJSXElement(s))return null;let t=s.openingElement.attributes,a=null;for(let l of t)if(e.isJSXAttribute(l)&&I(l)==="key"){a=l;break}if(!a)return null;let o=$(a.value);if(!o)return null;s.openingElement.attributes=t.filter(l=>l!==a);let u=i.callee.object,c=e.arrowFunctionExpression([],u),d=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),f=e.arrowFunctionExpression([d],e.cloneNode(o,!0));return e.callExpression(e.identifier("_$mapArray"),[c,r,e.objectExpression([e.objectProperty(e.identifier("key"),f),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function R(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(L(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let s=r.value;if(e.isJSXExpressionContainer(s))return!1}return i.children.every(R)}return!1}function Y(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function W(i){if(e.isJSXText(i)){let a=F(i.value);return a?ee(a):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(L(i))return"";let s=`<${r}`;for(let a of n.attributes){if(e.isJSXSpreadAttribute(a))continue;let o=I(a);if(o==="key"||de(o)||o.startsWith("bind:")||o.includes("|"))continue;let u=o;if(o==="className"&&(u="class"),o==="htmlFor"&&(u="for"),!a.value)s+=` ${u}`;else if(e.isStringLiteral(a.value))s+=` ${u}="${me(a.value.value)}"`;else if(e.isJSXExpressionContainer(a.value))continue}let t=i.openingElement.selfClosing;if(t&&ue(r))return s+=">",s;if(t)return s+=`></${r}>`,s;s+=">";for(let a of i.children)if(e.isJSXText(a)){let o=F(a.value);o&&(s+=ee(o))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||(s+="<!--$-->"):e.isJSXElement(a)&&(L(a)?s+="<!--$-->":s+=W(a));return s+=`</${r}>`,s}function ee(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function me(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(i,n){let{node:r}=i,s=r.openingElement,t=s.name.name;if(!D(t,n)){if(t==="For")return he(i,n);if(t==="Show")return ge(i,n)}if(t==="Switch"&&(!D(t,n)||fe(r)))return xe(i,n);if(L(r))return re(i,n);let a=s.attributes,o=r.children,u=o.every(R),c=a.every(p=>!Y(p)),d=a.every(p=>{if(e.isJSXSpreadAttribute(p))return!1;let h=I(p);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(u&&c&&d){let p=W(r);if(p){let h=oe(n,p);return n.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let f=W(r);if(!f){let p=r.loc,h=n.filename||n.file?.opts?.filename||"<unknown>",g=p?`:${p.start.line}:${p.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${h}${g}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,V(i,n)}let l=oe(n,f);n.needsTemplate=!0;let E=n.nextVarId(),m=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier(l),[]))])];return ne(m,E,a,n,t),ie(m,E,o,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...m),e.identifier(E)}function V(i,n){let{node:r}=i,s=r.openingElement,t=s.name.name,a=s.attributes,o=r.children,u=[];for(let f of a){if(e.isJSXSpreadAttribute(f))continue;let l=I(f),E=$(f.value),m=G(l);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(m)?e.identifier(m):e.stringLiteral(m),E))}let c=[];for(let f of o)if(e.isJSXText(f)){let l=F(f.value);l&&c.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(f)?e.isJSXEmptyExpression(f.expression)||c.push(f.expression):e.isJSXElement(f)?c.push(X({node:f},n)):e.isJSXFragment(f)&&c.push(N({node:f},n));let d=u.length>0?e.objectExpression(u):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),d,...c])}let Ee=new Set(["input","textarea","select","option"]);function ne(i,n,r,s,t){function a(c,d){return c==="class"?(s.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):c==="style"?(s.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):c==="value"&&t&&Ee.has(t)?(s.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):c==="checked"&&t==="input"?(s.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):c.startsWith("data-")||c.startsWith("aria-")?(s.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(c),d])):(s.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(c),d]))}let o=!1;function u(){o||(o=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let c of r){if(e.isJSXSpreadAttribute(c)){s.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),c.argument])));continue}let d=I(c);if(d!=="key"){if(d==="ref"){let f=$(c.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",f),e.stringLiteral("function")),e.callExpression(e.cloneNode(f),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(f),e.identifier("current")),e.identifier(n)))));continue}if(d.startsWith("on")&&!d.includes("|")&&!C(d,s)){let f=d.slice(2).toLowerCase(),l=$(c.value);ke.has(f)?(s.needsDelegation=!0,s.delegatedEvents||(s.delegatedEvents=new Set),s.delegatedEvents.add(f),u(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${f}`)),l)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(f),l])));continue}if(d.startsWith("on")&&(d.includes("|")||C(d,s))){let{eventName:f,modifiers:l}=b(d),E=$(c.value),m=z(E,l),p=f.slice(2).toLowerCase(),h=l.filter(x=>$e.has(x)),g=[e.stringLiteral(p),m];if(h.length>0){let x=h.map(w=>e.objectProperty(e.identifier(w),e.booleanLiteral(!0)));g.push(e.objectExpression(x))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),g)));continue}if(A(d)){let f=j(d),l=c.value.expression;s.needsEffect=!0,f==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):f==="checked"&&(s.needsEffect=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("checked")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(c.value)){let f=c.value.expression,l=G(d);if(y(f,s.signalNames,s.importedIdentifiers)){s.needsEffect=!0;let E=e.isIdentifier(f)&&(J(f.name,s.signalNames)||s.importedIdentifiers&&s.importedIdentifiers.has(f.name))?e.callExpression(f,[]):f,m=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(l,E))]);K(f,s.signalNames,s.importedIdentifiers)&&e.addComment(m,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(m))}else i.push(e.expressionStatement(a(l,f)))}}}}function B(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(B);if(i.type==="JSXElement"||i.type==="JSXFragment"||i.type==="CallExpression"&&i.callee&&i.callee.type==="Identifier"&&(i.callee.name==="_$mapArray"||i.callee.name==="mapArray"))return!0;for(let n of Object.keys(i)){if(n==="loc"||n==="start"||n==="end"||n==="leadingComments"||n==="trailingComments"||n==="innerComments")continue;let r=i[n];if(r&&typeof r=="object"&&B(r))return!0}return!1}function M(i,n,r){let s=null,t=!1;if(e.isConditionalExpression(i))s=i.test,t=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))s=i.left;else return i;if(!y(s,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(B))return i;let o=r.nextMemoId();r.needsMemo=!0;let u=t?e.unaryExpression("!",e.unaryExpression("!",s)):s;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],u)]))]));let c=e.callExpression(e.identifier(o),[]);return t?e.conditionalExpression(c,i.consequent,i.alternate):e.logicalExpression(i.operator,c,i.right)}function ie(i,n,r,s,t){let a=[],o=0;for(let l of r){if(e.isJSXText(l)){F(l.value)&&o++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:o}),o++;continue}if(e.isJSXElement(l)){let E=l.openingElement.name.name;if(L(l)||E==="For"||E==="Show")a.push({type:"component",child:l,childIndex:o}),o++;else{let m=l.openingElement.attributes.some(Y)||l.openingElement.attributes.some(p=>!e.isJSXSpreadAttribute(p)&&I(p)?.startsWith("on"))||!l.children.every(R);a.push({type:"static",child:l,childIndex:o,hasAnythingDynamic:m}),o++}continue}e.isJSXFragment(l)&&a.push({type:"fragment",child:l})}let u=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),c=u.length>=2,d=new Map;if(c){let l=null,E=0;for(let m of u){let p=m.childIndex,h=t.nextVarId();d.set(p,h);let g;if(l===null)g=H(n,p);else{g=e.identifier(l);for(let x=E;x<p;x++)g=e.memberExpression(g,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),g)])),l=h,E=p}}function f(l){return d.has(l)?e.identifier(d.get(l)):H(n,l)}for(let l of a){if(l.type==="expression"){let E=l.child.expression,m=f(l.childIndex);t.needsInsert=!0;let p=Q(E,t);if(p){t.needsMapArray=!0;let g=e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="_$mapArray"||p.callee.name==="mapArray"),x=e.isArrowFunctionExpression(p);x&&e.isExpression(p.body)?p.body=M(p.body,i,t):!g&&!x&&(p=M(p,i,t));let w=g||x?p:e.arrowFunctionExpression([],p);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),w,m])));continue}if(e.isCallExpression(E)&&e.isIdentifier(E.callee)&&(E.callee.name==="mapArray"||E.callee.name==="_$mapArray")){t.needsMapArray=!0,E.callee.name==="mapArray"&&(E.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,m])));continue}if(y(E,t.signalNames,t.importedIdentifiers)){E=M(E,i,t);let g=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],E),m]);K(E,t.signalNames,t.importedIdentifiers)&&e.addComment(g,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(g))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,m])));continue}if(l.type==="component"){let E=X({node:l.child},t),m=f(l.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,m])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let E;d.has(l.childIndex)?E=d.get(l.childIndex):(E=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),H(n,l.childIndex))]))),ne(i,E,l.child.openingElement.attributes,t,l.child.openingElement.name.name),ie(i,E,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let E of l.child.children)if(e.isJSXExpressionContainer(E)&&!e.isJSXEmptyExpression(E.expression)){t.needsInsert=!0;let m=E.expression;y(m,t.signalNames,t.importedIdentifiers)?(m=M(m,i,t),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],m)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m])))}}}}function H(i,n){if(n===0)return e.memberExpression(e.identifier(i),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(i),e.identifier("firstChild"));for(let s=0;s<n;s++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function re(i,n){let{node:r}=i,s=r.openingElement,t=U(s.name),a=s.attributes,o=r.children,u=null,c=[];for(let h of a){if(e.isJSXAttribute(h)){let g;if(e.isJSXNamespacedName(h.name)?g=`${h.name.namespace.name}:${h.name.name.name}`:g=h.name.name,g&&typeof g=="string"&&g.startsWith("client:")){let x=g.slice(7);h.value?u={type:x,value:h.value.value}:u={type:x};continue}}c.push(h)}function d(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],x=!1;for(let S of o)if(e.isJSXText(S)){let k=F(S.value);k&&g.push(e.stringLiteral(k))}else if(e.isJSXExpressionContainer(S))e.isJSXEmptyExpression(S.expression)||(x=!0,g.push(S.expression));else if(e.isJSXElement(S)){let k=S.openingElement.name.name;k!=="For"&&k!=="Show"&&k!=="Switch"&&(x=!0),g.push(X({node:S},n))}else e.isJSXFragment(S)&&(x=!0,g.push(N({node:S},n)));let w=e.arrayExpression(g);if(x){let S=n._pendingSetup?n._pendingSetup.splice(h):[];w=e.arrowFunctionExpression([],S.length>0?e.blockStatement([...S,e.returnStatement(w)]):w)}return w}if(u){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(u.type))];u.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(u.value)));let g=null;for(let w of c){if(e.isJSXSpreadAttribute(w)){g=w.argument;continue}let S=I(w);if(S==="key")continue;let k=$(w.value);h.push(e.objectProperty(e.identifier(S),k))}let x=g?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),g,e.objectExpression(h)]):e.objectExpression(h);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),x,d()])}n.needsCreateComponent=!0;let f=[],l=!1,E=null;for(let h of c){if(e.isJSXSpreadAttribute(h)){l=!0,E=h.argument;continue}let g=I(h);if(g==="key")continue;if(A(g)){let w=j(g),S=h.value.expression;w==="value"?(f.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(S),[]))),f.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):w==="checked"&&(f.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(S),[]))),f.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(g.startsWith("on")&&(g.includes("|")||C(g,n))){let{eventName:w,modifiers:S}=b(g),k=$(h.value),_e=z(k,S);f.push(e.objectProperty(e.identifier(w),_e));continue}let x=$(h.value);f.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),x))}let m;l?f.length>0?m=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),E,e.objectExpression(f)]):m=E:f.length>0?m=e.objectExpression(f):m=e.nullLiteral();let p=d();return e.callExpression(e.identifier("_$createComponent"),[t,m,p])}function he(i,n){let{node:r}=i,s=r.openingElement.attributes,t=r.children,a=null,o=null;for(let d of s)if(e.isJSXAttribute(d)){let f=I(d);f==="each"?a=$(d.value):f==="key"&&(o=$(d.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,V(i,n);let u=null;for(let d of t)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){u=d.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,V(i,n);n.needsMapArray=!0;let c=[a,u];return o&&c.push(e.objectExpression([e.objectProperty(e.identifier("key"),o)])),e.callExpression(e.identifier("_$mapArray"),c)}function ge(i,n){let{node:r}=i,s=r.openingElement.attributes,t=r.children,a=null,o=null;for(let m of s)if(e.isJSXAttribute(m)){let p=I(m);p==="when"?a=$(m.value):p==="fallback"&&(o=$(m.value))}if(!a)throw i.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let u=null;for(let m of t)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){u=m.expression;break}if(!u){let m=[];for(let p of t)if(e.isJSXText(p)){let h=F(p.value);h&&m.push(e.stringLiteral(h))}else e.isJSXElement(p)&&m.push(X({node:p},n));m.length===1?u=m[0]:m.length>1?u=e.arrayExpression(m):u=e.nullLiteral()}let c=se(a,n),d=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),f=e.isFunction(u),l=f?e.callExpression(u,[e.cloneNode(d)]):u,E=o||e.nullLiteral();if(y(c,n.signalNames,n.importedIdentifiers)){let m=n.nextMemoId();n.needsMemo=!0;let p=f?c:e.unaryExpression("!",e.unaryExpression("!",c));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],p)]))])),c=e.callExpression(e.identifier(m),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(d,c)]),e.returnStatement(e.conditionalExpression(e.cloneNode(d),l,E))]))}function se(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&J(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Se(i,n){let r=[];for(let s of i)if(e.isJSXText(s)){let t=F(s.value);t&&r.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||r.push(s.expression):e.isJSXElement(s)?r.push(X({node:s},n)):e.isJSXFragment(s)&&r.push(N({node:s},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function xe(i,n){let{node:r}=i,s=D(r.openingElement.name.name,n),t=p=>e.isJSXElement(p)&&e.isJSXIdentifier(p.openingElement.name,{name:"Match"})&&(s||!D("Match",n));if(!r.children.some(t)&&!ce(r.openingElement.name.name,n))return re(i,n);let a=p=>{let h=`<Switch> ${p}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`;throw i.buildCodeFrameError?i.buildCodeFrameError(h):new Error(`[what-compiler] ${h}`)},o=null;for(let p of r.openingElement.attributes)e.isJSXSpreadAttribute(p)&&a("cannot take a spread attribute"),I(p)==="fallback"&&(o=$(p.value));let u=[];for(let p of r.children){if(e.isJSXText(p)){F(p.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(p)){if(e.isJSXEmptyExpression(p.expression))continue;a("cannot read its arms from an expression child")}t(p)||a("cannot mix other elements with its <Match> arms"),u.push(p)}u.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let c=[];for(let p of u){let h=null;for(let S of p.openingElement.attributes)e.isJSXAttribute(S)&&I(S)==="when"&&(h=$(S.value));h||a('has a <Match> with no "when" prop');let g=n._pendingSetup.length,x=Se(p.children,n),w=n._pendingSetup.splice(g);w.length>0&&(x=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...w,e.returnStatement(x)])),[])),c.push([se(h,n),x])}let d=c.some(([p])=>y(p,n.signalNames,n.importedIdentifiers)),f=o||e.nullLiteral();if(!d){let p=f;for(let h=c.length-1;h>=0;h--)p=e.conditionalExpression(c[h][0],c[h][1],p);return e.arrowFunctionExpression([],p)}let l=e.numericLiteral(-1);for(let p=c.length-1;p>=0;p--)l=e.conditionalExpression(c[p][0],e.numericLiteral(p),l);let E=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let m=f;for(let p=c.length-1;p>=0;p--)m=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(E),[]),e.numericLiteral(p)),c[p][1],m);return e.arrowFunctionExpression([],m)}function be(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,s=Q(i,n);if(s){n.needsMapArray=!0;let a=e.isCallExpression(s)&&e.isIdentifier(s.callee)&&(s.callee.name==="_$mapArray"||s.callee.name==="mapArray");if(e.isArrowFunctionExpression(s)&&e.isExpression(s.body))return s.body=M(s.body,r,n),s;if(a)return s;let u=M(s,r,n);return e.arrowFunctionExpression([],u)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):y(i,n.signalNames,n.importedIdentifiers)?(i=M(i,r,n),e.arrowFunctionExpression([],i)):i}function N(i,n){let{node:r}=i,s=r.children,t=[];for(let a of s)if(e.isJSXText(a)){let o=F(a.value);o&&t.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||t.push(be(a.expression,n)):e.isJSXElement(a)?t.push(X({node:a},n)):e.isJSXFragment(a)&&t.push(N({node:a},n));return t.length===1?t[0]:e.arrayExpression(t)}function oe(i,n){if(i.templateMap.has(n))return i.templateMap.get(n);let r=`_tmpl$${i.templateCount++}`;return i.templateMap.set(n,r),i.templates.push({id:r,html:n}),r}function te(i,n,r){let s=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let a=t.get(s);a||(a=q(i),t.set(s,a)),n.signalNames=a,n._pendingSetup=[];let o=r(i,n),u=n._pendingSetup;if(n._pendingSetup=[],u.length>0){let c=i,d=!1;for(;c&&!c.isStatement();)(c.isArrowFunctionExpression()||c.isFunctionExpression())&&(d=!0),c=c.parentPath;c&&c.isStatement()&&(c.listKey==="body"||c.listKey==="consequent")&&Array.isArray(c.container)&&!d?(c.insertBefore(u),i.replaceWith(o)):(u.push(e.returnStatement(o)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(u)),[])))}else i.replaceWith(o)}function ye(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function we(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function ve(i){if(!e.isObjectExpression(i))return{property:null,value:null};for(let n of i.properties)if(!(!e.isObjectProperty(n)||(e.isIdentifier(n.key)&&!n.computed?n.key.name:e.isStringLiteral(n.key)?n.key.value:null)!=="id"))return e.isStringLiteral(n.value)?{property:n,value:n.value.value}:e.isTemplateLiteral(n.value)&&n.value.expressions.length===0?{property:n,value:n.value.quasis[0]?.value.cooked||""}:{property:n,value:null};return{property:null,value:null}}function ae(i,n,r,s,t){let a=i.node.loc?.start||{line:0,column:0},o=`${t}:${a.line}:${a.column+1}`,u=`${t}#${s}`,c=n.serverActionIds.get(r);if(c)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${c.bindingName}" at ${c.source}; conflicts with "${s}" at ${o}.`);let d={id:r,key:u,bindingName:s,filename:t,source:o,loc:a};if(n.serverActionIds.set(r,d),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(d)}catch(f){throw i.buildCodeFrameError(f instanceof Error?f.message:String(f))}}function Ae(i,n){if(!we(i,n))return;let r=ye(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let s=i.node.arguments[1],t=ve(s);if(t.property){t.value!==null&&ae(i,n,t.value,r,n.serverActionFilename);return}let a=`wa1_${Xe(`${n.serverActionFilename}#${r}`)}`;ae(i,n,a,r,n.serverActionFilename);let o=e.objectProperty(e.identifier("id"),e.stringLiteral(a));s?e.isObjectExpression(s)?s.properties.unshift(o):i.node.arguments[1]=e.objectExpression([o,e.spreadElement(s)]):i.node.arguments.push(e.objectExpression([o]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Me(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set,n.whatImports=new Set,n.foreignImports=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let s=r.source.value,t=s==="what-framework"||s.startsWith("what-framework/")||s==="what-core"||s.startsWith("what-core/"),a=t||s.startsWith("./")||s.startsWith("../");for(let o of r.specifiers){let u=null;(e.isImportSpecifier(o)&&e.isIdentifier(o.local)||e.isImportDefaultSpecifier(o)&&e.isIdentifier(o.local)||e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local))&&(u=o.local.name),u&&((a||/^(use|create)[A-Z]/.test(u))&&n.importedIdentifiers.add(u),t?n.whatImports.add(u):s.startsWith(".")||n.foreignImports.add(u)),Je.has(s)&&(e.isImportSpecifier(o)&&e.isIdentifier(o.imported,{name:"action"})&&e.isIdentifier(o.local)?n.serverActionBindings.add(o.local.name):e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local)&&n.serverActionNamespaces.add(o.local.name))}}i.traverse({Function(r){pe(r)},CallExpression(r){Ae(r,n)},VariableDeclarator(r){let s=r.node.init;if(!s||!e.isCallExpression(s))return;let t=s.callee,a="";if(e.isIdentifier(t)?a=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(a=t.property.name),le.has(a)){let o=r.node.id;if(e.isIdentifier(o))n.signalNames.add(o.name);else if(e.isArrayPattern(o))for(let u of o.elements)e.isIdentifier(u)&&n.signalNames.add(u.name);else if(e.isObjectPattern(o))for(let u of o.properties)e.isObjectProperty(u)&&e.isIdentifier(u.value)&&n.signalNames.add(u.value.name)}}})},exit(i,n){for(let t of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(t.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let s=[];if(n.needsH&&s.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&s.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&s.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let t=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){t=a;break}if(t){let a=new Set(t.specifiers.filter(o=>e.isImportSpecifier(o)).map(o=>o.imported.name));for(let o of r)a.has(o.imported.name)||t.specifiers.push(o)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(s.length>0&&Ne(i,e,s),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let t=e.arrayExpression([...n.delegatedEvents].map(o=>e.stringLiteral(o))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){te(i,n,X)},JSXFragment(i,n){te(i,n,N)}}}}function Ne(e,v,_){let C=null;for(let b of e.node.body)if(v.isImportDeclaration(b)&&(b.source.value==="what-core"||b.source.value==="what-framework")){C=b;break}if(C){let b=new Set(C.specifiers.filter(A=>v.isImportSpecifier(A)).map(A=>A.imported.name));for(let A of _)b.has(A.imported.name)||C.specifiers.push(A)}else{let b=v.importDeclaration(_,v.stringLiteral("what-framework"));e.unshiftContainer("body",b)}}export{Le as default};
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
- var Oe=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Te=new Set(["once","capture","passive"]),je=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),De=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),K=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),he=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),Je=new Set(["what-framework/server","what-server","what-server/actions"]);function Re(e){let u=0xcbf29ce484222325n;for(let x=0;x<e.length;x++)u^=BigInt(e.charCodeAt(x)),u=BigInt.asUintN(64,u*0x100000001b3n);return u.toString(36)}function Xe(e,u){let x=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),k=String(u||"").replace(/\\/g,"/").replace(/\/+$/,"");return k&&x.startsWith(`${k}/`)?x.slice(k.length+1):x.replace(/^\.\//,"")}function W(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let u=e.split(/\r\n|\n|\r/),x=-1;for(let _=0;_<u.length;_++)/[^ \t]/.test(u[_])&&(x=_);if(x===-1)return"";let k="";for(let _=0;_<u.length;_++){let C=u[_].replace(/\t/g," "),F=_===0,A=_===u.length-1;F||(C=C.replace(/^ +/,"")),A||(C=C.replace(/ +$/,"")),C&&(_!==x&&(C+=" "),k+=C)}return k}function Y({types:e}){let u=new Set,x=new Set;function k(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function _(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(s=>Oe.has(s));return{eventName:o,modifiers:t}}function C(i){return i.startsWith("bind:")}function F(i){return i.slice(5)}function A(i){return/^[A-Z]/.test(i)}function N(i){return je.has(String(i).toLowerCase())}function w(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function v(i){return i==="className"?"class":i==="htmlFor"?"for":i}function I(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function L(i,n){if(n.length===0)return i;let r=i;for(let o of n)switch(o){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function M(i,n){return n.has(i)}function T(i){let n=new Set;function r(t){let s=t.init;if(!s||!e.isCallExpression(s))return;let a=s.callee,p="";if(e.isIdentifier(a)?p=a.name:e.isMemberExpression(a)&&e.isIdentifier(a.property)&&(p=a.property.name),he.has(p)){let c=t.id;if(e.isIdentifier(c))n.add(c.name);else if(e.isArrayPattern(c))for(let f of c.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(c))for(let f of c.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}let o=i.scope;for(;o;){for(let s of Object.values(o.bindings))s.path.isVariableDeclarator()&&r(s.path.node);let t=o.path&&o.path.node;if(t&&t.params){for(let s of t.params)if(e.isObjectPattern(s))for(let a of s.properties)e.isObjectProperty(a)&&e.isIdentifier(a.value)?n.add(a.value.name):e.isRestElement(a)&&e.isIdentifier(a.argument)&&n.add(a.argument.name)}o=o.parent}return n}function R(i){return T(i)}function y(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?K.has(n.object.name):e.isIdentifier(n)?K.has(n.name):!1}function $(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&M(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!K.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&M(i.callee.object.name,n)||y(i))return!1;if(i.arguments.some(o=>S(o,n,r)))return!0}return!1}function S(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&M(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!K.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&M(i.callee.object.name,n)?!0:y(i)?i.arguments.some(o=>S(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>S(o,n,r)):S(i.callee,n,r)||i.arguments.some(o=>S(o,n,r)):e.isIdentifier(i)?M(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?S(i.object,n,r):e.isConditionalExpression(i)?S(i.test,n,r)||S(i.consequent,n,r)||S(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?S(i.left,n,r)||S(i.right,n,r):e.isUnaryExpression(i)?S(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>S(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&S(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&S(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function H(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let s=D(r.consequent,n),a=D(r.alternate,n);if(s||a){let p=e.conditionalExpression(r.test,s||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],p):p}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let s=D(r.right,n);if(s){let a=e.logicalExpression(r.operator,r.left,s);return o?e.arrowFunctionExpression([],a):a}return null}return D(r,n)}function D(i,n){if(!e.isCallExpression(i)||!e.isMemberExpression(i.callee)||!e.isIdentifier(i.callee.property,{name:"map"})||i.arguments.length<1)return null;let r=i.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let o=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))o=r.body;else if(e.isBlockStatement(r.body)){let l=r.body.body.find(m=>e.isReturnStatement(m));l&&(o=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(m=>e.isReturnStatement(m));l&&(o=l.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,s=null;for(let l of t)if(e.isJSXAttribute(l)&&I(l)==="key"){s=l;break}if(!s)return null;let a=w(s.value);if(!a)return null;o.openingElement.attributes=t.filter(l=>l!==s);let p=i.callee.object,c=e.arrowFunctionExpression([],p),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),d=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[c,r,e.objectExpression([e.objectProperty(e.identifier("key"),d),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function z(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement,r=n.name.name;if(A(r))return!1;for(let o of n.attributes){if(e.isJSXSpreadAttribute(o))return!1;let t=o.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(z)}return!1}function P(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function V(i){if(e.isJSXText(i)){let s=W(i.value);return s?ne(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(r))return"";let o=`<${r}`;for(let s of n.attributes){if(e.isJSXSpreadAttribute(s))continue;let a=I(s);if(a==="key"||a.startsWith("on")||a.startsWith("bind:")||a.includes("|"))continue;let p=a;if(a==="className"&&(p="class"),a==="htmlFor"&&(p="for"),!s.value)o+=` ${p}`;else if(e.isStringLiteral(s.value))o+=` ${p}="${we(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let t=i.openingElement.selfClosing;if(t&&N(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let s of i.children)if(e.isJSXText(s)){let a=W(s.value);a&&(o+=ne(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(o+="<!--$-->"):e.isJSXElement(s)&&(A(s.openingElement.name.name)?o+="<!--$-->":o+=V(s));return o+=`</${r}>`,o}function ne(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function we(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function B(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(t==="For")return Ce(i,n);if(t==="Show")return ke(i,n);if(A(t))return $e(i,n);let s=o.attributes,a=r.children,p=a.every(z),c=s.every(g=>!P(g)),f=s.every(g=>{if(e.isJSXSpreadAttribute(g))return!1;let E=I(g);return!E?.startsWith("on")&&!E?.startsWith("bind:")});if(p&&c&&f){let g=V(r);if(g){let E=ue(n,g);return n.needsTemplate=!0,e.callExpression(e.identifier(E),[])}}let d=V(r);if(!d){let g=r.loc,E=n.filename||n.file?.opts?.filename||"<unknown>",b=g?`:${g.start.line}:${g.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${E}${b}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,ie(i,n)}let l=ue(n,d);n.needsTemplate=!0;let m=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier(l),[]))])];return fe(h,m,s,n,t),pe(h,m,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(m)}function ie(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,p=[];for(let d of s){if(e.isJSXSpreadAttribute(d))continue;let l=I(d),m=w(d.value),h=v(l);p.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),m))}let c=[];for(let d of a)if(e.isJSXText(d)){let l=W(d.value);l&&c.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(d)?e.isJSXEmptyExpression(d.expression)||c.push(d.expression):e.isJSXElement(d)?c.push(B({node:d},n)):e.isJSXFragment(d)&&c.push(Z({node:d},n));let f=p.length>0?e.objectExpression(p):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),f,...c])}let _e=new Set(["input","textarea","select","option"]);function fe(i,n,r,o,t){function s(c,f){return c==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),f])):c==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),f])):c==="value"&&t&&_e.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),f])):c==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),f])):c.startsWith("data-")||c.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(c),f])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(c),f]))}let a=!1;function p(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let c of r){if(e.isJSXSpreadAttribute(c)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),c.argument])));continue}let f=I(c);if(f!=="key"){if(f==="ref"){let d=w(c.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",d),e.stringLiteral("function")),e.callExpression(e.cloneNode(d),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(d),e.identifier("current")),e.identifier(n)))));continue}if(f.startsWith("on")&&!f.includes("|")&&!k(f,o)){let d=f.slice(2).toLowerCase(),l=w(c.value);De.has(d)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(d),p(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${d}`)),l)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(d),l])));continue}if(f.startsWith("on")&&(f.includes("|")||k(f,o))){let{eventName:d,modifiers:l}=_(f),m=w(c.value),h=L(m,l),g=d.slice(2).toLowerCase(),E=l.filter(O=>Te.has(O)),b=[e.stringLiteral(g),h];if(E.length>0){let O=E.map(j=>e.objectProperty(e.identifier(j),e.booleanLiteral(!0)));b.push(e.objectExpression(O))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),b)));continue}if(C(f)){let d=F(f),l=c.value.expression;o.needsEffect=!0,d==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):d==="checked"&&(o.needsEffect=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("checked")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(c.value)){let d=c.value.expression,l=v(f);if(S(d,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let m=e.isIdentifier(d)&&(M(d.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(d.name))?e.callExpression(d,[]):d,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],s(l,m))]);$(d,o.signalNames,o.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(s(l,d)))}}}}function re(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(re);if(i.type==="JSXElement"||i.type==="JSXFragment"||i.type==="CallExpression"&&i.callee&&i.callee.type==="Identifier"&&(i.callee.name==="_$mapArray"||i.callee.name==="mapArray"))return!0;for(let n of Object.keys(i)){if(n==="loc"||n==="start"||n==="end"||n==="leadingComments"||n==="trailingComments"||n==="innerComments")continue;let r=i[n];if(r&&typeof r=="object"&&re(r))return!0}return!1}function X(i,n,r){let o=null,t=!1;if(e.isConditionalExpression(i))o=i.test,t=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!S(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(re))return i;let a=r.nextMemoId();r.needsMemo=!0;let p=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],p)]))]));let c=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(c,i.consequent,i.alternate):e.logicalExpression(i.operator,c,i.right)}function pe(i,n,r,o,t){let s=[],a=0;for(let l of r){if(e.isJSXText(l)){W(l.value)&&a++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s.push({type:"expression",child:l,childIndex:a}),a++;continue}if(e.isJSXElement(l)){let m=l.openingElement.name.name;if(A(m)||m==="For"||m==="Show")s.push({type:"component",child:l,childIndex:a}),a++;else{let h=l.openingElement.attributes.some(P)||l.openingElement.attributes.some(g=>!e.isJSXSpreadAttribute(g)&&I(g)?.startsWith("on"))||!l.children.every(z);s.push({type:"static",child:l,childIndex:a,hasAnythingDynamic:h}),a++}continue}e.isJSXFragment(l)&&s.push({type:"fragment",child:l})}let p=s.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),c=p.length>=2,f=new Map;if(c){let l=null,m=0;for(let h of p){let g=h.childIndex,E=t.nextVarId();f.set(g,E);let b;if(l===null)b=oe(n,g);else{b=e.identifier(l);for(let O=m;O<g;O++)b=e.memberExpression(b,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),b)])),l=E,m=g}}function d(l){return f.has(l)?e.identifier(f.get(l)):oe(n,l)}for(let l of s){if(l.type==="expression"){let m=l.child.expression,h=d(l.childIndex);t.needsInsert=!0;let g=H(m,t);if(g){t.needsMapArray=!0;let b=e.isCallExpression(g)&&e.isIdentifier(g.callee)&&(g.callee.name==="_$mapArray"||g.callee.name==="mapArray"),O=e.isArrowFunctionExpression(g);O&&e.isExpression(g.body)?g.body=X(g.body,i,t):!b&&!O&&(g=X(g,i,t));let j=b||O?g:e.arrowFunctionExpression([],g);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),j,h])));continue}if(e.isCallExpression(m)&&e.isIdentifier(m.callee)&&(m.callee.name==="mapArray"||m.callee.name==="_$mapArray")){t.needsMapArray=!0,m.callee.name==="mapArray"&&(m.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,h])));continue}if(S(m,t.signalNames,t.importedIdentifiers)){m=X(m,i,t);let b=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],m),h]);$(m,t.signalNames,t.importedIdentifiers)&&e.addComment(b,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(b))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,h])));continue}if(l.type==="component"){let m=B({node:l.child},t),h=d(l.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,h])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let m;f.has(l.childIndex)?m=f.get(l.childIndex):(m=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),oe(n,l.childIndex))]))),fe(i,m,l.child.openingElement.attributes,t,l.child.openingElement.name.name),pe(i,m,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let m of l.child.children)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){t.needsInsert=!0;let h=m.expression;S(h,t.signalNames,t.importedIdentifiers)?(h=X(h,i,t),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],h)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),h])))}}}}function oe(i,n){if(n===0)return e.memberExpression(e.identifier(i),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(i),e.identifier("firstChild"));for(let o=0;o<n;o++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function $e(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,p=null,c=[];for(let E of s){if(e.isJSXAttribute(E)){let b;if(e.isJSXNamespacedName(E.name)?b=`${E.name.namespace.name}:${E.name.name.name}`:b=E.name.name,b&&typeof b=="string"&&b.startsWith("client:")){let O=b.slice(7);E.value?p={type:O,value:E.value.value}:p={type:O};continue}}c.push(E)}if(p){n.needsCreateComponent=!0,n.needsIsland=!0;let E=[e.objectProperty(e.identifier("component"),e.identifier(t)),e.objectProperty(e.identifier("mode"),e.stringLiteral(p.type))];p.value&&E.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(p.value)));for(let b of c){if(e.isJSXSpreadAttribute(b))continue;let O=I(b),j=w(b.value);E.push(e.objectProperty(e.identifier(O),j))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(E),e.arrayExpression([])])}n.needsCreateComponent=!0;let f=[],d=!1,l=null;for(let E of c){if(e.isJSXSpreadAttribute(E)){d=!0,l=E.argument;continue}let b=I(E);if(b==="key")continue;if(C(b)){let j=F(b),U=E.value.expression;j==="value"?(f.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(U),[]))),f.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(U),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):j==="checked"&&(f.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(U),[]))),f.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(U),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(b.startsWith("on")&&(b.includes("|")||k(b,n))){let{eventName:j,modifiers:U}=_(b),Pe=w(E.value),Ne=L(Pe,U);f.push(e.objectProperty(e.identifier(j),Ne));continue}let O=w(E.value);f.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(b)?e.identifier(b):e.stringLiteral(b),O))}let m=[];for(let E of a)if(e.isJSXText(E)){let b=W(E.value);b&&m.push(e.stringLiteral(b))}else e.isJSXExpressionContainer(E)?e.isJSXEmptyExpression(E.expression)||m.push(E.expression):e.isJSXElement(E)?m.push(B({node:E},n)):e.isJSXFragment(E)&&m.push(Z({node:E},n));let h;d?f.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),l,e.objectExpression(f)]):h=l:f.length>0?h=e.objectExpression(f):h=e.nullLiteral();let g=m.length>0?e.arrayExpression(m):e.arrayExpression([]);return e.callExpression(e.identifier("_$createComponent"),[e.identifier(t),h,g])}function Ce(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null;for(let f of o)if(e.isJSXAttribute(f)){let d=I(f);d==="each"?s=w(f.value):d==="key"&&(a=w(f.value))}if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ie(i,n);let p=null;for(let f of t)if(e.isJSXExpressionContainer(f)&&!e.isJSXEmptyExpression(f.expression)){p=f.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ie(i,n);n.needsMapArray=!0;let c=[s,p];return a&&c.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),c)}function ke(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null;for(let h of o)if(e.isJSXAttribute(h)){let g=I(h);g==="when"?s=w(h.value):g==="fallback"&&(a=w(h.value))}if(!s)throw i.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let p=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){p=h.expression;break}if(!p){let h=[];for(let g of t)if(e.isJSXText(g)){let E=W(g.value);E&&h.push(e.stringLiteral(E))}else e.isJSXElement(g)&&h.push(B({node:g},n));h.length===1?p=h[0]:h.length>1?p=e.arrayExpression(h):p=e.nullLiteral()}let c;e.isCallExpression(s)?c=s:e.isArrowFunctionExpression(s)&&e.isExpression(s.body)?c=s.body:e.isIdentifier(s)&&(n.signalNames&&M(s.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(s.name))?c=e.callExpression(s,[]):c=s;let f=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),d=e.isFunction(p),l=d?e.callExpression(p,[e.cloneNode(f)]):p,m=a||e.nullLiteral();if(S(c,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let g=d?c:e.unaryExpression("!",e.unaryExpression("!",c));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],g)]))])),c=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(f,c)]),e.returnStatement(e.conditionalExpression(e.cloneNode(f),l,m))]))}function Ae(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=H(i,n);if(o){n.needsMapArray=!0;let s=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=X(o.body,r,n),o;if(s)return o;let p=X(o,r,n);return e.arrowFunctionExpression([],p)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):S(i,n.signalNames,n.importedIdentifiers)?(i=X(i,r,n),e.arrowFunctionExpression([],i)):i}function Z(i,n){let{node:r}=i,o=r.children,t=[];for(let s of o)if(e.isJSXText(s)){let a=W(s.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||t.push(Ae(s.expression,n)):e.isJSXElement(s)?t.push(B({node:s},n)):e.isJSXFragment(s)&&t.push(Z({node:s},n));return t.length===1?t[0]:e.arrayExpression(t)}function ue(i,n){if(i.templateMap.has(n))return i.templateMap.get(n);let r=`_tmpl$${i.templateCount++}`;return i.templateMap.set(n,r),i.templates.push({id:r,html:n}),r}function de(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let s=t.get(o);s||(s=T(i),t.set(o,s)),n.signalNames=s,n._pendingSetup=[];let a=r(i,n),p=n._pendingSetup;if(n._pendingSetup=[],p.length>0){let c=i,f=!1;for(;c&&!c.isStatement();)(c.isArrowFunctionExpression()||c.isFunctionExpression())&&(f=!0),c=c.parentPath;c&&c.isStatement()&&(c.listKey==="body"||c.listKey==="consequent")&&Array.isArray(c.container)&&!f?(c.insertBefore(p),i.replaceWith(a)):(p.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(p)),[])))}else i.replaceWith(a)}function Ie(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function Le(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function Fe(i){if(!e.isObjectExpression(i))return{property:null,value:null};for(let n of i.properties)if(!(!e.isObjectProperty(n)||(e.isIdentifier(n.key)&&!n.computed?n.key.name:e.isStringLiteral(n.key)?n.key.value:null)!=="id"))return e.isStringLiteral(n.value)?{property:n,value:n.value.value}:e.isTemplateLiteral(n.value)&&n.value.expressions.length===0?{property:n,value:n.value.quasis[0]?.value.cooked||""}:{property:n,value:null};return{property:null,value:null}}function me(i,n,r,o,t){let s=i.node.loc?.start||{line:0,column:0},a=`${t}:${s.line}:${s.column+1}`,p=`${t}#${o}`,c=n.serverActionIds.get(r);if(c)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${c.bindingName}" at ${c.source}; conflicts with "${o}" at ${a}.`);let f={id:r,key:p,bindingName:o,filename:t,source:a,loc:s};if(n.serverActionIds.set(r,f),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(f)}catch(d){throw i.buildCodeFrameError(d instanceof Error?d.message:String(d))}}function Me(i,n){if(!Le(i,n))return;let r=Ie(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let o=i.node.arguments[1],t=Fe(o);if(t.property){t.value!==null&&me(i,n,t.value,r,n.serverActionFilename);return}let s=`wa1_${Re(`${n.serverActionFilename}#${r}`)}`;me(i,n,s,r,n.serverActionFilename);let a=e.objectProperty(e.identifier("id"),e.stringLiteral(s));o?e.isObjectExpression(o)?o.properties.unshift(a):i.node.arguments[1]=e.objectExpression([a,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([a]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Xe(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let o=r.source.value,t=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/")||o.startsWith("./")||o.startsWith("../");for(let s of r.specifiers){let a=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(a=s.local.name),a&&(t||/^(use|create)[A-Z]/.test(a))&&n.importedIdentifiers.add(a),Je.has(o)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({CallExpression(r){Me(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let t=o.callee,s="";if(e.isIdentifier(t)?s=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(s=t.property.name),he.has(s)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let p of a.elements)e.isIdentifier(p)&&n.signalNames.add(p.name);else if(e.isObjectPattern(a))for(let p of a.properties)e.isObjectProperty(p)&&e.isIdentifier(p.value)&&n.signalNames.add(p.value.name)}}})},exit(i,n){for(let t of n.templates.reverse()){let s=e.callExpression(e.identifier("_$template"),[e.stringLiteral(t.html)]);e.addComment(s,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t.id),s)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let o=[];if(n.needsH&&o.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&o.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&o.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let t=null;for(let s of i.node.body)if(e.isImportDeclaration(s)&&(s.source.value==="what-framework/render"||s.source.value==="what-core/render")){t=s;break}if(t){let s=new Set(t.specifiers.filter(a=>e.isImportSpecifier(a)).map(a=>a.imported.name));for(let a of r)s.has(a.imported.name)||t.specifiers.push(a)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&We(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let t=e.arrayExpression([...n.delegatedEvents].map(a=>e.stringLiteral(a))),s=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),s])}}},JSXElement(i,n){de(i,n,B)},JSXFragment(i,n){de(i,n,Z)}}}}function We(e,u,x){let k=null;for(let _ of e.node.body)if(u.isImportDeclaration(_)&&(_.source.value==="what-core"||_.source.value==="what-framework")){k=_;break}if(k){let _=new Set(k.specifiers.filter(C=>u.isImportSpecifier(C)).map(C=>C.imported.name));for(let C of x)_.has(C.imported.name)||k.specifiers.push(C)}else{let _=u.importDeclaration(x,u.stringLiteral("what-framework"));e.unshiftContainer("body",_)}}import q from"path";import{transformSync as ze}from"@babel/core";import G from"fs";import J from"path";var ge=new Set([".jsx",".tsx",".js",".ts"]),He=new Set(["_layout","_error","_loading","_404"]);function ye(e){let u=[],x=[],k=[];function _(F,A=""){if(!G.existsSync(F))return;let N=G.readdirSync(F,{withFileTypes:!0});for(let w of N){let v=J.join(F,w.name);if(w.isDirectory()){if(w.name.match(/^\((.+)\)$/)){_(v,A);continue}if(w.name==="api"&&A===""){C(v,"/api");continue}_(v,A+"/"+Q(w.name));continue}let I=J.extname(w.name);if(!ge.has(I))continue;let L=J.basename(w.name,I);if(L==="_layout"){x.push({filePath:v,urlPrefix:A||"/"});continue}if(He.has(L))continue;let M=Q(L),T=L==="index"?A||"/":A+"/"+M;u.push({filePath:v,routePath:Ee(T),isDynamic:T.includes(":")||T.includes("*")})}}function C(F,A){if(!G.existsSync(F))return;let N=G.readdirSync(F,{withFileTypes:!0});for(let w of N){let v=J.join(F,w.name);if(w.isDirectory()){C(v,A+"/"+Q(w.name));continue}let I=J.extname(w.name);if(!ge.has(I))continue;let L=J.basename(w.name,I),M=Q(L),T=L==="index"?A:A+"/"+M;k.push({filePath:v,routePath:Ee(T)})}}return _(e),u.sort((F,A)=>{let N=xe(F.routePath),w=xe(A.routePath);return N-w}),{pages:u,layouts:x,apiRoutes:k}}function Q(e){let u=e.match(/^\[\.\.\.(\w+)\]$/);if(u)return"*"+u[1];let x=e.match(/^\[(\w+)\]$/);return x?":"+x[1]:e.toLowerCase()}function Ee(e){let u=e.replace(/\/+/g,"/");return u.length>1&&u.endsWith("/")&&(u=u.slice(0,-1)),u||"/"}function xe(e){return e.includes("*")?100:e.includes(":")?10:0}function be(e){let u=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!u)return{mode:"client"};try{let x=u[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(x)}}catch{return{mode:"client"}}}function Ve(e){return{hasLoader:/export\s+(?:async\s+)?(?:const|let|var|function)\s+loader\b/.test(e),hasGetStaticPaths:/export\s+(?:async\s+)?(?:const|let|var|function)\s+getStaticPaths\b/.test(e),hasPageConfig:/export\s+const\s+page\b/.test(e)}}function te(e,u){let{pages:x,layouts:k,apiRoutes:_}=ye(e),C=[],F=[],A=new Map;k.forEach((v,I)=>{let L=`_layout${I}`,M=se(v.filePath,u);C.push(`import ${L} from '${M}';`),A.set(v.urlPrefix,L)}),x.forEach((v,I)=>{let L=`_page${I}`,M=se(v.filePath,u);C.push(`import ${L} from '${M}';`);let T={mode:"client"},R={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let S=G.readFileSync(v.filePath,"utf-8");T=be(S),R=Ve(S)}catch{}let y=Be(v.routePath,A),$={path:v.routePath,component:L,mode:T.mode||"client",layout:y||null,hasLoader:R.hasLoader};F.push($)});let N=[];return _.forEach((v,I)=>{let L=`_api${I}`,M=se(v.filePath,u);C.push(`import * as ${L} from '${M}';`),N.push({path:v.routePath,handlers:L})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...C,"","export const routes = [",...F.map(v=>` { path: '${v.path}', component: ${v.component}, mode: '${v.mode}'${v.layout?`, layout: ${v.layout}`:""}${v.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...N.map(v=>` { path: '${v.path}', handlers: ${v.handlers} },`),"];","","export const pageModes = {",...F.map(v=>` '${v.path}': '${v.mode}',`),"};"].join(`
2
- `)}function se(e,u){return"/"+J.relative(u,e).split(J.sep).join("/")}function Be(e,u){let x=e.split("/").filter(Boolean);for(;x.length>0;){let k="/"+x.join("/");if(u.has(k))return u.get(k);x.pop()}return u.has("/")?u.get("/"):null}var Ue=`
1
+ var Be=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ue=new Set(["once","capture","passive"]),ze=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ge=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),ee=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),$e=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),qe=new Set(["For","Show","Switch","Match"]),Ze=new Set(["what-framework/server","what-server","what-server/actions"]);function Ke(e){let m=0xcbf29ce484222325n;for(let b=0;b<e.length;b++)m^=BigInt(e.charCodeAt(b)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function Ye(e,m){let b=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&b.startsWith(`${C}/`)?b.slice(C.length+1):b.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),b=-1;for(let v=0;v<m.length;v++)/[^ \t]/.test(m[v])&&(b=v);if(b===-1)return"";let C="";for(let v=0;v<m.length;v++){let _=m[v].replace(/\t/g," "),L=v===0,P=v===m.length-1;L||(_=_.replace(/^ +/,"")),P||(_=_.replace(/ +$/,"")),_&&(v!==b&&(_+=" "),C+=_)}return C}function ne({types:e}){let m=new Set,b=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function v(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(a=>Be.has(a));return{eventName:o,modifiers:t}}function _(i){return i.startsWith("bind:")}function L(i){return i.slice(5)}function P(i){return/^[A-Z]/.test(i)}function M(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&P(n.name)}function k(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function w(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function T(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function I(i){return e.isJSXMemberExpression(i)?e.memberExpression(I(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function j(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let c=0;c<r.properties.length;c++){let d=r.properties[c];if(e.isRestElement(d))return;if(e.isObjectProperty(d)&&!d.computed&&e.isIdentifier(d.key,{name:"children"})){if(o!==-1||!e.isIdentifier(d.value))return;o=c}}if(o===-1)return;let t=i.scope.getBinding(r.properties[o].value.name);if(!t||t.constantViolations.length>0||t.referencePaths.length===0||!t.referencePaths.every(c=>{let d=c.parentPath;if(!d||!d.isJSXExpressionContainer())return!1;let f=d.parentPath;if(!f||!f.isJSXElement()||!M(f.node))return!1;let l=f.node.openingElement.name;return!(e.isJSXIdentifier(l)&&qe.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let u=r.properties.filter((c,d)=>d!==o);if(u.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let c=e.objectPattern(u);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(c,e.cloneNode(s))])),i.node._whatMovedProps=c}for(let c of t.referencePaths)c.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function D(i){return ze.has(String(i).toLowerCase())}function N(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function y(i){return i==="className"?"class":i==="htmlFor"?"for":i}function S(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function O(i){return!!i&&i.length>2&&/^on/i.test(i)}function z(i,n){if(n.length===0)return i;let r=i;for(let o of n)switch(o){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function R(i,n){return n.has(i)}function Y(i){let n=new Set;function r(a){let s=a.init;if(!s||!e.isCallExpression(s))return;let u=s.callee,c="";if(e.isIdentifier(u)?c=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(c=u.property.name),$e.has(c)){let d=a.id;if(e.isIdentifier(d))n.add(d.name);else if(e.isArrayPattern(d))for(let f of d.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(d))for(let f of d.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function o(a){if(e.isObjectPattern(a))for(let s of a.properties)e.isObjectProperty(s)&&e.isIdentifier(s.value)?n.add(s.value.name):e.isRestElement(s)&&e.isIdentifier(s.argument)&&n.add(s.argument.name)}let t=i.scope;for(;t;){for(let s of Object.values(t.bindings))s.path.isVariableDeclarator()&&r(s.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let s of a.params)o(s);a._whatMovedProps&&o(a._whatMovedProps)}t=t.parent}return n}function X(i){return Y(i)}function G(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ee.has(n.object.name):e.isIdentifier(n)?ee.has(n.name):!1}function oe(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&R(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ee.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)||G(i))return!1;if(i.arguments.some(o=>F(o,n,r)))return!0}return!1}function F(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&R(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ee.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)?!0:G(i)?i.arguments.some(o=>F(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>F(o,n,r)):F(i.callee,n,r)||i.arguments.some(o=>F(o,n,r)):e.isIdentifier(i)?R(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?F(i.object,n,r):e.isConditionalExpression(i)?F(i.test,n,r)||F(i.consequent,n,r)||F(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?F(i.left,n,r)||F(i.right,n,r):e.isUnaryExpression(i)?F(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>F(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&F(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&F(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function he(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let a=Q(r.consequent,n),s=Q(r.alternate,n);if(a||s){let u=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return o?e.arrowFunctionExpression([],u):u}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=Q(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return o?e.arrowFunctionExpression([],s):s}return null}return Q(r,n)}function Q(i,n){if(!e.isCallExpression(i)||!e.isMemberExpression(i.callee)||!e.isIdentifier(i.callee.property,{name:"map"})||i.arguments.length<1)return null;let r=i.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let o=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))o=r.body;else if(e.isBlockStatement(r.body)){let l=r.body.body.find(g=>e.isReturnStatement(g));l&&(o=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(g=>e.isReturnStatement(g));l&&(o=l.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,a=null;for(let l of t)if(e.isJSXAttribute(l)&&S(l)==="key"){a=l;break}if(!a)return null;let s=N(a.value);if(!s)return null;o.openingElement.attributes=t.filter(l=>l!==a);let u=i.callee.object,c=e.arrowFunctionExpression([],u),d=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),f=e.arrowFunctionExpression([d],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[c,r,e.objectExpression([e.objectProperty(e.identifier("key"),f),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function se(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(M(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let o=r.value;if(e.isJSXExpressionContainer(o))return!1}return i.children.every(se)}return!1}function ge(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function te(i){if(e.isJSXText(i)){let a=H(i.value);return a?Ee(a):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(M(i))return"";let o=`<${r}`;for(let a of n.attributes){if(e.isJSXSpreadAttribute(a))continue;let s=S(a);if(s==="key"||O(s)||s.startsWith("bind:")||s.includes("|"))continue;let u=s;if(s==="className"&&(u="class"),s==="htmlFor"&&(u="for"),!a.value)o+=` ${u}`;else if(e.isStringLiteral(a.value))o+=` ${u}="${Pe(a.value.value)}"`;else if(e.isJSXExpressionContainer(a.value))continue}let t=i.openingElement.selfClosing;if(t&&D(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let a of i.children)if(e.isJSXText(a)){let s=H(a.value);s&&(o+=Ee(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||(o+="<!--$-->"):e.isJSXElement(a)&&(M(a)?o+="<!--$-->":o+=te(a));return o+=`</${r}>`,o}function Ee(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Pe(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function B(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!k(t,n)){if(t==="For")return Je(i,n);if(t==="Show")return Oe(i,n)}if(t==="Switch"&&(!k(t,n)||T(r)))return Xe(i,n);if(M(r))return ye(i,n);let a=o.attributes,s=r.children,u=s.every(se),c=a.every(p=>!ge(p)),d=a.every(p=>{if(e.isJSXSpreadAttribute(p))return!1;let E=S(p);return!E?.startsWith("on")&&!E?.startsWith("bind:")});if(u&&c&&d){let p=te(r);if(p){let E=we(n,p);return n.needsTemplate=!0,e.callExpression(e.identifier(E),[])}}let f=te(r);if(!f){let p=r.loc,E=n.filename||n.file?.opts?.filename||"<unknown>",x=p?`:${p.start.line}:${p.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${E}${x}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,ae(i,n)}let l=we(n,f);n.needsTemplate=!0;let g=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier(l),[]))])];return xe(h,g,a,n,t),be(h,g,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(g)}function ae(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,a=o.attributes,s=r.children,u=[];for(let f of a){if(e.isJSXSpreadAttribute(f))continue;let l=S(f),g=N(f.value),h=y(l);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),g))}let c=[];for(let f of s)if(e.isJSXText(f)){let l=H(f.value);l&&c.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(f)?e.isJSXEmptyExpression(f.expression)||c.push(f.expression):e.isJSXElement(f)?c.push(B({node:f},n)):e.isJSXFragment(f)&&c.push(q({node:f},n));let d=u.length>0?e.objectExpression(u):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),d,...c])}let Ne=new Set(["input","textarea","select","option"]);function xe(i,n,r,o,t){function a(c,d){return c==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):c==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):c==="value"&&t&&Ne.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):c==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):c.startsWith("data-")||c.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(c),d])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(c),d]))}let s=!1;function u(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let c of r){if(e.isJSXSpreadAttribute(c)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),c.argument])));continue}let d=S(c);if(d!=="key"){if(d==="ref"){let f=N(c.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",f),e.stringLiteral("function")),e.callExpression(e.cloneNode(f),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(f),e.identifier("current")),e.identifier(n)))));continue}if(d.startsWith("on")&&!d.includes("|")&&!C(d,o)){let f=d.slice(2).toLowerCase(),l=N(c.value);Ge.has(f)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(f),u(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${f}`)),l)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(f),l])));continue}if(d.startsWith("on")&&(d.includes("|")||C(d,o))){let{eventName:f,modifiers:l}=v(d),g=N(c.value),h=z(g,l),p=f.slice(2).toLowerCase(),E=l.filter(A=>Ue.has(A)),x=[e.stringLiteral(p),h];if(E.length>0){let A=E.map(J=>e.objectProperty(e.identifier(J),e.booleanLiteral(!0)));x.push(e.objectExpression(A))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),x)));continue}if(_(d)){let f=L(d),l=c.value.expression;o.needsEffect=!0,f==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):f==="checked"&&(o.needsEffect=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("checked")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(c.value)){let f=c.value.expression,l=y(d);if(F(f,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let g=e.isIdentifier(f)&&(R(f.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(f.name))?e.callExpression(f,[]):f,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(l,g))]);oe(f,o.signalNames,o.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(a(l,f)))}}}}function le(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(le);if(i.type==="JSXElement"||i.type==="JSXFragment"||i.type==="CallExpression"&&i.callee&&i.callee.type==="Identifier"&&(i.callee.name==="_$mapArray"||i.callee.name==="mapArray"))return!0;for(let n of Object.keys(i)){if(n==="loc"||n==="start"||n==="end"||n==="leadingComments"||n==="trailingComments"||n==="innerComments")continue;let r=i[n];if(r&&typeof r=="object"&&le(r))return!0}return!1}function U(i,n,r){let o=null,t=!1;if(e.isConditionalExpression(i))o=i.test,t=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!F(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(le))return i;let s=r.nextMemoId();r.needsMemo=!0;let u=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],u)]))]));let c=e.callExpression(e.identifier(s),[]);return t?e.conditionalExpression(c,i.consequent,i.alternate):e.logicalExpression(i.operator,c,i.right)}function be(i,n,r,o,t){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let g=l.openingElement.name.name;if(M(l)||g==="For"||g==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let h=l.openingElement.attributes.some(ge)||l.openingElement.attributes.some(p=>!e.isJSXSpreadAttribute(p)&&S(p)?.startsWith("on"))||!l.children.every(se);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:h}),s++}continue}e.isJSXFragment(l)&&a.push({type:"fragment",child:l})}let u=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),c=u.length>=2,d=new Map;if(c){let l=null,g=0;for(let h of u){let p=h.childIndex,E=t.nextVarId();d.set(p,E);let x;if(l===null)x=ce(n,p);else{x=e.identifier(l);for(let A=g;A<p;A++)x=e.memberExpression(x,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),x)])),l=E,g=p}}function f(l){return d.has(l)?e.identifier(d.get(l)):ce(n,l)}for(let l of a){if(l.type==="expression"){let g=l.child.expression,h=f(l.childIndex);t.needsInsert=!0;let p=he(g,t);if(p){t.needsMapArray=!0;let x=e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="_$mapArray"||p.callee.name==="mapArray"),A=e.isArrowFunctionExpression(p);A&&e.isExpression(p.body)?p.body=U(p.body,i,t):!x&&!A&&(p=U(p,i,t));let J=x||A?p:e.arrowFunctionExpression([],p);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),J,h])));continue}if(e.isCallExpression(g)&&e.isIdentifier(g.callee)&&(g.callee.name==="mapArray"||g.callee.name==="_$mapArray")){t.needsMapArray=!0,g.callee.name==="mapArray"&&(g.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(F(g,t.signalNames,t.importedIdentifiers)){g=U(g,i,t);let x=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],g),h]);oe(g,t.signalNames,t.importedIdentifiers)&&e.addComment(x,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(x))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(l.type==="component"){let g=B({node:l.child},t),h=f(l.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let g;d.has(l.childIndex)?g=d.get(l.childIndex):(g=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),ce(n,l.childIndex))]))),xe(i,g,l.child.openingElement.attributes,t,l.child.openingElement.name.name),be(i,g,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let g of l.child.children)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){t.needsInsert=!0;let h=g.expression;F(h,t.signalNames,t.importedIdentifiers)?(h=U(h,i,t),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],h)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),h])))}}}}function ce(i,n){if(n===0)return e.memberExpression(e.identifier(i),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(i),e.identifier("firstChild"));for(let o=0;o<n;o++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function ye(i,n){let{node:r}=i,o=r.openingElement,t=I(o.name),a=o.attributes,s=r.children,u=null,c=[];for(let E of a){if(e.isJSXAttribute(E)){let x;if(e.isJSXNamespacedName(E.name)?x=`${E.name.namespace.name}:${E.name.name.name}`:x=E.name.name,x&&typeof x=="string"&&x.startsWith("client:")){let A=x.slice(7);E.value?u={type:A,value:E.value.value}:u={type:A};continue}}c.push(E)}function d(){let E=n._pendingSetup?n._pendingSetup.length:0,x=[],A=!1;for(let $ of s)if(e.isJSXText($)){let W=H($.value);W&&x.push(e.stringLiteral(W))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(A=!0,x.push($.expression));else if(e.isJSXElement($)){let W=$.openingElement.name.name;W!=="For"&&W!=="Show"&&W!=="Switch"&&(A=!0),x.push(B({node:$},n))}else e.isJSXFragment($)&&(A=!0,x.push(q({node:$},n)));let J=e.arrayExpression(x);if(A){let $=n._pendingSetup?n._pendingSetup.splice(E):[];J=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(J)]):J)}return J}if(u){n.needsCreateComponent=!0,n.needsIsland=!0;let E=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(u.type))];u.value&&E.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(u.value)));let x=null;for(let J of c){if(e.isJSXSpreadAttribute(J)){x=J.argument;continue}let $=S(J);if($==="key")continue;let W=N(J.value);E.push(e.objectProperty(e.identifier($),W))}let A=x?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),x,e.objectExpression(E)]):e.objectExpression(E);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),A,d()])}n.needsCreateComponent=!0;let f=[],l=!1,g=null;for(let E of c){if(e.isJSXSpreadAttribute(E)){l=!0,g=E.argument;continue}let x=S(E);if(x==="key")continue;if(_(x)){let J=L(x),$=E.value.expression;J==="value"?(f.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),f.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):J==="checked"&&(f.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),f.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(x.startsWith("on")&&(x.includes("|")||C(x,n))){let{eventName:J,modifiers:$}=v(x),W=N(E.value),Ve=z(W,$);f.push(e.objectProperty(e.identifier(J),Ve));continue}let A=N(E.value);f.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(x)?e.identifier(x):e.stringLiteral(x),A))}let h;l?f.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),g,e.objectExpression(f)]):h=g:f.length>0?h=e.objectExpression(f):h=e.nullLiteral();let p=d();return e.callExpression(e.identifier("_$createComponent"),[t,h,p])}function Je(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,a=null,s=null;for(let d of o)if(e.isJSXAttribute(d)){let f=S(d);f==="each"?a=N(d.value):f==="key"&&(s=N(d.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ae(i,n);let u=null;for(let d of t)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){u=d.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ae(i,n);n.needsMapArray=!0;let c=[a,u];return s&&c.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),c)}function Oe(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,a=null,s=null;for(let h of o)if(e.isJSXAttribute(h)){let p=S(h);p==="when"?a=N(h.value):p==="fallback"&&(s=N(h.value))}if(!a)throw i.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let u=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){u=h.expression;break}if(!u){let h=[];for(let p of t)if(e.isJSXText(p)){let E=H(p.value);E&&h.push(e.stringLiteral(E))}else e.isJSXElement(p)&&h.push(B({node:p},n));h.length===1?u=h[0]:h.length>1?u=e.arrayExpression(h):u=e.nullLiteral()}let c=Se(a,n),d=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),f=e.isFunction(u),l=f?e.callExpression(u,[e.cloneNode(d)]):u,g=s||e.nullLiteral();if(F(c,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let p=f?c:e.unaryExpression("!",e.unaryExpression("!",c));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],p)]))])),c=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(d,c)]),e.returnStatement(e.conditionalExpression(e.cloneNode(d),l,g))]))}function Se(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&R(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Te(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let t=H(o.value);t&&r.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(B({node:o},n)):e.isJSXFragment(o)&&r.push(q({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Xe(i,n){let{node:r}=i,o=k(r.openingElement.name.name,n),t=p=>e.isJSXElement(p)&&e.isJSXIdentifier(p.openingElement.name,{name:"Match"})&&(o||!k("Match",n));if(!r.children.some(t)&&!w(r.openingElement.name.name,n))return ye(i,n);let a=p=>{let E=`<Switch> ${p}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`;throw i.buildCodeFrameError?i.buildCodeFrameError(E):new Error(`[what-compiler] ${E}`)},s=null;for(let p of r.openingElement.attributes)e.isJSXSpreadAttribute(p)&&a("cannot take a spread attribute"),S(p)==="fallback"&&(s=N(p.value));let u=[];for(let p of r.children){if(e.isJSXText(p)){H(p.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(p)){if(e.isJSXEmptyExpression(p.expression))continue;a("cannot read its arms from an expression child")}t(p)||a("cannot mix other elements with its <Match> arms"),u.push(p)}u.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let c=[];for(let p of u){let E=null;for(let $ of p.openingElement.attributes)e.isJSXAttribute($)&&S($)==="when"&&(E=N($.value));E||a('has a <Match> with no "when" prop');let x=n._pendingSetup.length,A=Te(p.children,n),J=n._pendingSetup.splice(x);J.length>0&&(A=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...J,e.returnStatement(A)])),[])),c.push([Se(E,n),A])}let d=c.some(([p])=>F(p,n.signalNames,n.importedIdentifiers)),f=s||e.nullLiteral();if(!d){let p=f;for(let E=c.length-1;E>=0;E--)p=e.conditionalExpression(c[E][0],c[E][1],p);return e.arrowFunctionExpression([],p)}let l=e.numericLiteral(-1);for(let p=c.length-1;p>=0;p--)l=e.conditionalExpression(c[p][0],e.numericLiteral(p),l);let g=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let h=f;for(let p=c.length-1;p>=0;p--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(g),[]),e.numericLiteral(p)),c[p][1],h);return e.arrowFunctionExpression([],h)}function je(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=he(i,n);if(o){n.needsMapArray=!0;let a=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=U(o.body,r,n),o;if(a)return o;let u=U(o,r,n);return e.arrowFunctionExpression([],u)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):F(i,n.signalNames,n.importedIdentifiers)?(i=U(i,r,n),e.arrowFunctionExpression([],i)):i}function q(i,n){let{node:r}=i,o=r.children,t=[];for(let a of o)if(e.isJSXText(a)){let s=H(a.value);s&&t.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||t.push(je(a.expression,n)):e.isJSXElement(a)?t.push(B({node:a},n)):e.isJSXFragment(a)&&t.push(q({node:a},n));return t.length===1?t[0]:e.arrayExpression(t)}function we(i,n){if(i.templateMap.has(n))return i.templateMap.get(n);let r=`_tmpl$${i.templateCount++}`;return i.templateMap.set(n,r),i.templates.push({id:r,html:n}),r}function ve(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let a=t.get(o);a||(a=Y(i),t.set(o,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),u=n._pendingSetup;if(n._pendingSetup=[],u.length>0){let c=i,d=!1;for(;c&&!c.isStatement();)(c.isArrowFunctionExpression()||c.isFunctionExpression())&&(d=!0),c=c.parentPath;c&&c.isStatement()&&(c.listKey==="body"||c.listKey==="consequent")&&Array.isArray(c.container)&&!d?(c.insertBefore(u),i.replaceWith(s)):(u.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(u)),[])))}else i.replaceWith(s)}function De(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function Re(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function We(i){if(!e.isObjectExpression(i))return{property:null,value:null};for(let n of i.properties)if(!(!e.isObjectProperty(n)||(e.isIdentifier(n.key)&&!n.computed?n.key.name:e.isStringLiteral(n.key)?n.key.value:null)!=="id"))return e.isStringLiteral(n.value)?{property:n,value:n.value.value}:e.isTemplateLiteral(n.value)&&n.value.expressions.length===0?{property:n,value:n.value.quasis[0]?.value.cooked||""}:{property:n,value:null};return{property:null,value:null}}function _e(i,n,r,o,t){let a=i.node.loc?.start||{line:0,column:0},s=`${t}:${a.line}:${a.column+1}`,u=`${t}#${o}`,c=n.serverActionIds.get(r);if(c)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${c.bindingName}" at ${c.source}; conflicts with "${o}" at ${s}.`);let d={id:r,key:u,bindingName:o,filename:t,source:s,loc:a};if(n.serverActionIds.set(r,d),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(d)}catch(f){throw i.buildCodeFrameError(f instanceof Error?f.message:String(f))}}function He(i,n){if(!Re(i,n))return;let r=De(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let o=i.node.arguments[1],t=We(o);if(t.property){t.value!==null&&_e(i,n,t.value,r,n.serverActionFilename);return}let a=`wa1_${Ke(`${n.serverActionFilename}#${r}`)}`;_e(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));o?e.isObjectExpression(o)?o.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Ye(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set,n.whatImports=new Set,n.foreignImports=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let o=r.source.value,t=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/"),a=t||o.startsWith("./")||o.startsWith("../");for(let s of r.specifiers){let u=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(u=s.local.name),u&&((a||/^(use|create)[A-Z]/.test(u))&&n.importedIdentifiers.add(u),t?n.whatImports.add(u):o.startsWith(".")||n.foreignImports.add(u)),Ze.has(o)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){j(r)},CallExpression(r){He(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let t=o.callee,a="";if(e.isIdentifier(t)?a=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(a=t.property.name),$e.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let u of s.elements)e.isIdentifier(u)&&n.signalNames.add(u.name);else if(e.isObjectPattern(s))for(let u of s.properties)e.isObjectProperty(u)&&e.isIdentifier(u.value)&&n.signalNames.add(u.value.name)}}})},exit(i,n){for(let t of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(t.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let o=[];if(n.needsH&&o.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&o.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&o.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let t=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){t=a;break}if(t){let a=new Set(t.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||t.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Qe(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let t=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){ve(i,n,B)},JSXFragment(i,n){ve(i,n,q)}}}}function Qe(e,m,b){let C=null;for(let v of e.node.body)if(m.isImportDeclaration(v)&&(v.source.value==="what-core"||v.source.value==="what-framework")){C=v;break}if(C){let v=new Set(C.specifiers.filter(_=>m.isImportSpecifier(_)).map(_=>_.imported.name));for(let _ of b)v.has(_.imported.name)||C.specifiers.push(_)}else{let v=m.importDeclaration(b,m.stringLiteral("what-framework"));e.unshiftContainer("body",v)}}import K from"path";import{transformSync as sn}from"@babel/core";import Z from"fs";import V from"path";var Ce=new Set([".jsx",".tsx",".js",".ts"]),en=new Set(["_layout","_error","_loading","_404"]);function Ie(e){let m=[],b=[],C=[];function v(L,P=""){if(!Z.existsSync(L))return;let M=Z.readdirSync(L,{withFileTypes:!0});for(let k of M){let w=V.join(L,k.name);if(k.isDirectory()){if(k.name.match(/^\((.+)\)$/)){v(w,P);continue}if(k.name==="api"&&P===""){_(w,"/api");continue}v(w,P+"/"+ie(k.name));continue}let T=V.extname(k.name);if(!Ce.has(T))continue;let I=V.basename(k.name,T);if(I==="_layout"){b.push({filePath:w,urlPrefix:P||"/"});continue}if(en.has(I))continue;let j=ie(I),D=I==="index"?P||"/":P+"/"+j;m.push({filePath:w,routePath:ke(D),isDynamic:D.includes(":")||D.includes("*")})}}function _(L,P){if(!Z.existsSync(L))return;let M=Z.readdirSync(L,{withFileTypes:!0});for(let k of M){let w=V.join(L,k.name);if(k.isDirectory()){_(w,P+"/"+ie(k.name));continue}let T=V.extname(k.name);if(!Ce.has(T))continue;let I=V.basename(k.name,T),j=ie(I),D=I==="index"?P:P+"/"+j;C.push({filePath:w,routePath:ke(D)})}}return v(e),m.sort((L,P)=>{let M=Ae(L.routePath),k=Ae(P.routePath);return M-k}),{pages:m,layouts:b,apiRoutes:C}}function ie(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let b=e.match(/^\[(\w+)\]$/);return b?":"+b[1]:e.toLowerCase()}function ke(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Ae(e){return e.includes("*")?100:e.includes(":")?10:0}function Me(e){let m=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!m)return{mode:"client"};try{let b=m[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(b)}}catch{return{mode:"client"}}}function nn(e){return{hasLoader:/export\s+(?:async\s+)?(?:const|let|var|function)\s+loader\b/.test(e),hasGetStaticPaths:/export\s+(?:async\s+)?(?:const|let|var|function)\s+getStaticPaths\b/.test(e),hasPageConfig:/export\s+const\s+page\b/.test(e)}}function pe(e,m){let{pages:b,layouts:C,apiRoutes:v}=Ie(e),_=[],L=[],P=new Map;C.forEach((w,T)=>{let I=`_layout${T}`,j=fe(w.filePath,m);_.push(`import ${I} from '${j}';`),P.set(w.urlPrefix,I)}),b.forEach((w,T)=>{let I=`_page${T}`,j=fe(w.filePath,m);_.push(`import ${I} from '${j}';`);let D={mode:"client"},N={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let O=Z.readFileSync(w.filePath,"utf-8");D=Me(O),N=nn(O)}catch{}let y=rn(w.routePath,P),S={path:w.routePath,component:I,mode:D.mode||"client",layout:y||null,hasLoader:N.hasLoader};L.push(S)});let M=[];return v.forEach((w,T)=>{let I=`_api${T}`,j=fe(w.filePath,m);_.push(`import * as ${I} from '${j}';`),M.push({path:w.routePath,handlers:I})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",..._,"","export const routes = [",...L.map(w=>` { path: '${w.path}', component: ${w.component}, mode: '${w.mode}'${w.layout?`, layout: ${w.layout}`:""}${w.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...M.map(w=>` { path: '${w.path}', handlers: ${w.handlers} },`),"];","","export const pageModes = {",...L.map(w=>` '${w.path}': '${w.mode}',`),"};"].join(`
2
+ `)}function fe(e,m){return"/"+V.relative(m,e).split(V.sep).join("/")}function rn(e,m){let b=e.split("/").filter(Boolean);for(;b.length>0;){let C="/"+b.join("/");if(m.has(C))return m.get(C);b.pop()}return m.has("/")?m.get("/"):null}var on=`
3
3
  :host {
4
4
  position: fixed;
5
5
  inset: 0;
@@ -185,12 +185,12 @@ var Oe=new Set(["preventDefault","stopPropagation","once","capture","passive","s
185
185
  white-space: pre-wrap;
186
186
  line-height: 1.5;
187
187
  }
188
- `,ln=`
188
+ `,bn=`
189
189
  class WhatErrorOverlay extends HTMLElement {
190
190
  constructor(err) {
191
191
  super();
192
192
  this.root = this.attachShadow({ mode: 'open' });
193
- this.root.innerHTML = '<style>${Ue}</style>';
193
+ this.root.innerHTML = '<style>${on}</style>';
194
194
  this._err = err;
195
195
  this.show(err);
196
196
  }
@@ -380,7 +380,7 @@ class WhatErrorOverlay extends HTMLElement {
380
380
  if (!customElements.get('what-error-overlay')) {
381
381
  customElements.define('what-error-overlay', WhatErrorOverlay);
382
382
  }
383
- `;function Se(e){let u=e.ws.send.bind(e.ws);e.ws.send=function(x){return x?.type==="error"&&x.err?.plugin==="vite-plugin-what"&&(x.err._isCompilerError=!0),u(x)}}var ve="virtual:what-routes",ee="\0"+ve,Ge=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,qe=/\.[cm]?[jt]sx?$/;function le(e,u){return e?Array.isArray(e)?e.some(x=>le(x,u)):e instanceof RegExp?(e.lastIndex=0,e.test(u)):typeof e=="function"?e(u):!1:!1}function Ze({rolldownVersion:e,viteVersion:u}={}){let x=parseInt(String(u??""),10);return!!e||Number.isFinite(x)&&x>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var ae=null;function Ke(){return ae||(ae=import("vite").then(e=>e.version||"").catch(()=>"")),ae}var Ye=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,Qe=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function ce(e={}){let{include:u=/\.[jt]sx$/,exclude:x=/node_modules/,sourceMaps:k=!0,production:_=!0,pages:C="src/pages",hot:F=!_,prodBundles:A=!0}=e,N="",w="",v=null,I=!1,L=new Map;function M(y){let $=L.get(y.id);if($&&$.key!==y.key)throw new Error(`Duplicate server action ID "${y.id}". First declared by "${$.bindingName}" at ${$.source}; conflicts with "${y.bindingName}" at ${y.source}.`);L.set(y.id,y)}function T(y){for(let[$,S]of L)S.filename===y&&L.delete($)}function R(y){let $=y.replace(/[?#].*$/,"");return N?q.relative(N,$).split(q.sep).join("/"):$}return{name:"vite-plugin-what",configResolved(y){N=y.root,w=q.resolve(N,C),I=y.command==="serve"},configureServer(y){v=y,Se(y),y.watcher.on("add",$=>{if($.startsWith(w)){let S=y.moduleGraph.getModuleById(ee);S&&(y.moduleGraph.invalidateModule(S),y.ws.send({type:"full-reload"}))}}),y.watcher.on("unlink",$=>{if(T(R($)),$.startsWith(w)){let S=y.moduleGraph.getModuleById(ee);S&&(y.moduleGraph.invalidateModule(S),y.ws.send({type:"full-reload"}))}})},resolveId(y){if(y===ve)return ee},load(y){if(y===ee)return te(w,N)},transform(y,$){let S=$.replace(/[?#].*$/,""),H=le(u,S),D=qe.test(S),z=D&&Ge.test(y);if(x&&le(x,S)||(D&&T(R(S)),!H&&!z))return null;try{let P=ze(y,{filename:$,sourceMaps:k,configFile:!1,babelrc:!1,plugins:[[Y,{production:_,projectRoot:N||process.cwd(),onActionId:M}]],parserOpts:{plugins:["jsx","typescript"]}});if(!P||!P.code)return null;let V=P.code;return F&&I&&!_&&en(y,$)&&(V+=rn($)),{code:V,map:P.map}}catch(P){throw P.plugin="vite-plugin-what",P.id||(P.id=$),P.loc===void 0&&P._loc&&(P.loc={file:$,line:P._loc.line,column:P._loc.column}),console.error(`[what] Error transforming ${$}:`,P.message),P}},handleHotUpdate({file:y,server:$,modules:S}){if(F&&u.test(y)&&!(x&&x.test(y))&&nn(y))return $.ws.send({type:"full-reload"}),[]},async config(y,{mode:$,command:S}){let H=S==="build"&&$==="production"&&A,D=Ze({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Ke()});return{...H?{resolve:{conditions:["production"]}}:{},...D,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function en(e,u){return!!(Ye.test(e)||u.includes("/pages/")||u.includes("\\pages\\"))}function nn(e){let u=q.basename(e,q.extname(e));return Qe.test(u)}function rn(e){return`
383
+ `;function Fe(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(b){return b?.type==="error"&&b.err?.plugin==="vite-plugin-what"&&(b.err._isCompilerError=!0),m(b)}}var Le="virtual:what-routes",re="\0"+Le,tn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,an=/\.[cm]?[jt]sx?$/;function de(e,m){return e?Array.isArray(e)?e.some(b=>de(b,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function ln({rolldownVersion:e,viteVersion:m}={}){let b=parseInt(String(m??""),10);return!!e||Number.isFinite(b)&&b>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var ue=null;function cn(){return ue||(ue=import("vite").then(e=>e.version||"").catch(()=>"")),ue}var fn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,pn=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function me(e={}){let{include:m=/\.[jt]sx$/,exclude:b=/node_modules/,sourceMaps:C=!0,production:v=!0,pages:_="src/pages",hot:L=!v,prodBundles:P=!0}=e,M="",k="",w=null,T=!1,I=new Map;function j(y){let S=I.get(y.id);if(S&&S.key!==y.key)throw new Error(`Duplicate server action ID "${y.id}". First declared by "${S.bindingName}" at ${S.source}; conflicts with "${y.bindingName}" at ${y.source}.`);I.set(y.id,y)}function D(y){for(let[S,O]of I)O.filename===y&&I.delete(S)}function N(y){let S=y.replace(/[?#].*$/,"");return M?K.relative(M,S).split(K.sep).join("/"):S}return{name:"vite-plugin-what",configResolved(y){M=y.root,k=K.resolve(M,_),T=y.command==="serve"},configureServer(y){w=y,Fe(y),y.watcher.on("add",S=>{if(S.startsWith(k)){let O=y.moduleGraph.getModuleById(re);O&&(y.moduleGraph.invalidateModule(O),y.ws.send({type:"full-reload"}))}}),y.watcher.on("unlink",S=>{if(D(N(S)),S.startsWith(k)){let O=y.moduleGraph.getModuleById(re);O&&(y.moduleGraph.invalidateModule(O),y.ws.send({type:"full-reload"}))}})},resolveId(y){if(y===Le)return re},load(y){if(y===re)return pe(k,M)},transform(y,S){let O=S.replace(/[?#].*$/,""),z=de(m,O),R=an.test(O),Y=R&&tn.test(y);if(b&&de(b,O)||(R&&D(N(O)),!z&&!Y))return null;try{let X=sn(y,{filename:S,sourceMaps:C,configFile:!1,babelrc:!1,plugins:[[ne,{production:v,projectRoot:M||process.cwd(),onActionId:j}]],parserOpts:{plugins:["jsx","typescript"]}});if(!X||!X.code)return null;let G=X.code;return L&&T&&!v&&un(y,S)&&(G+=mn(S)),{code:G,map:X.map}}catch(X){throw X.plugin="vite-plugin-what",X.id||(X.id=S),X.loc===void 0&&X._loc&&(X.loc={file:S,line:X._loc.line,column:X._loc.column}),console.error(`[what] Error transforming ${S}:`,X.message),X}},handleHotUpdate({file:y,server:S,modules:O}){if(L&&m.test(y)&&!(b&&b.test(y))&&dn(y))return S.ws.send({type:"full-reload"}),[]},async config(y,{mode:S,command:O}){let z=O==="build"&&S==="production"&&P,R=ln({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await cn()});return{...z?{resolve:{conditions:["production"]}}:{},...R,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function un(e,m){return!!(fn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function dn(e){let m=K.basename(e,K.extname(e));return pn.test(m)}function mn(e){return`
384
384
 
385
385
  // --- What Framework HMR Boundary ---
386
386
  if (import.meta.hot) {
@@ -393,4 +393,4 @@ if (import.meta.hot) {
393
393
  }
394
394
  });
395
395
  }
396
- `}import{h as yn,Fragment as bn,mount as Sn,Island as vn}from"what-core";export{bn as Fragment,vn as Island,Y as babelPlugin,be as extractPageConfig,te as generateRoutesModule,yn as h,Sn as mount,ye as scanPages,ce as vitePlugin,ce as what};
396
+ `}import{h as Mn,Fragment as Fn,mount as Ln,Island as Pn}from"what-core";export{Fn as Fragment,Pn as Island,ne as babelPlugin,Me as extractPageConfig,pe as generateRoutesModule,Mn as h,Ln as mount,Ie as scanPages,me as vitePlugin,me as what};