what-compiler 0.12.4 → 0.13.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 Je=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Me=new Set(["once","capture","passive"]),Ne=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Xe=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"]),pe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),De=new Set(["For","Show","Switch","Match"]),je=new Set(["what-framework/server","what-server","what-server/actions"]);function Le(e){let _=0xcbf29ce484222325n;for(let I=0;I<e.length;I++)_^=BigInt(e.charCodeAt(I)),_=BigInt.asUintN(64,_*0x100000001b3n);return _.toString(36)}function Pe(e,_){let I=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(_||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&I.startsWith(`${C}/`)?I.slice(C.length+1):I.replace(/^\.\//,"")}function J(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let _=e.split(/\r\n|\n|\r/),I=-1;for(let y=0;y<_.length;y++)/[^ \t]/.test(_[y])&&(I=y);if(I===-1)return"";let C="";for(let y=0;y<_.length;y++){let A=_[y].replace(/\t/g," "),P=y===0,W=y===_.length-1;P||(A=A.replace(/^ +/,"")),W||(A=A.replace(/ +$/,"")),A&&(y!==I&&(A+=" "),C+=A)}return C}function Oe({types:e}){let _=new Set,I=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(s=>s!=="").length===0)}function y(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],s=r.slice(1).filter(t=>Je.has(t));return{eventName:o,modifiers:s}}function A(i){return i.startsWith("bind:")}function P(i){return i.slice(5)}function W(i){return/^[A-Z]/.test(i)}function z(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let s=o?.loc?.start,t=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${t}:${s.line}:${s.column+1}`:t})`)}function j(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&W(n.name)}function O(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function ue(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function de(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function q(i){return e.isJSXMemberExpression(i)?e.memberExpression(q(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function me(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let m=r.properties[p];if(e.isRestElement(m))return;if(e.isObjectProperty(m)&&!m.computed&&e.isIdentifier(m.key,{name:"children"})){if(o!==-1||!e.isIdentifier(m.value))return;o=p}}if(o===-1)return;let s=i.scope.getBinding(r.properties[o].value.name);if(!s||s.constantViolations.length>0||s.referencePaths.length===0||!s.referencePaths.every(p=>{let m=p.parentPath;if(!m||!m.isJSXExpressionContainer())return!1;let u=m.parentPath;if(!u||!u.isJSXElement()||!j(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&De.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,m)=>m!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of s.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function Ee(i){return Ne.has(String(i).toLowerCase())}function k(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function K(i){return i==="className"?"class":i==="htmlFor"?"for":i}function $(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 he(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 N(i,n){return n.has(i)}function Q(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,m="";if(e.isIdentifier(p)?m=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(m=p.property.name),pe.has(m)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function s(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let t=i.scope;for(;t;){for(let c of Object.values(t.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let c of a.params)s(c);a._whatMovedProps&&s(a._whatMovedProps)}t=t.parent}return n}function Te(i){return Q(i)}function Y(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 ee(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&N(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)&&N(i.callee.object.name,n)||Y(i))return!1;if(i.arguments.some(o=>w(o,n,r)))return!0}return!1}function w(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&N(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)&&N(i.callee.object.name,n)?!0:Y(i)?i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>w(o,n,r)):w(i.callee,n,r)||i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i)?N(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?w(i.object,n,r):e.isConditionalExpression(i)?w(i.test,n,r)||w(i.consequent,n,r)||w(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?w(i.left,n,r)||w(i.right,n,r):e.isUnaryExpression(i)?w(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>w(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&w(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&w(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function M(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":M(i.left,n);break;case"RestElement":M(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)M(r,n);break;case"ObjectPattern":for(let r of i.properties)M(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function ge(i){let n=new Set;for(let o=1;o<i.params.length;o++)M(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let s of o.declarations)M(s.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":M(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let s of Object.keys(o)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments")continue;let t=o[s];t&&typeof t=="object"&&r(t)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of M(i.params[0],new Set))n.delete(o);return n}function xe(i,n){if(n.size===0)return null;let r=null,o=s=>{if(!(r||!s||typeof s!="object")){if(Array.isArray(s)){s.forEach(o);return}if(s.type==="Identifier"){n.has(s.name)&&(r=s.name);return}for(let t of Object.keys(s)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments"||s.type==="MemberExpression"&&t==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&t==="key"&&!s.computed)continue;let a=s[t];a&&typeof a=="object"&&o(a)}}};return o(i),r}function ne(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let t=R(r.consequent,n),a=R(r.alternate,n);if(t||a){let c=e.conditionalExpression(r.test,t||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let t=R(r.right,n);if(t){let a=e.logicalExpression(r.operator,r.left,t);return o?e.arrowFunctionExpression([],a):a}return null}return R(r,n)}function R(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 d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}}else if(e.isFunctionExpression(r)){let d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,t=null;for(let d of s)if(e.isJSXAttribute(d)&&$(d)==="key"){t=d;break}if(!t)return null;let a=k(t.value);if(!a)return null;let c=ge(r);if(xe(a,c)){let d=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=s.filter(d=>d!==t);let m=i.callee.object,u=e.arrowFunctionExpression([],m),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),E=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),E),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function V(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(j(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(V)}return!1}function ie(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function B(i){if(e.isJSXText(i)){let t=J(i.value);return t?re(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(j(i))return"";let o=`<${r}`;for(let t of n.attributes){if(e.isJSXSpreadAttribute(t))continue;let a=$(t);if(a==="key"||he(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!t.value)o+=` ${c}`;else if(e.isStringLiteral(t.value))o+=` ${c}="${be(t.value.value)}"`;else if(e.isJSXExpressionContainer(t.value))continue}let s=i.openingElement.selfClosing;if(s&&Ee(r))return o+=">",o;if(s)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let a=J(t.value);a&&(o+=re(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)&&(j(t)?o+="<!--$-->":o+=B(t));return o+=`</${r}>`,o}function re(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function be(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name;if(!O(s,n)){if(s==="For")return ve(i,n);if(s==="Show")return we(i,n)}if(s==="Switch"&&(!O(s,n)||de(r)))return Ae(i,n);if(j(r))return te(i,n);let t=o.attributes,a=r.children,c=a.every(V),p=t.every(l=>!ie(l)),m=t.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let h=$(l);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(c&&p&&m){let l=B(r);if(l){let h=le(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let u=B(r);if(!u){let l=r.loc,h=n.filename||n.file?.opts?.filename||"<unknown>",g=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${h}${g}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,G(i,n)}let f=le(n,u);n.needsTemplate=!0;let E=n.nextVarId(),d=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier(f),[]))])];return oe(d,E,t,n,s),se(d,E,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...d),e.identifier(E)}function G(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,t=o.attributes,a=r.children,c=[];for(let u of t){if(e.isJSXSpreadAttribute(u))continue;let f=$(u),E=k(u.value),d=K(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(d)?e.identifier(d):e.stringLiteral(d),E))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=J(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(X({node:u},n)):e.isJSXFragment(u)&&p.push(L({node:u},n));let m=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),m,...p])}let Se=new Set(["input","textarea","select","option"]);function oe(i,n,r,o,s){function t(p,m){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),m])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),m])):p==="value"&&s&&Se.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),m])):p==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),m])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),m])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),m]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let m=$(p);if(m!=="key"){if(m==="ref"){let u=k(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(m.startsWith("on")&&!m.includes("|")&&!C(m,o)){let u=m.slice(2).toLowerCase(),f=k(p.value);Xe.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(m.startsWith("on")&&(m.includes("|")||C(m,o))){let{eventName:u,modifiers:f}=y(m),E=k(p.value),d=Z(E,f),l=u.slice(2).toLowerCase(),h=f.filter(x=>Me.has(x)),g=[e.stringLiteral(l),d];if(h.length>0){let x=h.map(S=>e.objectProperty(e.identifier(S),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(m)){let u=P(m),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=K(m);if(w(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let E=o.signalNames&&o.signalNames.fromDestructuredProps,d=e.isIdentifier(u)&&!(E&&E.has(u.name))&&(N(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],t(f,d))]);ee(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(t(f,u)))}}}}function H(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(H);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"&&H(r))return!0}return!1}function ye(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function D(i,n,r){let o=null,s=!1;if(e.isConditionalExpression(i))o=i.test,s=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!w(o,r.signalNames,r.importedIdentifiers)||!(s?[i.consequent,i.alternate]:[i.right]).some(H))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return s?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function se(i,n,r,o,s){let t=[],a=0;for(let f of r){if(e.isJSXText(f)){J(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;t.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let E=f.openingElement.name.name;if(j(f)||E==="For"||E==="Show")t.push({type:"component",child:f,childIndex:a}),a++;else{let d=f.openingElement.attributes.some(ie)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&$(l)?.startsWith("on"))||!f.children.every(V);t.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:d}),a++}continue}e.isJSXFragment(f)&&t.push({type:"fragment",child:f})}let c=t.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,m=new Map;if(p){let f=null,E=0;for(let d of c){let l=d.childIndex,h=s.nextVarId();m.set(l,h);let g;if(f===null)g=U(n,l);else{g=e.identifier(f);for(let x=E;x<l;x++)g=e.memberExpression(g,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),g)])),f=h,E=l}}function u(f){return m.has(f)?e.identifier(m.get(f)):U(n,f)}for(let f of t){if(f.type==="expression"){let E=f.child.expression,d=u(f.childIndex);s.needsInsert=!0;let l=ne(E,s);if(l){s.needsMapArray=!0;let g=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),x=e.isArrowFunctionExpression(l);x&&e.isExpression(l.body)?l.body=D(l.body,i,s):!g&&!x&&(l=D(l,i,s));let S=g||x?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),S,d])));continue}if(e.isCallExpression(E)&&e.isIdentifier(E.callee)&&(E.callee.name==="mapArray"||E.callee.name==="_$mapArray")){s.needsMapArray=!0,E.callee.name==="mapArray"&&(E.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(w(E,s.signalNames,s.importedIdentifiers)){E=D(E,i,s);let g=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],E),d]);ee(E,s.signalNames,s.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,d])));continue}if(f.type==="component"){let E=X({node:f.child},s),d=u(f.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let E;m.has(f.childIndex)?E=m.get(f.childIndex):(E=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),U(n,f.childIndex))]))),oe(i,E,f.child.openingElement.attributes,s,f.child.openingElement.name.name),se(i,E,f.child.children,f.child,s);continue}if(f.type==="fragment"){for(let E of f.child.children)if(e.isJSXExpressionContainer(E)&&!e.isJSXEmptyExpression(E.expression)){s.needsInsert=!0;let d=E.expression;w(d,s.signalNames,s.importedIdentifiers)?(d=D(d,i,s),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],d)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),d])))}}}}function U(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 te(i,n){let{node:r}=i,o=r.openingElement,s=q(o.name),t=o.attributes,a=r.children,c=null,p=[];for(let h of t){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?c={type:x,value:h.value.value}:c={type:x};continue}}p.push(h)}function m(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],x=!1;for(let b of a)if(e.isJSXText(b)){let v=J(b.value);v&&g.push(e.stringLiteral(v))}else if(e.isJSXExpressionContainer(b))e.isJSXEmptyExpression(b.expression)||(x=!0,g.push(b.expression));else if(e.isJSXElement(b)){let v=b.openingElement.name.name;v!=="For"&&v!=="Show"&&v!=="Switch"&&(x=!0),g.push(X({node:b},n))}else e.isJSXFragment(b)&&(x=!0,g.push(L({node:b},n)));let S=e.arrayExpression(g);if(x){let b=n._pendingSetup?n._pendingSetup.splice(h):[];S=e.arrowFunctionExpression([],b.length>0?e.blockStatement([...b,e.returnStatement(S)]):S)}return S}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),s),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let g=null;for(let S of p){if(e.isJSXSpreadAttribute(S)){g=S.argument;continue}let b=$(S);if(b==="key")continue;let v=k(S.value);h.push(e.objectProperty(e.identifier(b),v))}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,m()])}n.needsCreateComponent=!0;let u=[],f=!1,E=null;for(let h of p){if(e.isJSXSpreadAttribute(h)){f=!0,E=h.argument;continue}let g=$(h);if(g==="key")continue;if(A(g)){let S=P(g),b=h.value.expression;S==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):S==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),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:S,modifiers:b}=y(g),v=k(h.value),F=Z(v,b);u.push(e.objectProperty(e.identifier(S),F));continue}let x=k(h.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),x))}let d;f?u.length>0?d=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),E,e.objectExpression(u)]):d=E:u.length>0?d=e.objectExpression(u):d=e.nullLiteral();let l=m();return e.callExpression(e.identifier("_$createComponent"),[s,d,l])}function ve(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null,c=null;for(let v of o)if(e.isJSXAttribute(v)){let F=$(v);F==="each"?t=k(v.value):F==="key"?a=k(v.value):F==="fallback"&&(c=k(v.value))}if(!t)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,G(i,n);let p=null;for(let v of s)if(e.isJSXExpressionContainer(v)&&!e.isJSXEmptyExpression(v.expression)){p=v.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,G(i,n);n.needsMapArray=!0;let m=v=>{let F=[v,p];return a&&F.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),F)};if(!c)return m(t);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,E=`_for$${u}`,d=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let h=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),g=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),t)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(h,g)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(h),e.memberExpression(e.cloneNode(h),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),m(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let x=e.identifier("_parent"),S=e.identifier("_marker"),b=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([x,S],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(b,e.callExpression(e.identifier(E),[e.cloneNode(x),e.cloneNode(S)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(x),e.arrayExpression([e.identifier(d)]),e.cloneNode(S)])),e.returnStatement(e.cloneNode(b))])),e.identifier(E)])}function we(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null;for(let d of o)if(e.isJSXAttribute(d)){let l=$(d);l==="when"?t=k(d.value):l==="fallback"&&(a=k(d.value))}if(!t)throw z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let d of s)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){c=d.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let d=n._pendingSetup.length,l=[];for(let g of s)if(e.isJSXText(g)){let x=J(g.value);x&&l.push(e.stringLiteral(x))}else e.isJSXElement(g)&&l.push(X({node:g},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let h=n._pendingSetup.splice(d);h.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...h,e.returnStatement(c)])),[]))}let p=ae(t,n),m=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(m)]):c,E=a||e.nullLiteral();if(w(p,n.signalNames,n.importedIdentifiers)){let d=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(d),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(m,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(m),f,E))]))}function ae(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&N(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function _e(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let s=J(o.value);s&&r.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(X({node:o},n)):e.isJSXFragment(o)&&r.push(L({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Ae(i,n){let{node:r}=i,o=O(r.openingElement.name.name,n),s=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!O("Match",n));if(!r.children.some(s)&&!ue(r.openingElement.name.name,n))return te(i,n);let t=l=>{throw z(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&t("cannot take a spread attribute"),$(l)==="fallback"&&(a=k(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){J(l.value)&&t("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;t("cannot read its arms from an expression child")}s(l)||t("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&t("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let h=null;for(let b of l.openingElement.attributes)e.isJSXAttribute(b)&&$(b)==="when"&&(h=k(b.value));h||t('has a <Match> with no "when" prop');let g=n._pendingSetup.length,x=_e(l.children,n),S=n._pendingSetup.splice(g);S.length>0&&(x=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...S,e.returnStatement(x)])),[])),p.push([ae(h,n),x])}let m=p.some(([l])=>w(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!m){let l=u;for(let h=p.length-1;h>=0;h--)l=e.conditionalExpression(p[h][0],p[h][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);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([],f)]))]));let d=u;for(let l=p.length-1;l>=0;l--)d=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(E),[]),e.numericLiteral(l)),p[l][1],d);return e.arrowFunctionExpression([],d)}function Ie(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=ne(i,n);if(o){n.needsMapArray=!0;let t=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=D(o.body,r,n),o;if(t)return o;let c=D(o,r,n);return e.arrowFunctionExpression([],c)}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):w(i,n.signalNames,n.importedIdentifiers)?(i=D(i,r,n),e.arrowFunctionExpression([],i)):i}function L(i,n){let{node:r}=i,o=r.children,s=[];for(let t of o)if(e.isJSXText(t)){let a=J(t.value);a&&s.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||s.push(Ie(t.expression,n)):e.isJSXElement(t)?s.push(X({node:t},n)):e.isJSXFragment(t)&&s.push(L({node:t},n));return s.length===1?s[0]:e.arrayExpression(s)}function le(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 ce(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let t=s.get(o);t||(t=Q(i),s.set(o,t)),n.signalNames=t,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,m=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(m=!0),ye(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!m&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ce(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 ke(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 $e(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 fe(i,n,r,o,s){let t=i.node.loc?.start||{line:0,column:0},a=`${s}:${t.line}:${t.column+1}`,c=`${s}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let m={id:r,key:c,bindingName:o,filename:s,source:a,loc:t};if(n.serverActionIds.set(r,m),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(m)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Fe(i,n){if(!ke(i,n))return;let r=Ce(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],s=$e(o);if(s.property){s.value!==null&&fe(i,n,s.value,r,n.serverActionFilename);return}let t=`wa1_${Le(`${n.serverActionFilename}#${r}`)}`;fe(i,n,t,r,n.serverActionFilename);let a=e.objectProperty(e.identifier("id"),e.stringLiteral(t));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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Pe(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,s=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/"),t=s||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((t||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),je.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){me(r)},CallExpression(r){Fe(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,t="";if(e.isIdentifier(s)?t=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(t=s.property.name),pe.has(t)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let s of n.templates.reverse()){let t=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(t,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.id),t)]))}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 s=null;for(let t of i.node.body)if(e.isImportDeclaration(t)&&(t.source.value==="what-framework/render"||t.source.value==="what-core/render")){s=t;break}if(s){let t=new Set(s.specifiers.filter(a=>e.isImportSpecifier(a)).map(a=>a.imported.name));for(let a of r)t.has(a.imported.name)||s.specifiers.push(a)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Re(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(a=>e.stringLiteral(a))),t=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"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),t])}}},JSXElement(i,n){ce(i,n,X)},JSXFragment(i,n){ce(i,n,L)}}}}function Re(e,_,I){let C=null;for(let y of e.node.body)if(_.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){C=y;break}if(C){let y=new Set(C.specifiers.filter(A=>_.isImportSpecifier(A)).map(A=>A.imported.name));for(let A of I)y.has(A.imported.name)||C.specifiers.push(A)}else{let y=_.importDeclaration(I,_.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Oe as default};
1
+ var Je=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Me=new Set(["once","capture","passive"]),Ne=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Xe=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"]),fe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),De=new Set(["For","Show","Switch","Match"]),je=new Set(["what-framework/server","what-server","what-server/actions"]);function Le(e){let _=0xcbf29ce484222325n;for(let I=0;I<e.length;I++)_^=BigInt(e.charCodeAt(I)),_=BigInt.asUintN(64,_*0x100000001b3n);return _.toString(36)}function Pe(e,_){let I=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(_||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&I.startsWith(`${C}/`)?I.slice(C.length+1):I.replace(/^\.\//,"")}function J(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let _=e.split(/\r\n|\n|\r/),I=-1;for(let y=0;y<_.length;y++)/[^ \t]/.test(_[y])&&(I=y);if(I===-1)return"";let C="";for(let y=0;y<_.length;y++){let A=_[y].replace(/\t/g," "),P=y===0,W=y===_.length-1;P||(A=A.replace(/^ +/,"")),W||(A=A.replace(/ +$/,"")),A&&(y!==I&&(A+=" "),C+=A)}return C}function Oe({types:e}){let _=new Set,I=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(s=>s!=="").length===0)}function y(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],s=r.slice(1).filter(t=>Je.has(t));return{eventName:o,modifiers:s}}function A(i){return i.startsWith("bind:")}function P(i){return i.slice(5)}function W(i){return/^[A-Z]/.test(i)}function z(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let s=o?.loc?.start,t=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${t}:${s.line}:${s.column+1}`:t})`)}function j(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&W(n.name)}function O(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function pe(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function ue(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function q(i){return e.isJSXMemberExpression(i)?e.memberExpression(q(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function de(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let m=r.properties[p];if(e.isRestElement(m))return;if(e.isObjectProperty(m)&&!m.computed&&e.isIdentifier(m.key,{name:"children"})){if(o!==-1||!e.isIdentifier(m.value))return;o=p}}if(o===-1)return;let s=i.scope.getBinding(r.properties[o].value.name);if(!s||s.constantViolations.length>0||s.referencePaths.length===0||!s.referencePaths.every(p=>{let m=p.parentPath;if(!m||!m.isJSXExpressionContainer())return!1;let u=m.parentPath;if(!u||!u.isJSXElement()||!j(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&De.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,m)=>m!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of s.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function me(i){return Ne.has(String(i).toLowerCase())}function k(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function K(i){return i==="className"?"class":i==="htmlFor"?"for":i}function $(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 Ee(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 N(i,n){return n.has(i)}function he(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,m="";if(e.isIdentifier(p)?m=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(m=p.property.name),fe.has(m)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function s(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let t=i.scope;for(;t;){for(let c of Object.values(t.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let c of a.params)s(c);a._whatMovedProps&&s(a._whatMovedProps)}t=t.parent}return n}function Q(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 Y(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&N(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)&&N(i.callee.object.name,n)||Q(i))return!1;if(i.arguments.some(o=>w(o,n,r)))return!0}return!1}function w(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&N(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)&&N(i.callee.object.name,n)?!0:Q(i)?i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>w(o,n,r)):w(i.callee,n,r)||i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i)?N(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?w(i.object,n,r):e.isConditionalExpression(i)?w(i.test,n,r)||w(i.consequent,n,r)||w(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?w(i.left,n,r)||w(i.right,n,r):e.isUnaryExpression(i)?w(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>w(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&w(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&w(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function M(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":M(i.left,n);break;case"RestElement":M(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)M(r,n);break;case"ObjectPattern":for(let r of i.properties)M(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function ge(i){let n=new Set;for(let o=1;o<i.params.length;o++)M(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let s of o.declarations)M(s.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":M(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let s of Object.keys(o)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments")continue;let t=o[s];t&&typeof t=="object"&&r(t)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of M(i.params[0],new Set))n.delete(o);return n}function xe(i,n){if(n.size===0)return null;let r=null,o=s=>{if(!(r||!s||typeof s!="object")){if(Array.isArray(s)){s.forEach(o);return}if(s.type==="Identifier"){n.has(s.name)&&(r=s.name);return}for(let t of Object.keys(s)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments"||s.type==="MemberExpression"&&t==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&t==="key"&&!s.computed)continue;let a=s[t];a&&typeof a=="object"&&o(a)}}};return o(i),r}function ee(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let t=R(r.consequent,n),a=R(r.alternate,n);if(t||a){let c=e.conditionalExpression(r.test,t||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let t=R(r.right,n);if(t){let a=e.logicalExpression(r.operator,r.left,t);return o?e.arrowFunctionExpression([],a):a}return null}return R(r,n)}function R(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 d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}}else if(e.isFunctionExpression(r)){let d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,t=null;for(let d of s)if(e.isJSXAttribute(d)&&$(d)==="key"){t=d;break}if(!t)return null;let a=k(t.value);if(!a)return null;let c=ge(r);if(xe(a,c)){let d=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=s.filter(d=>d!==t);let m=i.callee.object,u=e.arrowFunctionExpression([],m),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),E=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),E),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function V(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(j(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(V)}return!1}function ne(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function B(i){if(e.isJSXText(i)){let t=J(i.value);return t?ie(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(j(i))return"";let o=`<${r}`;for(let t of n.attributes){if(e.isJSXSpreadAttribute(t))continue;let a=$(t);if(a==="key"||Ee(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!t.value)o+=` ${c}`;else if(e.isStringLiteral(t.value))o+=` ${c}="${be(t.value.value)}"`;else if(e.isJSXExpressionContainer(t.value))continue}let s=i.openingElement.selfClosing;if(s&&me(r))return o+=">",o;if(s)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let a=J(t.value);a&&(o+=ie(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)&&(j(t)?o+="<!--$-->":o+=B(t));return o+=`</${r}>`,o}function ie(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function be(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name;if(!O(s,n)){if(s==="For")return ve(i,n);if(s==="Show")return we(i,n)}if(s==="Switch"&&(!O(s,n)||ue(r)))return Ae(i,n);if(j(r))return se(i,n);let t=o.attributes,a=r.children,c=a.every(V),p=t.every(l=>!ne(l)),m=t.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let h=$(l);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(c&&p&&m){let l=B(r);if(l){let h=ae(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let u=B(r);if(!u){let l=r.loc,h=n.filename||n.file?.opts?.filename||"<unknown>",g=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${h}${g}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,G(i,n)}let f=ae(n,u);n.needsTemplate=!0;let E=n.nextVarId(),d=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier(f),[]))])];return re(d,E,t,n,s),oe(d,E,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...d),e.identifier(E)}function G(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,t=o.attributes,a=r.children,c=[];for(let u of t){if(e.isJSXSpreadAttribute(u))continue;let f=$(u),E=k(u.value),d=K(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(d)?e.identifier(d):e.stringLiteral(d),E))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=J(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(X({node:u},n)):e.isJSXFragment(u)&&p.push(L({node:u},n));let m=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),m,...p])}let Se=new Set(["input","textarea","select","option"]);function re(i,n,r,o,s){function t(p,m){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),m])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),m])):p==="value"&&s&&Se.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),m])):p==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),m])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),m])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),m]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let m=$(p);if(m!=="key"){if(m==="ref"){let u=k(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(m.startsWith("on")&&!m.includes("|")&&!C(m,o)){let u=m.slice(2).toLowerCase(),f=k(p.value);Xe.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(m.startsWith("on")&&(m.includes("|")||C(m,o))){let{eventName:u,modifiers:f}=y(m),E=k(p.value),d=Z(E,f),l=u.slice(2).toLowerCase(),h=f.filter(x=>Me.has(x)),g=[e.stringLiteral(l),d];if(h.length>0){let x=h.map(S=>e.objectProperty(e.identifier(S),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(m)){let u=P(m),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=K(m);if(w(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let E=o.signalNames&&o.signalNames.fromDestructuredProps,d=e.isIdentifier(u)&&!(E&&E.has(u.name))&&(N(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],t(f,d))]);Y(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(t(f,u)))}}}}function H(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(H);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"&&H(r))return!0}return!1}function ye(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function D(i,n,r){let o=null,s=!1;if(e.isConditionalExpression(i))o=i.test,s=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!w(o,r.signalNames,r.importedIdentifiers)||!(s?[i.consequent,i.alternate]:[i.right]).some(H))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return s?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function oe(i,n,r,o,s){let t=[],a=0;for(let f of r){if(e.isJSXText(f)){J(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;t.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let E=f.openingElement.name.name;if(j(f)||E==="For"||E==="Show")t.push({type:"component",child:f,childIndex:a}),a++;else{let d=f.openingElement.attributes.some(ne)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&$(l)?.startsWith("on"))||!f.children.every(V);t.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:d}),a++}continue}e.isJSXFragment(f)&&t.push({type:"fragment",child:f})}let c=t.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,m=new Map;if(p){let f=null,E=0;for(let d of c){let l=d.childIndex,h=s.nextVarId();m.set(l,h);let g;if(f===null)g=U(n,l);else{g=e.identifier(f);for(let x=E;x<l;x++)g=e.memberExpression(g,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),g)])),f=h,E=l}}function u(f){return m.has(f)?e.identifier(m.get(f)):U(n,f)}for(let f of t){if(f.type==="expression"){let E=f.child.expression,d=u(f.childIndex);s.needsInsert=!0;let l=ee(E,s);if(l){s.needsMapArray=!0;let g=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),x=e.isArrowFunctionExpression(l);x&&e.isExpression(l.body)?l.body=D(l.body,i,s):!g&&!x&&(l=D(l,i,s));let S=g||x?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),S,d])));continue}if(e.isCallExpression(E)&&e.isIdentifier(E.callee)&&(E.callee.name==="mapArray"||E.callee.name==="_$mapArray")){s.needsMapArray=!0,E.callee.name==="mapArray"&&(E.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(w(E,s.signalNames,s.importedIdentifiers)){E=D(E,i,s);let g=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],E),d]);Y(E,s.signalNames,s.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,d])));continue}if(f.type==="component"){let E=X({node:f.child},s),d=u(f.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let E;m.has(f.childIndex)?E=m.get(f.childIndex):(E=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),U(n,f.childIndex))]))),re(i,E,f.child.openingElement.attributes,s,f.child.openingElement.name.name),oe(i,E,f.child.children,f.child,s);continue}if(f.type==="fragment"){for(let E of f.child.children)if(e.isJSXExpressionContainer(E)&&!e.isJSXEmptyExpression(E.expression)){s.needsInsert=!0;let d=E.expression;w(d,s.signalNames,s.importedIdentifiers)?(d=D(d,i,s),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],d)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),d])))}}}}function U(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 se(i,n){let{node:r}=i,o=r.openingElement,s=q(o.name),t=o.attributes,a=r.children,c=null,p=[];for(let h of t){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?c={type:x,value:h.value.value}:c={type:x};continue}}p.push(h)}function m(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],x=!1;for(let b of a)if(e.isJSXText(b)){let v=J(b.value);v&&g.push(e.stringLiteral(v))}else if(e.isJSXExpressionContainer(b))e.isJSXEmptyExpression(b.expression)||(x=!0,g.push(b.expression));else if(e.isJSXElement(b)){let v=b.openingElement.name.name;v!=="For"&&v!=="Show"&&v!=="Switch"&&(x=!0),g.push(X({node:b},n))}else e.isJSXFragment(b)&&(x=!0,g.push(L({node:b},n)));let S=e.arrayExpression(g);if(x){let b=n._pendingSetup?n._pendingSetup.splice(h):[];S=e.arrowFunctionExpression([],b.length>0?e.blockStatement([...b,e.returnStatement(S)]):S)}return S}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),s),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let g=null;for(let S of p){if(e.isJSXSpreadAttribute(S)){g=S.argument;continue}let b=$(S);if(b==="key")continue;let v=k(S.value);h.push(e.objectProperty(e.identifier(b),v))}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,m()])}n.needsCreateComponent=!0;let u=[],f=!1,E=null;for(let h of p){if(e.isJSXSpreadAttribute(h)){f=!0,E=h.argument;continue}let g=$(h);if(g==="key")continue;if(A(g)){let S=P(g),b=h.value.expression;S==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):S==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),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:S,modifiers:b}=y(g),v=k(h.value),F=Z(v,b);u.push(e.objectProperty(e.identifier(S),F));continue}let x=k(h.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),x))}let d;f?u.length>0?d=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),E,e.objectExpression(u)]):d=E:u.length>0?d=e.objectExpression(u):d=e.nullLiteral();let l=m();return e.callExpression(e.identifier("_$createComponent"),[s,d,l])}function ve(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null,c=null;for(let v of o)if(e.isJSXAttribute(v)){let F=$(v);F==="each"?t=k(v.value):F==="key"?a=k(v.value):F==="fallback"&&(c=k(v.value))}if(!t)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,G(i,n);let p=null;for(let v of s)if(e.isJSXExpressionContainer(v)&&!e.isJSXEmptyExpression(v.expression)){p=v.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,G(i,n);n.needsMapArray=!0;let m=v=>{let F=[v,p];return a&&F.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),F)};if(!c)return m(t);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,E=`_for$${u}`,d=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let h=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),g=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),t)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(h,g)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(h),e.memberExpression(e.cloneNode(h),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),m(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let x=e.identifier("_parent"),S=e.identifier("_marker"),b=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([x,S],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(b,e.callExpression(e.identifier(E),[e.cloneNode(x),e.cloneNode(S)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(x),e.arrayExpression([e.identifier(d)]),e.cloneNode(S)])),e.returnStatement(e.cloneNode(b))])),e.identifier(E)])}function we(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null;for(let d of o)if(e.isJSXAttribute(d)){let l=$(d);l==="when"?t=k(d.value):l==="fallback"&&(a=k(d.value))}if(!t)throw z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let d of s)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){c=d.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let d=n._pendingSetup.length,l=[];for(let g of s)if(e.isJSXText(g)){let x=J(g.value);x&&l.push(e.stringLiteral(x))}else e.isJSXElement(g)&&l.push(X({node:g},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let h=n._pendingSetup.splice(d);h.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...h,e.returnStatement(c)])),[]))}let p=te(t,n),m=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(m)]):c,E=a||e.nullLiteral();if(w(p,n.signalNames,n.importedIdentifiers)){let d=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(d),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(m,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(m),f,E))]))}function te(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&N(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function _e(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let s=J(o.value);s&&r.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(X({node:o},n)):e.isJSXFragment(o)&&r.push(L({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Ae(i,n){let{node:r}=i,o=O(r.openingElement.name.name,n),s=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!O("Match",n));if(!r.children.some(s)&&!pe(r.openingElement.name.name,n))return se(i,n);let t=l=>{throw z(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&t("cannot take a spread attribute"),$(l)==="fallback"&&(a=k(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){J(l.value)&&t("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;t("cannot read its arms from an expression child")}s(l)||t("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&t("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let h=null;for(let b of l.openingElement.attributes)e.isJSXAttribute(b)&&$(b)==="when"&&(h=k(b.value));h||t('has a <Match> with no "when" prop');let g=n._pendingSetup.length,x=_e(l.children,n),S=n._pendingSetup.splice(g);S.length>0&&(x=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...S,e.returnStatement(x)])),[])),p.push([te(h,n),x])}let m=p.some(([l])=>w(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!m){let l=u;for(let h=p.length-1;h>=0;h--)l=e.conditionalExpression(p[h][0],p[h][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);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([],f)]))]));let d=u;for(let l=p.length-1;l>=0;l--)d=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(E),[]),e.numericLiteral(l)),p[l][1],d);return e.arrowFunctionExpression([],d)}function Ie(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=ee(i,n);if(o){n.needsMapArray=!0;let t=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=D(o.body,r,n),o;if(t)return o;let c=D(o,r,n);return e.arrowFunctionExpression([],c)}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):w(i,n.signalNames,n.importedIdentifiers)?(i=D(i,r,n),e.arrowFunctionExpression([],i)):i}function L(i,n){let{node:r}=i,o=r.children,s=[];for(let t of o)if(e.isJSXText(t)){let a=J(t.value);a&&s.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||s.push(Ie(t.expression,n)):e.isJSXElement(t)?s.push(X({node:t},n)):e.isJSXFragment(t)&&s.push(L({node:t},n));return s.length===1?s[0]:e.arrayExpression(s)}function ae(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 le(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let t=s.get(o);t||(t=he(i),s.set(o,t)),n.signalNames=t,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,m=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(m=!0),ye(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!m&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ce(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 ke(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 $e(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 ce(i,n,r,o,s){let t=i.node.loc?.start||{line:0,column:0},a=`${s}:${t.line}:${t.column+1}`,c=`${s}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let m={id:r,key:c,bindingName:o,filename:s,source:a,loc:t};if(n.serverActionIds.set(r,m),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(m)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Fe(i,n){if(!ke(i,n))return;let r=Ce(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],s=$e(o);if(s.property){s.value!==null&&ce(i,n,s.value,r,n.serverActionFilename);return}let t=`wa1_${Le(`${n.serverActionFilename}#${r}`)}`;ce(i,n,t,r,n.serverActionFilename);let a=e.objectProperty(e.identifier("id"),e.stringLiteral(t));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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Pe(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,s=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/"),t=s||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((t||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),je.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){de(r)},CallExpression(r){Fe(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,t="";if(e.isIdentifier(s)?t=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(t=s.property.name),fe.has(t)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let s of n.templates.reverse()){let t=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(t,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.id),t)]))}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 s=null;for(let t of i.node.body)if(e.isImportDeclaration(t)&&(t.source.value==="what-framework/render"||t.source.value==="what-core/render")){s=t;break}if(s){let t=new Set(s.specifiers.filter(a=>e.isImportSpecifier(a)).map(a=>a.imported.name));for(let a of r)t.has(a.imported.name)||s.specifiers.push(a)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Re(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(a=>e.stringLiteral(a))),t=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"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),t])}}},JSXElement(i,n){le(i,n,X)},JSXFragment(i,n){le(i,n,L)}}}}function Re(e,_,I){let C=null;for(let y of e.node.body)if(_.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){C=y;break}if(C){let y=new Set(C.specifiers.filter(A=>_.isImportSpecifier(A)).map(A=>A.imported.name));for(let A of I)y.has(A.imported.name)||C.specifiers.push(A)}else{let y=_.importDeclaration(I,_.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Oe as default};
package/dist/index.min.js CHANGED
@@ -1,15 +1,15 @@
1
- var Ze=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ye=new Set(["once","capture","passive"]),Qe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),en=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),ne=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),Ie=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),nn=new Set(["For","Show","Switch","Match"]),rn=new Set(["what-framework/server","what-server","what-server/actions"]);function on(e){let m=0xcbf29ce484222325n;for(let d=0;d<e.length;d++)m^=BigInt(e.charCodeAt(d)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function tn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),v=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return v&&d.startsWith(`${v}/`)?d.slice(v.length+1):d.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),d=-1;for(let E=0;E<m.length;E++)/[^ \t]/.test(m[E])&&(d=E);if(d===-1)return"";let v="";for(let E=0;E<m.length;E++){let w=m[E].replace(/\t/g," "),_=E===0,k=E===m.length-1;_||(w=w.replace(/^ +/,"")),k||(w=w.replace(/ +$/,"")),w&&(E!==d&&(w+=" "),v+=w)}return v}function ie({types:e}){let m=new Set,d=new Set;function v(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(s=>Ze.has(s));return{eventName:o,modifiers:t}}function w(i){return i.startsWith("bind:")}function _(i){return i.slice(5)}function k(i){return/^[A-Z]/.test(i)}function j(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let t=o?.loc?.start,s=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${t?`${s}:${t.line}:${t.column+1}`:s})`)}function M(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&k(n.name)}function $(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function J(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function P(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function T(i){return e.isJSXMemberExpression(i)?e.memberExpression(T(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function X(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let g=r.properties[p];if(e.isRestElement(g))return;if(e.isObjectProperty(g)&&!g.computed&&e.isIdentifier(g.key,{name:"children"})){if(o!==-1||!e.isIdentifier(g.value))return;o=p}}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(p=>{let g=p.parentPath;if(!g||!g.isJSXExpressionContainer())return!1;let u=g.parentPath;if(!u||!u.isJSXElement()||!M(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&nn.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,g)=>g!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of t.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function V(i){return Qe.has(String(i).toLowerCase())}function b(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function I(i){return i==="className"?"class":i==="htmlFor"?"for":i}function A(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 K(i){return!!i&&i.length>2&&/^on/i.test(i)}function U(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 D(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,g="";if(e.isIdentifier(p)?g=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(g=p.property.name),Ie.has(g)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function t(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let s=i.scope;for(;s;){for(let c of Object.values(s.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=s.path&&s.path.node;if(a){if(a.params)for(let c of a.params)t(c);a._whatMovedProps&&t(a._whatMovedProps)}s=s.parent}return n}function te(i){return D(i)}function se(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ne.has(n.object.name):e.isIdentifier(n)?ne.has(n.name):!1}function Ee(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)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)||se(i))return!1;if(i.arguments.some(o=>O(o,n,r)))return!0}return!1}function O(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)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)?!0:se(i)?i.arguments.some(o=>O(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>O(o,n,r)):O(i.callee,n,r)||i.arguments.some(o=>O(o,n,r)):e.isIdentifier(i)?R(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?O(i.object,n,r):e.isConditionalExpression(i)?O(i.test,n,r)||O(i.consequent,n,r)||O(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?O(i.left,n,r)||O(i.right,n,r):e.isUnaryExpression(i)?O(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>O(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&O(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&O(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function B(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":B(i.left,n);break;case"RestElement":B(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)B(r,n);break;case"ObjectPattern":for(let r of i.properties)B(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function De(i){let n=new Set;for(let o=1;o<i.params.length;o++)B(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let t of o.declarations)B(t.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":B(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let t of Object.keys(o)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments")continue;let s=o[t];s&&typeof s=="object"&&r(s)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of B(i.params[0],new Set))n.delete(o);return n}function Je(i,n){if(n.size===0)return null;let r=null,o=t=>{if(!(r||!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(o);return}if(t.type==="Identifier"){n.has(t.name)&&(r=t.name);return}for(let s of Object.keys(t)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments"||t.type==="MemberExpression"&&s==="property"&&!t.computed||(t.type==="ObjectProperty"||t.type==="ObjectMethod")&&s==="key"&&!t.computed)continue;let a=t[s];a&&typeof a=="object"&&o(a)}}};return o(i),r}function xe(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=ee(r.consequent,n),a=ee(r.alternate,n);if(s||a){let c=e.conditionalExpression(r.test,s||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let s=ee(r.right,n);if(s){let a=e.logicalExpression(r.operator,r.left,s);return o?e.arrowFunctionExpression([],a):a}return null}return ee(r,n)}function ee(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 h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}}else if(e.isFunctionExpression(r)){let h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,s=null;for(let h of t)if(e.isJSXAttribute(h)&&A(h)==="key"){s=h;break}if(!s)return null;let a=b(s.value);if(!a)return null;let c=De(r);if(Je(a,c)){let h=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=t.filter(h=>h!==s);let g=i.callee.object,u=e.arrowFunctionExpression([],g),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),x=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),x),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function ae(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(ae)}return!1}function be(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function le(i){if(e.isJSXText(i)){let s=H(i.value);return s?ye(s):""}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 s of n.attributes){if(e.isJSXSpreadAttribute(s))continue;let a=A(s);if(a==="key"||K(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!s.value)o+=` ${c}`;else if(e.isStringLiteral(s.value))o+=` ${c}="${Te(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let t=i.openingElement.selfClosing;if(t&&V(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let s of i.children)if(e.isJSXText(s)){let a=H(s.value);a&&(o+=ye(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(o+="<!--$-->"):e.isJSXElement(s)&&(M(s)?o+="<!--$-->":o+=le(s));return o+=`</${r}>`,o}function ye(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Te(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function z(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!$(t,n)){if(t==="For")return We(i,n);if(t==="Show")return He(i,n)}if(t==="Switch"&&(!$(t,n)||P(r)))return Be(i,n);if(M(r))return ve(i,n);let s=o.attributes,a=r.children,c=a.every(ae),p=s.every(l=>!be(l)),g=s.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let y=A(l);return!y?.startsWith("on")&&!y?.startsWith("bind:")});if(c&&p&&g){let l=le(r);if(l){let y=ke(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(y),[])}}let u=le(r);if(!u){let l=r.loc,y=n.filename||n.file?.opts?.filename||"<unknown>",S=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${y}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,ce(i,n)}let f=ke(n,u);n.needsTemplate=!0;let x=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier(f),[]))])];return Se(h,x,s,n,t),we(h,x,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(x)}function ce(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,c=[];for(let u of s){if(e.isJSXSpreadAttribute(u))continue;let f=A(u),x=b(u.value),h=I(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),x))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=H(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(z({node:u},n)):e.isJSXFragment(u)&&p.push(Z({node:u},n));let g=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),g,...p])}let Xe=new Set(["input","textarea","select","option"]);function Se(i,n,r,o,t){function s(p,g){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),g])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),g])):p==="value"&&t&&Xe.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),g])):p==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),g])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),g])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),g]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let g=A(p);if(g!=="key"){if(g==="ref"){let u=b(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(g.startsWith("on")&&!g.includes("|")&&!v(g,o)){let u=g.slice(2).toLowerCase(),f=b(p.value);en.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(g.startsWith("on")&&(g.includes("|")||v(g,o))){let{eventName:u,modifiers:f}=E(g),x=b(p.value),h=U(x,f),l=u.slice(2).toLowerCase(),y=f.filter(C=>Ye.has(C)),S=[e.stringLiteral(l),h];if(y.length>0){let C=y.map(L=>e.objectProperty(e.identifier(L),e.booleanLiteral(!0)));S.push(e.objectExpression(C))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),S)));continue}if(w(g)){let u=_(g),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=I(g);if(O(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let x=o.signalNames&&o.signalNames.fromDestructuredProps,h=e.isIdentifier(u)&&!(x&&x.has(u.name))&&(R(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],s(f,h))]);Ee(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(s(f,u)))}}}}function fe(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(fe);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"&&fe(r))return!0}return!1}function Re(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function q(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(!O(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(fe))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function we(i,n,r,o,t){let s=[],a=0;for(let f of r){if(e.isJSXText(f)){H(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;s.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let x=f.openingElement.name.name;if(M(f)||x==="For"||x==="Show")s.push({type:"component",child:f,childIndex:a}),a++;else{let h=f.openingElement.attributes.some(be)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&A(l)?.startsWith("on"))||!f.children.every(ae);s.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:h}),a++}continue}e.isJSXFragment(f)&&s.push({type:"fragment",child:f})}let c=s.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,g=new Map;if(p){let f=null,x=0;for(let h of c){let l=h.childIndex,y=t.nextVarId();g.set(l,y);let S;if(f===null)S=pe(n,l);else{S=e.identifier(f);for(let C=x;C<l;C++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(y),S)])),f=y,x=l}}function u(f){return g.has(f)?e.identifier(g.get(f)):pe(n,f)}for(let f of s){if(f.type==="expression"){let x=f.child.expression,h=u(f.childIndex);t.needsInsert=!0;let l=xe(x,t);if(l){t.needsMapArray=!0;let S=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),C=e.isArrowFunctionExpression(l);C&&e.isExpression(l.body)?l.body=q(l.body,i,t):!S&&!C&&(l=q(l,i,t));let L=S||C?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),L,h])));continue}if(e.isCallExpression(x)&&e.isIdentifier(x.callee)&&(x.callee.name==="mapArray"||x.callee.name==="_$mapArray")){t.needsMapArray=!0,x.callee.name==="mapArray"&&(x.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(O(x,t.signalNames,t.importedIdentifiers)){x=q(x,i,t);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],x),h]);Ee(x,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(S))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="component"){let x=z({node:f.child},t),h=u(f.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let x;g.has(f.childIndex)?x=g.get(f.childIndex):(x=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),pe(n,f.childIndex))]))),Se(i,x,f.child.openingElement.attributes,t,f.child.openingElement.name.name),we(i,x,f.child.children,f.child,t);continue}if(f.type==="fragment"){for(let x of f.child.children)if(e.isJSXExpressionContainer(x)&&!e.isJSXEmptyExpression(x.expression)){t.needsInsert=!0;let h=x.expression;O(h,t.signalNames,t.importedIdentifiers)?(h=q(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 pe(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 ve(i,n){let{node:r}=i,o=r.openingElement,t=T(o.name),s=o.attributes,a=r.children,c=null,p=[];for(let y of s){if(e.isJSXAttribute(y)){let S;if(e.isJSXNamespacedName(y.name)?S=`${y.name.namespace.name}:${y.name.name.name}`:S=y.name.name,S&&typeof S=="string"&&S.startsWith("client:")){let C=S.slice(7);y.value?c={type:C,value:y.value.value}:c={type:C};continue}}p.push(y)}function g(){let y=n._pendingSetup?n._pendingSetup.length:0,S=[],C=!1;for(let F of a)if(e.isJSXText(F)){let N=H(F.value);N&&S.push(e.stringLiteral(N))}else if(e.isJSXExpressionContainer(F))e.isJSXEmptyExpression(F.expression)||(C=!0,S.push(F.expression));else if(e.isJSXElement(F)){let N=F.openingElement.name.name;N!=="For"&&N!=="Show"&&N!=="Switch"&&(C=!0),S.push(z({node:F},n))}else e.isJSXFragment(F)&&(C=!0,S.push(Z({node:F},n)));let L=e.arrayExpression(S);if(C){let F=n._pendingSetup?n._pendingSetup.splice(y):[];L=e.arrowFunctionExpression([],F.length>0?e.blockStatement([...F,e.returnStatement(L)]):L)}return L}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let y=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&y.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let S=null;for(let L of p){if(e.isJSXSpreadAttribute(L)){S=L.argument;continue}let F=A(L);if(F==="key")continue;let N=b(L.value);y.push(e.objectProperty(e.identifier(F),N))}let C=S?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),S,e.objectExpression(y)]):e.objectExpression(y);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),C,g()])}n.needsCreateComponent=!0;let u=[],f=!1,x=null;for(let y of p){if(e.isJSXSpreadAttribute(y)){f=!0,x=y.argument;continue}let S=A(y);if(S==="key")continue;if(w(S)){let L=_(S),F=y.value.expression;L==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(F),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(F),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):L==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(F),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(F),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(S.startsWith("on")&&(S.includes("|")||v(S,n))){let{eventName:L,modifiers:F}=E(S),N=b(y.value),W=U(N,F);u.push(e.objectProperty(e.identifier(L),W));continue}let C=b(y.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(S)?e.identifier(S):e.stringLiteral(S),C))}let h;f?u.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),x,e.objectExpression(u)]):h=x:u.length>0?h=e.objectExpression(u):h=e.nullLiteral();let l=g();return e.callExpression(e.identifier("_$createComponent"),[t,h,l])}function We(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null,c=null;for(let N of o)if(e.isJSXAttribute(N)){let W=A(N);W==="each"?s=b(N.value):W==="key"?a=b(N.value):W==="fallback"&&(c=b(N.value))}if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ce(i,n);let p=null;for(let N of t)if(e.isJSXExpressionContainer(N)&&!e.isJSXEmptyExpression(N.expression)){p=N.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ce(i,n);n.needsMapArray=!0;let g=N=>{let W=[N,p];return a&&W.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),W)};if(!c)return g(s);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,x=`_for$${u}`,h=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let y=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),s)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(y,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(y),e.memberExpression(e.cloneNode(y),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),g(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let C=e.identifier("_parent"),L=e.identifier("_marker"),F=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([C,L],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(F,e.callExpression(e.identifier(x),[e.cloneNode(C),e.cloneNode(L)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(C),e.arrayExpression([e.identifier(h)]),e.cloneNode(L)])),e.returnStatement(e.cloneNode(F))])),e.identifier(x)])}function He(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 l=A(h);l==="when"?s=b(h.value):l==="fallback"&&(a=b(h.value))}if(!s)throw j(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){c=h.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let h=n._pendingSetup.length,l=[];for(let S of t)if(e.isJSXText(S)){let C=H(S.value);C&&l.push(e.stringLiteral(C))}else e.isJSXElement(S)&&l.push(z({node:S},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let y=n._pendingSetup.splice(h);y.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...y,e.returnStatement(c)])),[]))}let p=_e(s,n),g=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(g)]):c,x=a||e.nullLiteral();if(O(p,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(g,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(g),f,x))]))}function _e(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 Ve(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(z({node:o},n)):e.isJSXFragment(o)&&r.push(Z({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Be(i,n){let{node:r}=i,o=$(r.openingElement.name.name,n),t=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!$("Match",n));if(!r.children.some(t)&&!J(r.openingElement.name.name,n))return ve(i,n);let s=l=>{throw j(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&s("cannot take a spread attribute"),A(l)==="fallback"&&(a=b(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){H(l.value)&&s("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s("cannot read its arms from an expression child")}t(l)||s("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&s("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let y=null;for(let F of l.openingElement.attributes)e.isJSXAttribute(F)&&A(F)==="when"&&(y=b(F.value));y||s('has a <Match> with no "when" prop');let S=n._pendingSetup.length,C=Ve(l.children,n),L=n._pendingSetup.splice(S);L.length>0&&(C=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...L,e.returnStatement(C)])),[])),p.push([_e(y,n),C])}let g=p.some(([l])=>O(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!g){let l=u;for(let y=p.length-1;y>=0;y--)l=e.conditionalExpression(p[y][0],p[y][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);let x=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))]));let h=u;for(let l=p.length-1;l>=0;l--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(x),[]),e.numericLiteral(l)),p[l][1],h);return e.arrowFunctionExpression([],h)}function Ge(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=xe(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=q(o.body,r,n),o;if(s)return o;let c=q(o,r,n);return e.arrowFunctionExpression([],c)}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):O(i,n.signalNames,n.importedIdentifiers)?(i=q(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=H(s.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||t.push(Ge(s.expression,n)):e.isJSXElement(s)?t.push(z({node:s},n)):e.isJSXFragment(s)&&t.push(Z({node:s},n));return t.length===1?t[0]:e.arrayExpression(t)}function ke(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 $e(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let s=t.get(o);s||(s=D(i),t.set(o,s)),n.signalNames=s,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,g=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(g=!0),Re(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!g&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ue(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 ze(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 qe(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 Ce(i,n,r,o,t){let s=i.node.loc?.start||{line:0,column:0},a=`${t}:${s.line}:${s.column+1}`,c=`${t}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let g={id:r,key:c,bindingName:o,filename:t,source:a,loc:s};if(n.serverActionIds.set(r,g),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(g)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Ke(i,n){if(!ze(i,n))return;let r=Ue(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=qe(o);if(t.property){t.value!==null&&Ce(i,n,t.value,r,n.serverActionFilename);return}let s=`wa1_${on(`${n.serverActionFilename}#${r}`)}`;Ce(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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=tn(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/"),s=t||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((s||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),t?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),rn.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){X(r)},CallExpression(r){Ke(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),Ie.has(s)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.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&&sn(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){$e(i,n,z)},JSXFragment(i,n){$e(i,n,Z)}}}}function sn(e,m,d){let v=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){v=E;break}if(v){let E=new Set(v.specifiers.filter(w=>m.isImportSpecifier(w)).map(w=>w.imported.name));for(let w of d)E.has(w.imported.name)||v.specifiers.push(w)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import Q from"path";import{transformSync as xn}from"@babel/core";import Y from"fs";import G from"path";var Ae=new Set([".jsx",".tsx",".js",".ts"]),an=new Set(["_layout","_error","_loading","_404"]);function Pe(e){let m=[],d=[],v=[];function E(_,k=""){if(!Y.existsSync(_))return;let j=Y.readdirSync(_,{withFileTypes:!0});for(let M of j){let $=G.join(_,M.name);if(M.isDirectory()){if(M.name.match(/^\((.+)\)$/)){E($,k);continue}if(M.name==="api"&&k===""){w($,"/api");continue}E($,k+"/"+re(M.name));continue}let J=G.extname(M.name);if(!Ae.has(J))continue;let P=G.basename(M.name,J);if(P==="_layout"){d.push({filePath:$,urlPrefix:k||"/"});continue}if(an.has(P))continue;let T=re(P),X=P==="index"?k||"/":k+"/"+T;m.push({filePath:$,routePath:Fe(X),isDynamic:X.includes(":")||X.includes("*")})}}function w(_,k){if(!Y.existsSync(_))return;let j=Y.readdirSync(_,{withFileTypes:!0});for(let M of j){let $=G.join(_,M.name);if(M.isDirectory()){w($,k+"/"+re(M.name));continue}let J=G.extname(M.name);if(!Ae.has(J))continue;let P=G.basename(M.name,J),T=re(P),X=P==="index"?k:k+"/"+T;v.push({filePath:$,routePath:Fe(X)})}}return E(e),m.sort((_,k)=>{let j=Me(_.routePath),M=Me(k.routePath);return j-M}),{pages:m,layouts:d,apiRoutes:v}}function re(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function Fe(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Me(e){return e.includes("*")?100:e.includes(":")?10:0}var ln=/export\s+const\s+page\s*=\s*\{/;function Ne(e,m={}){let d=ln.exec(e);if(!d)return{mode:"client"};let v=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(un(e,v))}}catch(E){return cn(E,m.filePath),{mode:"client"}}}function cn(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
1
+ var Ke=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ze=new Set(["once","capture","passive"]),Ye=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Qe=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),ne=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),Ce=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),en=new Set(["For","Show","Switch","Match"]),nn=new Set(["what-framework/server","what-server","what-server/actions"]);function rn(e){let m=0xcbf29ce484222325n;for(let d=0;d<e.length;d++)m^=BigInt(e.charCodeAt(d)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function on(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),w=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return w&&d.startsWith(`${w}/`)?d.slice(w.length+1):d.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),d=-1;for(let E=0;E<m.length;E++)/[^ \t]/.test(m[E])&&(d=E);if(d===-1)return"";let w="";for(let E=0;E<m.length;E++){let S=m[E].replace(/\t/g," "),v=E===0,$=E===m.length-1;v||(S=S.replace(/^ +/,"")),$||(S=S.replace(/ +$/,"")),S&&(E!==d&&(S+=" "),w+=S)}return w}function ie({types:e}){let m=new Set,d=new Set;function w(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(s=>Ke.has(s));return{eventName:o,modifiers:t}}function S(i){return i.startsWith("bind:")}function v(i){return i.slice(5)}function $(i){return/^[A-Z]/.test(i)}function O(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let t=o?.loc?.start,s=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${t?`${s}:${t.line}:${t.column+1}`:s})`)}function F(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&$(n.name)}function C(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function J(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function j(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function X(i){return e.isJSXMemberExpression(i)?e.memberExpression(X(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function R(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let g=r.properties[p];if(e.isRestElement(g))return;if(e.isObjectProperty(g)&&!g.computed&&e.isIdentifier(g.key,{name:"children"})){if(o!==-1||!e.isIdentifier(g.value))return;o=p}}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(p=>{let g=p.parentPath;if(!g||!g.isJSXExpressionContainer())return!1;let u=g.parentPath;if(!u||!u.isJSXElement()||!F(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&en.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,g)=>g!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of t.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function k(i){return Ye.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 D(i){return i==="className"?"class":i==="htmlFor"?"for":i}function T(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 z(i){return!!i&&i.length>2&&/^on/i.test(i)}function Y(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 L(i,n){return n.has(i)}function Q(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,g="";if(e.isIdentifier(p)?g=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(g=p.property.name),Ce.has(g)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function t(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let s=i.scope;for(;s;){for(let c of Object.values(s.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=s.path&&s.path.node;if(a){if(a.params)for(let c of a.params)t(c);a._whatMovedProps&&t(a._whatMovedProps)}s=s.parent}return n}function te(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ne.has(n.object.name):e.isIdentifier(n)?ne.has(n.name):!1}function ge(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&L(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&L(i.callee.object.name,n)||te(i))return!1;if(i.arguments.some(o=>N(o,n,r)))return!0}return!1}function N(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&L(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&L(i.callee.object.name,n)?!0:te(i)?i.arguments.some(o=>N(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>N(o,n,r)):N(i.callee,n,r)||i.arguments.some(o=>N(o,n,r)):e.isIdentifier(i)?L(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?N(i.object,n,r):e.isConditionalExpression(i)?N(i.test,n,r)||N(i.consequent,n,r)||N(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?N(i.left,n,r)||N(i.right,n,r):e.isUnaryExpression(i)?N(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>N(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&N(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&N(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function V(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":V(i.left,n);break;case"RestElement":V(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)V(r,n);break;case"ObjectPattern":for(let r of i.properties)V(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function je(i){let n=new Set;for(let o=1;o<i.params.length;o++)V(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let t of o.declarations)V(t.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":V(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let t of Object.keys(o)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments")continue;let s=o[t];s&&typeof s=="object"&&r(s)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of V(i.params[0],new Set))n.delete(o);return n}function De(i,n){if(n.size===0)return null;let r=null,o=t=>{if(!(r||!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(o);return}if(t.type==="Identifier"){n.has(t.name)&&(r=t.name);return}for(let s of Object.keys(t)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments"||t.type==="MemberExpression"&&s==="property"&&!t.computed||(t.type==="ObjectProperty"||t.type==="ObjectMethod")&&s==="key"&&!t.computed)continue;let a=t[s];a&&typeof a=="object"&&o(a)}}};return o(i),r}function Ee(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=ee(r.consequent,n),a=ee(r.alternate,n);if(s||a){let c=e.conditionalExpression(r.test,s||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let s=ee(r.right,n);if(s){let a=e.logicalExpression(r.operator,r.left,s);return o?e.arrowFunctionExpression([],a):a}return null}return ee(r,n)}function ee(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 h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}}else if(e.isFunctionExpression(r)){let h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,s=null;for(let h of t)if(e.isJSXAttribute(h)&&T(h)==="key"){s=h;break}if(!s)return null;let a=_(s.value);if(!a)return null;let c=je(r);if(De(a,c)){let h=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=t.filter(h=>h!==s);let g=i.callee.object,u=e.arrowFunctionExpression([],g),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),x=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),x),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(F(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 xe(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function ae(i){if(e.isJSXText(i)){let s=H(i.value);return s?be(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(F(i))return"";let o=`<${r}`;for(let s of n.attributes){if(e.isJSXSpreadAttribute(s))continue;let a=T(s);if(a==="key"||z(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!s.value)o+=` ${c}`;else if(e.isStringLiteral(s.value))o+=` ${c}="${Te(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let t=i.openingElement.selfClosing;if(t&&k(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let s of i.children)if(e.isJSXText(s)){let a=H(s.value);a&&(o+=be(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(o+="<!--$-->"):e.isJSXElement(s)&&(F(s)?o+="<!--$-->":o+=ae(s));return o+=`</${r}>`,o}function be(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Te(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function U(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!C(t,n)){if(t==="For")return Re(i,n);if(t==="Show")return We(i,n)}if(t==="Switch"&&(!C(t,n)||j(r)))return Ve(i,n);if(F(r))return we(i,n);let s=o.attributes,a=r.children,c=a.every(se),p=s.every(l=>!xe(l)),g=s.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let b=T(l);return!b?.startsWith("on")&&!b?.startsWith("bind:")});if(c&&p&&g){let l=ae(r);if(l){let b=_e(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(b),[])}}let u=ae(r);if(!u){let l=r.loc,b=n.filename||n.file?.opts?.filename||"<unknown>",y=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${b}${y}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,le(i,n)}let f=_e(n,u);n.needsTemplate=!0;let x=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier(f),[]))])];return ye(h,x,s,n,t),Se(h,x,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(x)}function le(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,c=[];for(let u of s){if(e.isJSXSpreadAttribute(u))continue;let f=T(u),x=_(u.value),h=D(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),x))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=H(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(U({node:u},n)):e.isJSXFragment(u)&&p.push(q({node:u},n));let g=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),g,...p])}let Je=new Set(["input","textarea","select","option"]);function ye(i,n,r,o,t){function s(p,g){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),g])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),g])):p==="value"&&t&&Je.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),g])):p==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),g])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),g])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),g]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let g=T(p);if(g!=="key"){if(g==="ref"){let u=_(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(g.startsWith("on")&&!g.includes("|")&&!w(g,o)){let u=g.slice(2).toLowerCase(),f=_(p.value);Qe.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(g.startsWith("on")&&(g.includes("|")||w(g,o))){let{eventName:u,modifiers:f}=E(g),x=_(p.value),h=Y(x,f),l=u.slice(2).toLowerCase(),b=f.filter(I=>Ze.has(I)),y=[e.stringLiteral(l),h];if(b.length>0){let I=b.map(M=>e.objectProperty(e.identifier(M),e.booleanLiteral(!0)));y.push(e.objectExpression(I))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),y)));continue}if(S(g)){let u=v(g),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=D(g);if(N(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let x=o.signalNames&&o.signalNames.fromDestructuredProps,h=e.isIdentifier(u)&&!(x&&x.has(u.name))&&(L(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],s(f,h))]);ge(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(s(f,u)))}}}}function ce(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(ce);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"&&ce(r))return!0}return!1}function Xe(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function G(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(!N(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(ce))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function Se(i,n,r,o,t){let s=[],a=0;for(let f of r){if(e.isJSXText(f)){H(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;s.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let x=f.openingElement.name.name;if(F(f)||x==="For"||x==="Show")s.push({type:"component",child:f,childIndex:a}),a++;else{let h=f.openingElement.attributes.some(xe)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&T(l)?.startsWith("on"))||!f.children.every(se);s.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:h}),a++}continue}e.isJSXFragment(f)&&s.push({type:"fragment",child:f})}let c=s.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,g=new Map;if(p){let f=null,x=0;for(let h of c){let l=h.childIndex,b=t.nextVarId();g.set(l,b);let y;if(f===null)y=fe(n,l);else{y=e.identifier(f);for(let I=x;I<l;I++)y=e.memberExpression(y,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(b),y)])),f=b,x=l}}function u(f){return g.has(f)?e.identifier(g.get(f)):fe(n,f)}for(let f of s){if(f.type==="expression"){let x=f.child.expression,h=u(f.childIndex);t.needsInsert=!0;let l=Ee(x,t);if(l){t.needsMapArray=!0;let y=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),I=e.isArrowFunctionExpression(l);I&&e.isExpression(l.body)?l.body=G(l.body,i,t):!y&&!I&&(l=G(l,i,t));let M=y||I?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,h])));continue}if(e.isCallExpression(x)&&e.isIdentifier(x.callee)&&(x.callee.name==="mapArray"||x.callee.name==="_$mapArray")){t.needsMapArray=!0,x.callee.name==="mapArray"&&(x.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(N(x,t.signalNames,t.importedIdentifiers)){x=G(x,i,t);let y=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],x),h]);ge(x,t.signalNames,t.importedIdentifiers)&&e.addComment(y,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(y))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="component"){let x=U({node:f.child},t),h=u(f.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let x;g.has(f.childIndex)?x=g.get(f.childIndex):(x=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),fe(n,f.childIndex))]))),ye(i,x,f.child.openingElement.attributes,t,f.child.openingElement.name.name),Se(i,x,f.child.children,f.child,t);continue}if(f.type==="fragment"){for(let x of f.child.children)if(e.isJSXExpressionContainer(x)&&!e.isJSXEmptyExpression(x.expression)){t.needsInsert=!0;let h=x.expression;N(h,t.signalNames,t.importedIdentifiers)?(h=G(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 fe(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 we(i,n){let{node:r}=i,o=r.openingElement,t=X(o.name),s=o.attributes,a=r.children,c=null,p=[];for(let b of s){if(e.isJSXAttribute(b)){let y;if(e.isJSXNamespacedName(b.name)?y=`${b.name.namespace.name}:${b.name.name.name}`:y=b.name.name,y&&typeof y=="string"&&y.startsWith("client:")){let I=y.slice(7);b.value?c={type:I,value:b.value.value}:c={type:I};continue}}p.push(b)}function g(){let b=n._pendingSetup?n._pendingSetup.length:0,y=[],I=!1;for(let A of a)if(e.isJSXText(A)){let P=H(A.value);P&&y.push(e.stringLiteral(P))}else if(e.isJSXExpressionContainer(A))e.isJSXEmptyExpression(A.expression)||(I=!0,y.push(A.expression));else if(e.isJSXElement(A)){let P=A.openingElement.name.name;P!=="For"&&P!=="Show"&&P!=="Switch"&&(I=!0),y.push(U({node:A},n))}else e.isJSXFragment(A)&&(I=!0,y.push(q({node:A},n)));let M=e.arrayExpression(y);if(I){let A=n._pendingSetup?n._pendingSetup.splice(b):[];M=e.arrowFunctionExpression([],A.length>0?e.blockStatement([...A,e.returnStatement(M)]):M)}return M}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let b=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&b.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let y=null;for(let M of p){if(e.isJSXSpreadAttribute(M)){y=M.argument;continue}let A=T(M);if(A==="key")continue;let P=_(M.value);b.push(e.objectProperty(e.identifier(A),P))}let I=y?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),y,e.objectExpression(b)]):e.objectExpression(b);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),I,g()])}n.needsCreateComponent=!0;let u=[],f=!1,x=null;for(let b of p){if(e.isJSXSpreadAttribute(b)){f=!0,x=b.argument;continue}let y=T(b);if(y==="key")continue;if(S(y)){let M=v(y),A=b.value.expression;M==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(A),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(A),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):M==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(A),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(A),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(y.startsWith("on")&&(y.includes("|")||w(y,n))){let{eventName:M,modifiers:A}=E(y),P=_(b.value),W=Y(P,A);u.push(e.objectProperty(e.identifier(M),W));continue}let I=_(b.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(y)?e.identifier(y):e.stringLiteral(y),I))}let h;f?u.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),x,e.objectExpression(u)]):h=x:u.length>0?h=e.objectExpression(u):h=e.nullLiteral();let l=g();return e.callExpression(e.identifier("_$createComponent"),[t,h,l])}function Re(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null,c=null;for(let P of o)if(e.isJSXAttribute(P)){let W=T(P);W==="each"?s=_(P.value):W==="key"?a=_(P.value):W==="fallback"&&(c=_(P.value))}if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,le(i,n);let p=null;for(let P of t)if(e.isJSXExpressionContainer(P)&&!e.isJSXEmptyExpression(P.expression)){p=P.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,le(i,n);n.needsMapArray=!0;let g=P=>{let W=[P,p];return a&&W.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),W)};if(!c)return g(s);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,x=`_for$${u}`,h=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let b=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),y=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),s)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(b,y)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(b),e.memberExpression(e.cloneNode(b),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),g(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let I=e.identifier("_parent"),M=e.identifier("_marker"),A=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([I,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(A,e.callExpression(e.identifier(x),[e.cloneNode(I),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(I),e.arrayExpression([e.identifier(h)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(A))])),e.identifier(x)])}function We(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 l=T(h);l==="when"?s=_(h.value):l==="fallback"&&(a=_(h.value))}if(!s)throw O(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){c=h.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let h=n._pendingSetup.length,l=[];for(let y of t)if(e.isJSXText(y)){let I=H(y.value);I&&l.push(e.stringLiteral(I))}else e.isJSXElement(y)&&l.push(U({node:y},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let b=n._pendingSetup.splice(h);b.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...b,e.returnStatement(c)])),[]))}let p=ve(s,n),g=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(g)]):c,x=a||e.nullLiteral();if(N(p,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(g,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(g),f,x))]))}function ve(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&L(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function He(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(U({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 Ve(i,n){let{node:r}=i,o=C(r.openingElement.name.name,n),t=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!C("Match",n));if(!r.children.some(t)&&!J(r.openingElement.name.name,n))return we(i,n);let s=l=>{throw O(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&s("cannot take a spread attribute"),T(l)==="fallback"&&(a=_(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){H(l.value)&&s("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s("cannot read its arms from an expression child")}t(l)||s("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&s("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let b=null;for(let A of l.openingElement.attributes)e.isJSXAttribute(A)&&T(A)==="when"&&(b=_(A.value));b||s('has a <Match> with no "when" prop');let y=n._pendingSetup.length,I=He(l.children,n),M=n._pendingSetup.splice(y);M.length>0&&(I=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(I)])),[])),p.push([ve(b,n),I])}let g=p.some(([l])=>N(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!g){let l=u;for(let b=p.length-1;b>=0;b--)l=e.conditionalExpression(p[b][0],p[b][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);let x=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))]));let h=u;for(let l=p.length-1;l>=0;l--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(x),[]),e.numericLiteral(l)),p[l][1],h);return e.arrowFunctionExpression([],h)}function Be(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=Ee(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=G(o.body,r,n),o;if(s)return o;let c=G(o,r,n);return e.arrowFunctionExpression([],c)}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):N(i,n.signalNames,n.importedIdentifiers)?(i=G(i,r,n),e.arrowFunctionExpression([],i)):i}function q(i,n){let{node:r}=i,o=r.children,t=[];for(let s of o)if(e.isJSXText(s)){let a=H(s.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||t.push(Be(s.expression,n)):e.isJSXElement(s)?t.push(U({node:s},n)):e.isJSXFragment(s)&&t.push(q({node:s},n));return t.length===1?t[0]:e.arrayExpression(t)}function _e(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 ke(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let s=t.get(o);s||(s=Q(i),t.set(o,s)),n.signalNames=s,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,g=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(g=!0),Xe(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!g&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ue(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 Ge(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 ze(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 s=i.node.loc?.start||{line:0,column:0},a=`${t}:${s.line}:${s.column+1}`,c=`${t}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let g={id:r,key:c,bindingName:o,filename:t,source:a,loc:s};if(n.serverActionIds.set(r,g),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(g)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function qe(i,n){if(!Ge(i,n))return;let r=Ue(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=ze(o);if(t.property){t.value!==null&&$e(i,n,t.value,r,n.serverActionFilename);return}let s=`wa1_${rn(`${n.serverActionFilename}#${r}`)}`;$e(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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=on(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/"),s=t||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((s||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),t?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),nn.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){R(r)},CallExpression(r){qe(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),Ce.has(s)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.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&&tn(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){ke(i,n,U)},JSXFragment(i,n){ke(i,n,q)}}}}function tn(e,m,d){let w=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){w=E;break}if(w){let E=new Set(w.specifiers.filter(S=>m.isImportSpecifier(S)).map(S=>S.imported.name));for(let S of d)E.has(S.imported.name)||w.specifiers.push(S)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import Z from"path";import{transformSync as En}from"@babel/core";import K from"fs";import B from"path";var Ie=new Set([".jsx",".tsx",".js",".ts"]),sn=new Set(["_layout","_error","_loading","_404"]);function Le(e){let m=[],d=[],w=[];function E(v,$=""){if(!K.existsSync(v))return;let O=K.readdirSync(v,{withFileTypes:!0});for(let F of O){let C=B.join(v,F.name);if(F.isDirectory()){if(F.name.match(/^\((.+)\)$/)){E(C,$);continue}if(F.name==="api"&&$===""){S(C,"/api");continue}E(C,$+"/"+re(F.name));continue}let J=B.extname(F.name);if(!Ie.has(J))continue;let j=B.basename(F.name,J);if(j==="_layout"){d.push({filePath:C,urlPrefix:$||"/"});continue}if(sn.has(j))continue;let X=re(j),R=j==="index"?$||"/":$+"/"+X;m.push({filePath:C,routePath:Ae(R),isDynamic:R.includes(":")||R.includes("*")})}}function S(v,$){if(!K.existsSync(v))return;let O=K.readdirSync(v,{withFileTypes:!0});for(let F of O){let C=B.join(v,F.name);if(F.isDirectory()){S(C,$+"/"+re(F.name));continue}let J=B.extname(F.name);if(!Ie.has(J))continue;let j=B.basename(F.name,J),X=re(j),R=j==="index"?$:$+"/"+X;w.push({filePath:C,routePath:Ae(R)})}}return E(e),m.sort((v,$)=>{let O=Fe(v.routePath),F=Fe($.routePath);return O-F}),{pages:m,layouts:d,apiRoutes:w}}function re(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function Ae(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Fe(e){return e.includes("*")?100:e.includes(":")?10:0}var an=/export\s+const\s+page\s*=\s*\{/;function Pe(e,m={}){let d=an.exec(e);if(!d)return{mode:"client"};let w=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(pn(e,w))}}catch(E){return ln(E,m.filePath),{mode:"client"}}}function ln(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
2
2
  This page falls back to mode 'client', so static generation will skip it.
3
- \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var fn=e=>/[A-Za-z_$]/.test(e),pn=e=>/[A-Za-z0-9_$]/.test(e);function un(e,m){let d=[],v=-1,E=0,w=m;for(;w<e.length;){let _=e[w];if(_==="/"&&e[w+1]==="/"){let k=e.indexOf(`
4
- `,w);w=k===-1?e.length:k,d.push(" ");continue}if(_==="/"&&e[w+1]==="*"){let k=e.indexOf("*/",w+2);if(k===-1)throw new SyntaxError("unterminated block comment");w=k+2,d.push(" ");continue}if(_==='"'||_==="'"||_==="`"){let k=mn(e,w);d.push(JSON.stringify(k.value)),v=-1,w=k.end;continue}if(fn(_)){let k=w+1;for(;k<e.length&&pn(e[k]);)k++;let j=e.slice(w,k);d.push(dn(e,k)?JSON.stringify(j):j),v=-1,w=k;continue}if(_===" "||_===" "||_===`
5
- `||_==="\r"){d.push(_),w++;continue}if(_===","){d.push(","),v=d.length-1,w++;continue}if(_==="}"||_==="]"){if(v!==-1&&(d[v]=""),v=-1,d.push(_),w++,_==="}"&&--E===0)return d.join("");continue}_==="{"&&E++,d.push(_),v=-1,w++}throw new SyntaxError("unterminated object literal")}function dn(e,m){let d=m;for(;d<e.length;){let v=e[d];if(v===" "||v===" "||v===`
6
- `||v==="\r"){d++;continue}if(v==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
- `,d);if(E===-1)return!1;d=E+1;continue}if(v==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return v===":"}return!1}var Le={n:`
8
- `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function mn(e,m){let d=e[m],v="",E=m+1;for(;E<e.length;){let w=e[E];if(w==="\\"){let _=e[E+1];if(_===void 0)break;if(_===`
9
- `){E+=2;continue}if(_==="\r"){E+=e[E+2]===`
10
- `?3:2;continue}if(_==="u"){if(e[E+2]==="{"){let k=e.indexOf("}",E+3);if(k===-1)throw new SyntaxError("invalid unicode escape");v+=String.fromCodePoint(parseInt(e.slice(E+3,k),16)),E=k+1;continue}v+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(_==="x"){v+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}v+=Object.prototype.hasOwnProperty.call(Le,_)?Le[_]:_,E+=2;continue}if(w===d)return{value:v,end:E+1};if(d==="`"&&w==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(w===`
11
- `||w==="\r"))break;v+=w,E++}throw new SyntaxError("unterminated string literal")}function hn(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 de(e,m){let{pages:d,layouts:v,apiRoutes:E}=Pe(e),w=[],_=[],k=new Map;v.forEach(($,J)=>{let P=`_layout${J}`,T=ue($.filePath,m);w.push(`import ${P} from '${T}';`),k.set($.urlPrefix,P)}),d.forEach(($,J)=>{let P=`_page${J}`,T=ue($.filePath,m);w.push(`import ${P} from '${T}';`);let X={mode:"client"},V={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let A=Y.readFileSync($.filePath,"utf-8");X=Ne(A,{filePath:$.filePath}),V=hn(A)}catch{}let b=gn($.routePath,k),I={path:$.routePath,component:P,mode:X.mode||"client",layout:b||null,hasLoader:V.hasLoader};_.push(I)});let j=[];return E.forEach(($,J)=>{let P=`_api${J}`,T=ue($.filePath,m);w.push(`import * as ${P} from '${T}';`),j.push({path:$.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...w,"","export const routes = [",..._.map($=>` { path: '${$.path}', component: ${$.component}, mode: '${$.mode}'${$.layout?`, layout: ${$.layout}`:""}${$.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...j.map($=>` { path: '${$.path}', handlers: ${$.handlers} },`),"];","","export const pageModes = {",..._.map($=>` '${$.path}': '${$.mode}',`),"};"].join(`
12
- `)}function ue(e,m){return"/"+G.relative(m,e).split(G.sep).join("/")}function gn(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let v="/"+d.join("/");if(m.has(v))return m.get(v);d.pop()}return m.has("/")?m.get("/"):null}var En=`
3
+ \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var cn=e=>/[A-Za-z_$]/.test(e),fn=e=>/[A-Za-z0-9_$]/.test(e);function pn(e,m){let d=[],w=-1,E=0,S=m;for(;S<e.length;){let v=e[S];if(v==="/"&&e[S+1]==="/"){let $=e.indexOf(`
4
+ `,S);S=$===-1?e.length:$,d.push(" ");continue}if(v==="/"&&e[S+1]==="*"){let $=e.indexOf("*/",S+2);if($===-1)throw new SyntaxError("unterminated block comment");S=$+2,d.push(" ");continue}if(v==='"'||v==="'"||v==="`"){let $=dn(e,S);d.push(JSON.stringify($.value)),w=-1,S=$.end;continue}if(cn(v)){let $=S+1;for(;$<e.length&&fn(e[$]);)$++;let O=e.slice(S,$);d.push(un(e,$)?JSON.stringify(O):O),w=-1,S=$;continue}if(v===" "||v===" "||v===`
5
+ `||v==="\r"){d.push(v),S++;continue}if(v===","){d.push(","),w=d.length-1,S++;continue}if(v==="}"||v==="]"){if(w!==-1&&(d[w]=""),w=-1,d.push(v),S++,v==="}"&&--E===0)return d.join("");continue}v==="{"&&E++,d.push(v),w=-1,S++}throw new SyntaxError("unterminated object literal")}function un(e,m){let d=m;for(;d<e.length;){let w=e[d];if(w===" "||w===" "||w===`
6
+ `||w==="\r"){d++;continue}if(w==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
+ `,d);if(E===-1)return!1;d=E+1;continue}if(w==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return w===":"}return!1}var Me={n:`
8
+ `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function dn(e,m){let d=e[m],w="",E=m+1;for(;E<e.length;){let S=e[E];if(S==="\\"){let v=e[E+1];if(v===void 0)break;if(v===`
9
+ `){E+=2;continue}if(v==="\r"){E+=e[E+2]===`
10
+ `?3:2;continue}if(v==="u"){if(e[E+2]==="{"){let $=e.indexOf("}",E+3);if($===-1)throw new SyntaxError("invalid unicode escape");w+=String.fromCodePoint(parseInt(e.slice(E+3,$),16)),E=$+1;continue}w+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(v==="x"){w+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}w+=Object.prototype.hasOwnProperty.call(Me,v)?Me[v]:v,E+=2;continue}if(S===d)return{value:w,end:E+1};if(d==="`"&&S==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(S===`
11
+ `||S==="\r"))break;w+=S,E++}throw new SyntaxError("unterminated string literal")}function mn(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 ue(e,m){let{pages:d,layouts:w,apiRoutes:E}=Le(e),S=[],v=[],$=new Map;w.forEach((C,J)=>{let j=`_layout${J}`,X=pe(C.filePath,m);S.push(`import ${j} from '${X}';`),$.set(C.urlPrefix,j)}),d.forEach((C,J)=>{let j=`_page${J}`,X=pe(C.filePath,m);S.push(`import ${j} from '${X}';`);let R={mode:"client"},k={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let T=K.readFileSync(C.filePath,"utf-8");R=Pe(T,{filePath:C.filePath}),k=mn(T)}catch{}let _=hn(C.routePath,$),D={path:C.routePath,component:j,mode:R.mode||"client",layout:_||null,hasLoader:k.hasLoader};v.push(D)});let O=[];return E.forEach((C,J)=>{let j=`_api${J}`,X=pe(C.filePath,m);S.push(`import * as ${j} from '${X}';`),O.push({path:C.routePath,handlers:j})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...S,"","export const routes = [",...v.map(C=>` { path: '${C.path}', component: ${C.component}, mode: '${C.mode}'${C.layout?`, layout: ${C.layout}`:""}${C.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...O.map(C=>` { path: '${C.path}', handlers: ${C.handlers} },`),"];","","export const pageModes = {",...v.map(C=>` '${C.path}': '${C.mode}',`),"};"].join(`
12
+ `)}function pe(e,m){return"/"+B.relative(m,e).split(B.sep).join("/")}function hn(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let w="/"+d.join("/");if(m.has(w))return m.get(w);d.pop()}return m.has("/")?m.get("/"):null}var gn=`
13
13
  :host {
14
14
  position: fixed;
15
15
  inset: 0;
@@ -195,12 +195,12 @@ var Ze=new Set(["preventDefault","stopPropagation","once","capture","passive","s
195
195
  white-space: pre-wrap;
196
196
  line-height: 1.5;
197
197
  }
198
- `,Pn=`
198
+ `,Ln=`
199
199
  class WhatErrorOverlay extends HTMLElement {
200
200
  constructor(err) {
201
201
  super();
202
202
  this.root = this.attachShadow({ mode: 'open' });
203
- this.root.innerHTML = '<style>${En}</style>';
203
+ this.root.innerHTML = '<style>${gn}</style>';
204
204
  this._err = err;
205
205
  this.show(err);
206
206
  }
@@ -390,7 +390,7 @@ class WhatErrorOverlay extends HTMLElement {
390
390
  if (!customElements.get('what-error-overlay')) {
391
391
  customElements.define('what-error-overlay', WhatErrorOverlay);
392
392
  }
393
- `;function Oe(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(d){return d?.type==="error"&&d.err?.plugin==="vite-plugin-what"&&(d.err._isCompilerError=!0),m(d)}}var je="virtual:what-routes",oe="\0"+je,bn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,yn=/\.[cm]?[jt]sx?$/;function he(e,m){return e?Array.isArray(e)?e.some(d=>he(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function Sn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var me=null;function wn(){return me||(me=import("vite").then(e=>e.version||"").catch(()=>"")),me}var vn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,_n=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function ge(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:v=!0,production:E=!0,pages:w="src/pages",hot:_=!E,prodBundles:k=!0}=e,j="",M="",$=null,J=!1,P=new Map;function T(b){let I=P.get(b.id);if(I&&I.key!==b.key)throw new Error(`Duplicate server action ID "${b.id}". First declared by "${I.bindingName}" at ${I.source}; conflicts with "${b.bindingName}" at ${b.source}.`);P.set(b.id,b)}function X(b){for(let[I,A]of P)A.filename===b&&P.delete(I)}function V(b){let I=b.replace(/[?#].*$/,"");return j?Q.relative(j,I).split(Q.sep).join("/"):I}return{name:"vite-plugin-what",configResolved(b){j=b.root,M=Q.resolve(j,w),J=b.command==="serve"},configureServer(b){$=b,Oe(b),b.watcher.on("add",I=>{if(I.startsWith(M)){let A=b.moduleGraph.getModuleById(oe);A&&(b.moduleGraph.invalidateModule(A),b.ws.send({type:"full-reload"}))}}),b.watcher.on("unlink",I=>{if(X(V(I)),I.startsWith(M)){let A=b.moduleGraph.getModuleById(oe);A&&(b.moduleGraph.invalidateModule(A),b.ws.send({type:"full-reload"}))}})},resolveId(b){if(b===je)return oe},load(b){if(b===oe)return de(M,j)},transform(b,I){let A=I.replace(/[?#].*$/,""),K=he(m,A),U=yn.test(A),R=U&&bn.test(b);if(d&&he(d,A)||(U&&X(V(A)),!K&&!R))return null;try{let D=xn(b,{filename:I,sourceMaps:v,configFile:!1,babelrc:!1,plugins:[[ie,{production:E,projectRoot:j||process.cwd(),onActionId:T}]],parserOpts:{plugins:["jsx","typescript"]}});if(!D||!D.code)return null;let te=D.code;return _&&J&&!E&&kn(b,I)&&(te+=Cn(I)),{code:te,map:D.map}}catch(D){throw D.plugin="vite-plugin-what",D.id||(D.id=I),D.loc===void 0&&D._loc&&(D.loc={file:I,line:D._loc.line,column:D._loc.column}),console.error(`[what] Error transforming ${I}:`,D.message),D}},handleHotUpdate({file:b,server:I,modules:A}){if(_&&m.test(b)&&!(d&&d.test(b))&&$n(b))return I.ws.send({type:"full-reload"}),[]},async config(b,{mode:I,command:A}){let K=A==="build"&&I==="production"&&k,U=Sn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await wn()});return{...K?{resolve:{conditions:["production"]}}:{},...U,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function kn(e,m){return!!(vn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function $n(e){let m=Q.basename(e,Q.extname(e));return _n.test(m)}function Cn(e){return`
393
+ `;function Ne(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(d){return d?.type==="error"&&d.err?.plugin==="vite-plugin-what"&&(d.err._isCompilerError=!0),m(d)}}var Oe="virtual:what-routes",oe="\0"+Oe,xn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,bn=/\.[cm]?[jt]sx?$/;function me(e,m){return e?Array.isArray(e)?e.some(d=>me(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function yn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var de=null;function Sn(){return de||(de=import("vite").then(e=>e.version||"").catch(()=>"")),de}var wn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,vn=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function he(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:w=!0,production:E=!0,pages:S="src/pages",hot:v=!E,prodBundles:$=!0}=e,O="",F="",C=!1,J=new Map;function j(k){let _=J.get(k.id);if(_&&_.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${_.bindingName}" at ${_.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});J.set(k.id,k)}function X(k){for(let[_,D]of J)D.filename===k&&J.delete(_)}function R(k){let _=k.replace(/[?#].*$/,"");return O?Z.relative(O,_).split(Z.sep).join("/"):_}return{name:"vite-plugin-what",configResolved(k){O=k.root,F=Z.resolve(O,S),C=k.command==="serve"},configureServer(k){Ne(k),k.watcher.on("add",_=>{if(_.startsWith(F)){let D=k.moduleGraph.getModuleById(oe);D&&(k.moduleGraph.invalidateModule(D),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",_=>{if(X(R(_)),_.startsWith(F)){let D=k.moduleGraph.getModuleById(oe);D&&(k.moduleGraph.invalidateModule(D),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===Oe)return oe},load(k){if(k===oe)return ue(F,O)},transform(k,_){let D=_.replace(/[?#].*$/,""),T=me(m,D),z=bn.test(D),Y=z&&xn.test(k);if(d&&me(d,D)||(z&&X(R(D)),!T&&!Y))return null;try{let L=En(k,{filename:_,sourceMaps:w,configFile:!1,babelrc:!1,plugins:[[ie,{production:E,projectRoot:O||process.cwd(),onActionId:j}]],parserOpts:{plugins:["jsx","typescript"]}});if(!L||!L.code)return null;let Q=L.code;return v&&C&&!E&&_n(k,_)&&(Q+=$n(_)),{code:Q,map:L.map}}catch(L){throw L.plugin="vite-plugin-what",L.id||(L.id=_),L.loc===void 0&&L._loc&&(L.loc={file:_,line:L._loc.line,column:L._loc.column}),console.error(`[what] Error transforming ${_}:`,L.message),L}},handleHotUpdate({file:k,server:_}){if(v&&m.test(k)&&!(d&&d.test(k))&&kn(k))return _.ws.send({type:"full-reload"}),[]},async config(k,{mode:_,command:D}){let T=D==="build"&&_==="production"&&$,z=yn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Sn()});return{...T?{resolve:{conditions:["production"]}}:{},...z,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function _n(e,m){return!!(wn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function kn(e){let m=Z.basename(e,Z.extname(e));return vn.test(m)}function $n(e){return`
394
394
 
395
395
  // --- What Framework HMR Boundary ---
396
396
  if (import.meta.hot) {
@@ -403,4 +403,4 @@ if (import.meta.hot) {
403
403
  }
404
404
  });
405
405
  }
406
- `}import{h as Vn,Fragment as Bn,mount as Gn,Island as Un}from"what-core";export{Bn as Fragment,Un as Island,ie as babelPlugin,Ne as extractPageConfig,de as generateRoutesModule,Vn as h,Gn as mount,Pe as scanPages,ge as vitePlugin,ge as what};
406
+ `}import{h as Wn,Fragment as Hn,mount as Vn,Island as Bn}from"what-core";export{Hn as Fragment,Bn as Island,ie as babelPlugin,Pe as extractPageConfig,ue as generateRoutesModule,Wn as h,Vn as mount,Le as scanPages,he as vitePlugin,he as what};
@@ -1,15 +1,15 @@
1
- import Q from"path";import{transformSync as En}from"@babel/core";var ze=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),qe=new Set(["once","capture","passive"]),Ke=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ze=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),ne=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"]),Ye=new Set(["For","Show","Switch","Match"]),Qe=new Set(["what-framework/server","what-server","what-server/actions"]);function en(e){let m=0xcbf29ce484222325n;for(let d=0;d<e.length;d++)m^=BigInt(e.charCodeAt(d)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function nn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),v=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return v&&d.startsWith(`${v}/`)?d.slice(v.length+1):d.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),d=-1;for(let E=0;E<m.length;E++)/[^ \t]/.test(m[E])&&(d=E);if(d===-1)return"";let v="";for(let E=0;E<m.length;E++){let w=m[E].replace(/\t/g," "),_=E===0,k=E===m.length-1;_||(w=w.replace(/^ +/,"")),k||(w=w.replace(/ +$/,"")),w&&(E!==d&&(w+=" "),v+=w)}return v}function pe({types:e}){let m=new Set,d=new Set;function v(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(s=>ze.has(s));return{eventName:o,modifiers:t}}function w(i){return i.startsWith("bind:")}function _(i){return i.slice(5)}function k(i){return/^[A-Z]/.test(i)}function j(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let t=o?.loc?.start,s=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${t?`${s}:${t.line}:${t.column+1}`:s})`)}function M(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&k(n.name)}function $(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function J(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function P(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function T(i){return e.isJSXMemberExpression(i)?e.memberExpression(T(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function X(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let g=r.properties[p];if(e.isRestElement(g))return;if(e.isObjectProperty(g)&&!g.computed&&e.isIdentifier(g.key,{name:"children"})){if(o!==-1||!e.isIdentifier(g.value))return;o=p}}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(p=>{let g=p.parentPath;if(!g||!g.isJSXExpressionContainer())return!1;let u=g.parentPath;if(!u||!u.isJSXElement()||!M(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&Ye.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,g)=>g!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of t.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function V(i){return Ke.has(String(i).toLowerCase())}function b(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function I(i){return i==="className"?"class":i==="htmlFor"?"for":i}function A(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 K(i){return!!i&&i.length>2&&/^on/i.test(i)}function U(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 D(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,g="";if(e.isIdentifier(p)?g=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(g=p.property.name),$e.has(g)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function t(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let s=i.scope;for(;s;){for(let c of Object.values(s.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=s.path&&s.path.node;if(a){if(a.params)for(let c of a.params)t(c);a._whatMovedProps&&t(a._whatMovedProps)}s=s.parent}return n}function oe(i){return D(i)}function te(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ne.has(n.object.name):e.isIdentifier(n)?ne.has(n.name):!1}function he(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)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)||te(i))return!1;if(i.arguments.some(o=>O(o,n,r)))return!0}return!1}function O(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)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&R(i.callee.object.name,n)?!0:te(i)?i.arguments.some(o=>O(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>O(o,n,r)):O(i.callee,n,r)||i.arguments.some(o=>O(o,n,r)):e.isIdentifier(i)?R(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?O(i.object,n,r):e.isConditionalExpression(i)?O(i.test,n,r)||O(i.consequent,n,r)||O(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?O(i.left,n,r)||O(i.right,n,r):e.isUnaryExpression(i)?O(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>O(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&O(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&O(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function B(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":B(i.left,n);break;case"RestElement":B(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)B(r,n);break;case"ObjectPattern":for(let r of i.properties)B(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function Ne(i){let n=new Set;for(let o=1;o<i.params.length;o++)B(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let t of o.declarations)B(t.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":B(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let t of Object.keys(o)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments")continue;let s=o[t];s&&typeof s=="object"&&r(s)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of B(i.params[0],new Set))n.delete(o);return n}function Oe(i,n){if(n.size===0)return null;let r=null,o=t=>{if(!(r||!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(o);return}if(t.type==="Identifier"){n.has(t.name)&&(r=t.name);return}for(let s of Object.keys(t)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments"||t.type==="MemberExpression"&&s==="property"&&!t.computed||(t.type==="ObjectProperty"||t.type==="ObjectMethod")&&s==="key"&&!t.computed)continue;let a=t[s];a&&typeof a=="object"&&o(a)}}};return o(i),r}function ge(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=ee(r.consequent,n),a=ee(r.alternate,n);if(s||a){let c=e.conditionalExpression(r.test,s||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let s=ee(r.right,n);if(s){let a=e.logicalExpression(r.operator,r.left,s);return o?e.arrowFunctionExpression([],a):a}return null}return ee(r,n)}function ee(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 h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}}else if(e.isFunctionExpression(r)){let h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,s=null;for(let h of t)if(e.isJSXAttribute(h)&&A(h)==="key"){s=h;break}if(!s)return null;let a=b(s.value);if(!a)return null;let c=Ne(r);if(Oe(a,c)){let h=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=t.filter(h=>h!==s);let g=i.callee.object,u=e.arrowFunctionExpression([],g),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),x=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),x),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 Ee(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function ae(i){if(e.isJSXText(i)){let s=H(i.value);return s?xe(s):""}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 s of n.attributes){if(e.isJSXSpreadAttribute(s))continue;let a=A(s);if(a==="key"||K(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!s.value)o+=` ${c}`;else if(e.isStringLiteral(s.value))o+=` ${c}="${je(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let t=i.openingElement.selfClosing;if(t&&V(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let s of i.children)if(e.isJSXText(s)){let a=H(s.value);a&&(o+=xe(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(o+="<!--$-->"):e.isJSXElement(s)&&(M(s)?o+="<!--$-->":o+=ae(s));return o+=`</${r}>`,o}function xe(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function je(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function z(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!$(t,n)){if(t==="For")return Te(i,n);if(t==="Show")return Xe(i,n)}if(t==="Switch"&&(!$(t,n)||P(r)))return We(i,n);if(M(r))return Se(i,n);let s=o.attributes,a=r.children,c=a.every(se),p=s.every(l=>!Ee(l)),g=s.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let y=A(l);return!y?.startsWith("on")&&!y?.startsWith("bind:")});if(c&&p&&g){let l=ae(r);if(l){let y=ve(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(y),[])}}let u=ae(r);if(!u){let l=r.loc,y=n.filename||n.file?.opts?.filename||"<unknown>",S=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${y}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,le(i,n)}let f=ve(n,u);n.needsTemplate=!0;let x=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier(f),[]))])];return be(h,x,s,n,t),ye(h,x,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(x)}function le(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,c=[];for(let u of s){if(e.isJSXSpreadAttribute(u))continue;let f=A(u),x=b(u.value),h=I(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),x))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=H(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(z({node:u},n)):e.isJSXFragment(u)&&p.push(Z({node:u},n));let g=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),g,...p])}let De=new Set(["input","textarea","select","option"]);function be(i,n,r,o,t){function s(p,g){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),g])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),g])):p==="value"&&t&&De.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),g])):p==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),g])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),g])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),g]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let g=A(p);if(g!=="key"){if(g==="ref"){let u=b(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(g.startsWith("on")&&!g.includes("|")&&!v(g,o)){let u=g.slice(2).toLowerCase(),f=b(p.value);Ze.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(g.startsWith("on")&&(g.includes("|")||v(g,o))){let{eventName:u,modifiers:f}=E(g),x=b(p.value),h=U(x,f),l=u.slice(2).toLowerCase(),y=f.filter(C=>qe.has(C)),S=[e.stringLiteral(l),h];if(y.length>0){let C=y.map(L=>e.objectProperty(e.identifier(L),e.booleanLiteral(!0)));S.push(e.objectExpression(C))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),S)));continue}if(w(g)){let u=_(g),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=I(g);if(O(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let x=o.signalNames&&o.signalNames.fromDestructuredProps,h=e.isIdentifier(u)&&!(x&&x.has(u.name))&&(R(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],s(f,h))]);he(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(s(f,u)))}}}}function ce(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(ce);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"&&ce(r))return!0}return!1}function Je(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function q(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(!O(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(ce))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function ye(i,n,r,o,t){let s=[],a=0;for(let f of r){if(e.isJSXText(f)){H(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;s.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let x=f.openingElement.name.name;if(M(f)||x==="For"||x==="Show")s.push({type:"component",child:f,childIndex:a}),a++;else{let h=f.openingElement.attributes.some(Ee)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&A(l)?.startsWith("on"))||!f.children.every(se);s.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:h}),a++}continue}e.isJSXFragment(f)&&s.push({type:"fragment",child:f})}let c=s.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,g=new Map;if(p){let f=null,x=0;for(let h of c){let l=h.childIndex,y=t.nextVarId();g.set(l,y);let S;if(f===null)S=fe(n,l);else{S=e.identifier(f);for(let C=x;C<l;C++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(y),S)])),f=y,x=l}}function u(f){return g.has(f)?e.identifier(g.get(f)):fe(n,f)}for(let f of s){if(f.type==="expression"){let x=f.child.expression,h=u(f.childIndex);t.needsInsert=!0;let l=ge(x,t);if(l){t.needsMapArray=!0;let S=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),C=e.isArrowFunctionExpression(l);C&&e.isExpression(l.body)?l.body=q(l.body,i,t):!S&&!C&&(l=q(l,i,t));let L=S||C?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),L,h])));continue}if(e.isCallExpression(x)&&e.isIdentifier(x.callee)&&(x.callee.name==="mapArray"||x.callee.name==="_$mapArray")){t.needsMapArray=!0,x.callee.name==="mapArray"&&(x.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(O(x,t.signalNames,t.importedIdentifiers)){x=q(x,i,t);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],x),h]);he(x,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(S))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="component"){let x=z({node:f.child},t),h=u(f.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let x;g.has(f.childIndex)?x=g.get(f.childIndex):(x=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),fe(n,f.childIndex))]))),be(i,x,f.child.openingElement.attributes,t,f.child.openingElement.name.name),ye(i,x,f.child.children,f.child,t);continue}if(f.type==="fragment"){for(let x of f.child.children)if(e.isJSXExpressionContainer(x)&&!e.isJSXEmptyExpression(x.expression)){t.needsInsert=!0;let h=x.expression;O(h,t.signalNames,t.importedIdentifiers)?(h=q(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 fe(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 Se(i,n){let{node:r}=i,o=r.openingElement,t=T(o.name),s=o.attributes,a=r.children,c=null,p=[];for(let y of s){if(e.isJSXAttribute(y)){let S;if(e.isJSXNamespacedName(y.name)?S=`${y.name.namespace.name}:${y.name.name.name}`:S=y.name.name,S&&typeof S=="string"&&S.startsWith("client:")){let C=S.slice(7);y.value?c={type:C,value:y.value.value}:c={type:C};continue}}p.push(y)}function g(){let y=n._pendingSetup?n._pendingSetup.length:0,S=[],C=!1;for(let F of a)if(e.isJSXText(F)){let N=H(F.value);N&&S.push(e.stringLiteral(N))}else if(e.isJSXExpressionContainer(F))e.isJSXEmptyExpression(F.expression)||(C=!0,S.push(F.expression));else if(e.isJSXElement(F)){let N=F.openingElement.name.name;N!=="For"&&N!=="Show"&&N!=="Switch"&&(C=!0),S.push(z({node:F},n))}else e.isJSXFragment(F)&&(C=!0,S.push(Z({node:F},n)));let L=e.arrayExpression(S);if(C){let F=n._pendingSetup?n._pendingSetup.splice(y):[];L=e.arrowFunctionExpression([],F.length>0?e.blockStatement([...F,e.returnStatement(L)]):L)}return L}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let y=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&y.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let S=null;for(let L of p){if(e.isJSXSpreadAttribute(L)){S=L.argument;continue}let F=A(L);if(F==="key")continue;let N=b(L.value);y.push(e.objectProperty(e.identifier(F),N))}let C=S?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),S,e.objectExpression(y)]):e.objectExpression(y);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),C,g()])}n.needsCreateComponent=!0;let u=[],f=!1,x=null;for(let y of p){if(e.isJSXSpreadAttribute(y)){f=!0,x=y.argument;continue}let S=A(y);if(S==="key")continue;if(w(S)){let L=_(S),F=y.value.expression;L==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(F),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(F),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):L==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(F),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(F),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(S.startsWith("on")&&(S.includes("|")||v(S,n))){let{eventName:L,modifiers:F}=E(S),N=b(y.value),W=U(N,F);u.push(e.objectProperty(e.identifier(L),W));continue}let C=b(y.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(S)?e.identifier(S):e.stringLiteral(S),C))}let h;f?u.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),x,e.objectExpression(u)]):h=x:u.length>0?h=e.objectExpression(u):h=e.nullLiteral();let l=g();return e.callExpression(e.identifier("_$createComponent"),[t,h,l])}function Te(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null,c=null;for(let N of o)if(e.isJSXAttribute(N)){let W=A(N);W==="each"?s=b(N.value):W==="key"?a=b(N.value):W==="fallback"&&(c=b(N.value))}if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,le(i,n);let p=null;for(let N of t)if(e.isJSXExpressionContainer(N)&&!e.isJSXEmptyExpression(N.expression)){p=N.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,le(i,n);n.needsMapArray=!0;let g=N=>{let W=[N,p];return a&&W.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),W)};if(!c)return g(s);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,x=`_for$${u}`,h=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let y=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),s)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(y,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(y),e.memberExpression(e.cloneNode(y),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),g(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let C=e.identifier("_parent"),L=e.identifier("_marker"),F=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([C,L],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(F,e.callExpression(e.identifier(x),[e.cloneNode(C),e.cloneNode(L)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(C),e.arrayExpression([e.identifier(h)]),e.cloneNode(L)])),e.returnStatement(e.cloneNode(F))])),e.identifier(x)])}function Xe(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 l=A(h);l==="when"?s=b(h.value):l==="fallback"&&(a=b(h.value))}if(!s)throw j(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){c=h.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let h=n._pendingSetup.length,l=[];for(let S of t)if(e.isJSXText(S)){let C=H(S.value);C&&l.push(e.stringLiteral(C))}else e.isJSXElement(S)&&l.push(z({node:S},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let y=n._pendingSetup.splice(h);y.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...y,e.returnStatement(c)])),[]))}let p=we(s,n),g=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(g)]):c,x=a||e.nullLiteral();if(O(p,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(g,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(g),f,x))]))}function we(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 Re(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(z({node:o},n)):e.isJSXFragment(o)&&r.push(Z({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function We(i,n){let{node:r}=i,o=$(r.openingElement.name.name,n),t=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!$("Match",n));if(!r.children.some(t)&&!J(r.openingElement.name.name,n))return Se(i,n);let s=l=>{throw j(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&s("cannot take a spread attribute"),A(l)==="fallback"&&(a=b(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){H(l.value)&&s("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s("cannot read its arms from an expression child")}t(l)||s("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&s("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let y=null;for(let F of l.openingElement.attributes)e.isJSXAttribute(F)&&A(F)==="when"&&(y=b(F.value));y||s('has a <Match> with no "when" prop');let S=n._pendingSetup.length,C=Re(l.children,n),L=n._pendingSetup.splice(S);L.length>0&&(C=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...L,e.returnStatement(C)])),[])),p.push([we(y,n),C])}let g=p.some(([l])=>O(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!g){let l=u;for(let y=p.length-1;y>=0;y--)l=e.conditionalExpression(p[y][0],p[y][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);let x=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))]));let h=u;for(let l=p.length-1;l>=0;l--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(x),[]),e.numericLiteral(l)),p[l][1],h);return e.arrowFunctionExpression([],h)}function He(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=ge(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=q(o.body,r,n),o;if(s)return o;let c=q(o,r,n);return e.arrowFunctionExpression([],c)}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):O(i,n.signalNames,n.importedIdentifiers)?(i=q(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=H(s.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||t.push(He(s.expression,n)):e.isJSXElement(s)?t.push(z({node:s},n)):e.isJSXFragment(s)&&t.push(Z({node:s},n));return t.length===1?t[0]:e.arrayExpression(t)}function ve(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 _e(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let s=t.get(o);s||(s=D(i),t.set(o,s)),n.signalNames=s,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,g=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(g=!0),Je(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!g&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ve(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 Be(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 Ge(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 ke(i,n,r,o,t){let s=i.node.loc?.start||{line:0,column:0},a=`${t}:${s.line}:${s.column+1}`,c=`${t}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let g={id:r,key:c,bindingName:o,filename:t,source:a,loc:s};if(n.serverActionIds.set(r,g),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(g)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Ue(i,n){if(!Be(i,n))return;let r=Ve(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=Ge(o);if(t.property){t.value!==null&&ke(i,n,t.value,r,n.serverActionFilename);return}let s=`wa1_${en(`${n.serverActionFilename}#${r}`)}`;ke(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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=nn(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/"),s=t||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((s||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),t?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),Qe.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){X(r)},CallExpression(r){Ue(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),$e.has(s)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.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&&rn(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){_e(i,n,z)},JSXFragment(i,n){_e(i,n,Z)}}}}function rn(e,m,d){let v=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){v=E;break}if(v){let E=new Set(v.specifiers.filter(w=>m.isImportSpecifier(w)).map(w=>w.imported.name));for(let w of d)E.has(w.imported.name)||v.specifiers.push(w)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import Y from"fs";import G from"path";var Ce=new Set([".jsx",".tsx",".js",".ts"]),on=new Set(["_layout","_error","_loading","_404"]);function tn(e){let m=[],d=[],v=[];function E(_,k=""){if(!Y.existsSync(_))return;let j=Y.readdirSync(_,{withFileTypes:!0});for(let M of j){let $=G.join(_,M.name);if(M.isDirectory()){if(M.name.match(/^\((.+)\)$/)){E($,k);continue}if(M.name==="api"&&k===""){w($,"/api");continue}E($,k+"/"+ie(M.name));continue}let J=G.extname(M.name);if(!Ce.has(J))continue;let P=G.basename(M.name,J);if(P==="_layout"){d.push({filePath:$,urlPrefix:k||"/"});continue}if(on.has(P))continue;let T=ie(P),X=P==="index"?k||"/":k+"/"+T;m.push({filePath:$,routePath:Ie(X),isDynamic:X.includes(":")||X.includes("*")})}}function w(_,k){if(!Y.existsSync(_))return;let j=Y.readdirSync(_,{withFileTypes:!0});for(let M of j){let $=G.join(_,M.name);if(M.isDirectory()){w($,k+"/"+ie(M.name));continue}let J=G.extname(M.name);if(!Ce.has(J))continue;let P=G.basename(M.name,J),T=ie(P),X=P==="index"?k:k+"/"+T;v.push({filePath:$,routePath:Ie(X)})}}return E(e),m.sort((_,k)=>{let j=Ae(_.routePath),M=Ae(k.routePath);return j-M}),{pages:m,layouts:d,apiRoutes:v}}function ie(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function Ie(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}var sn=/export\s+const\s+page\s*=\s*\{/;function an(e,m={}){let d=sn.exec(e);if(!d)return{mode:"client"};let v=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(pn(e,v))}}catch(E){return ln(E,m.filePath),{mode:"client"}}}function ln(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
1
+ import Z from"path";import{transformSync as gn}from"@babel/core";var Ge=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),ze=new Set(["once","capture","passive"]),qe=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"]),ne=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),ke=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),Ze=new Set(["For","Show","Switch","Match"]),Ye=new Set(["what-framework/server","what-server","what-server/actions"]);function Qe(e){let m=0xcbf29ce484222325n;for(let d=0;d<e.length;d++)m^=BigInt(e.charCodeAt(d)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function en(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),w=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return w&&d.startsWith(`${w}/`)?d.slice(w.length+1):d.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),d=-1;for(let E=0;E<m.length;E++)/[^ \t]/.test(m[E])&&(d=E);if(d===-1)return"";let w="";for(let E=0;E<m.length;E++){let S=m[E].replace(/\t/g," "),v=E===0,$=E===m.length-1;v||(S=S.replace(/^ +/,"")),$||(S=S.replace(/ +$/,"")),S&&(E!==d&&(S+=" "),w+=S)}return w}function fe({types:e}){let m=new Set,d=new Set;function w(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(s=>Ge.has(s));return{eventName:o,modifiers:t}}function S(i){return i.startsWith("bind:")}function v(i){return i.slice(5)}function $(i){return/^[A-Z]/.test(i)}function O(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let t=o?.loc?.start,s=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${t?`${s}:${t.line}:${t.column+1}`:s})`)}function F(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&$(n.name)}function C(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function J(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function j(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function X(i){return e.isJSXMemberExpression(i)?e.memberExpression(X(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function R(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let g=r.properties[p];if(e.isRestElement(g))return;if(e.isObjectProperty(g)&&!g.computed&&e.isIdentifier(g.key,{name:"children"})){if(o!==-1||!e.isIdentifier(g.value))return;o=p}}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(p=>{let g=p.parentPath;if(!g||!g.isJSXExpressionContainer())return!1;let u=g.parentPath;if(!u||!u.isJSXElement()||!F(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&Ze.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,g)=>g!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of t.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function k(i){return qe.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 D(i){return i==="className"?"class":i==="htmlFor"?"for":i}function T(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 z(i){return!!i&&i.length>2&&/^on/i.test(i)}function Y(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 L(i,n){return n.has(i)}function Q(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,g="";if(e.isIdentifier(p)?g=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(g=p.property.name),ke.has(g)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function t(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let s=i.scope;for(;s;){for(let c of Object.values(s.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=s.path&&s.path.node;if(a){if(a.params)for(let c of a.params)t(c);a._whatMovedProps&&t(a._whatMovedProps)}s=s.parent}return n}function oe(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ne.has(n.object.name):e.isIdentifier(n)?ne.has(n.name):!1}function me(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&L(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&L(i.callee.object.name,n)||oe(i))return!1;if(i.arguments.some(o=>N(o,n,r)))return!0}return!1}function N(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&L(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&L(i.callee.object.name,n)?!0:oe(i)?i.arguments.some(o=>N(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>N(o,n,r)):N(i.callee,n,r)||i.arguments.some(o=>N(o,n,r)):e.isIdentifier(i)?L(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?N(i.object,n,r):e.isConditionalExpression(i)?N(i.test,n,r)||N(i.consequent,n,r)||N(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?N(i.left,n,r)||N(i.right,n,r):e.isUnaryExpression(i)?N(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>N(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&N(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&N(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function V(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":V(i.left,n);break;case"RestElement":V(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)V(r,n);break;case"ObjectPattern":for(let r of i.properties)V(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function Pe(i){let n=new Set;for(let o=1;o<i.params.length;o++)V(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let t of o.declarations)V(t.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":V(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let t of Object.keys(o)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments")continue;let s=o[t];s&&typeof s=="object"&&r(s)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of V(i.params[0],new Set))n.delete(o);return n}function Ne(i,n){if(n.size===0)return null;let r=null,o=t=>{if(!(r||!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(o);return}if(t.type==="Identifier"){n.has(t.name)&&(r=t.name);return}for(let s of Object.keys(t)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments"||t.type==="MemberExpression"&&s==="property"&&!t.computed||(t.type==="ObjectProperty"||t.type==="ObjectMethod")&&s==="key"&&!t.computed)continue;let a=t[s];a&&typeof a=="object"&&o(a)}}};return o(i),r}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 s=ee(r.consequent,n),a=ee(r.alternate,n);if(s||a){let c=e.conditionalExpression(r.test,s||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let s=ee(r.right,n);if(s){let a=e.logicalExpression(r.operator,r.left,s);return o?e.arrowFunctionExpression([],a):a}return null}return ee(r,n)}function ee(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 h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}}else if(e.isFunctionExpression(r)){let h=r.body.body.find(l=>e.isReturnStatement(l));h&&(o=h.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,s=null;for(let h of t)if(e.isJSXAttribute(h)&&T(h)==="key"){s=h;break}if(!s)return null;let a=_(s.value);if(!a)return null;let c=Pe(r);if(Ne(a,c)){let h=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=t.filter(h=>h!==s);let g=i.callee.object,u=e.arrowFunctionExpression([],g),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),x=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),x),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function te(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(F(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(te)}return!1}function ge(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function se(i){if(e.isJSXText(i)){let s=H(i.value);return s?Ee(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(F(i))return"";let o=`<${r}`;for(let s of n.attributes){if(e.isJSXSpreadAttribute(s))continue;let a=T(s);if(a==="key"||z(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!s.value)o+=` ${c}`;else if(e.isStringLiteral(s.value))o+=` ${c}="${Oe(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let t=i.openingElement.selfClosing;if(t&&k(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let s of i.children)if(e.isJSXText(s)){let a=H(s.value);a&&(o+=Ee(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(o+="<!--$-->"):e.isJSXElement(s)&&(F(s)?o+="<!--$-->":o+=se(s));return o+=`</${r}>`,o}function Ee(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Oe(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function U(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!C(t,n)){if(t==="For")return Te(i,n);if(t==="Show")return Je(i,n)}if(t==="Switch"&&(!C(t,n)||j(r)))return Re(i,n);if(F(r))return ye(i,n);let s=o.attributes,a=r.children,c=a.every(te),p=s.every(l=>!ge(l)),g=s.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let b=T(l);return!b?.startsWith("on")&&!b?.startsWith("bind:")});if(c&&p&&g){let l=se(r);if(l){let b=we(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(b),[])}}let u=se(r);if(!u){let l=r.loc,b=n.filename||n.file?.opts?.filename||"<unknown>",y=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${b}${y}. 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 f=we(n,u);n.needsTemplate=!0;let x=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier(f),[]))])];return xe(h,x,s,n,t),be(h,x,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(x)}function ae(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,s=o.attributes,a=r.children,c=[];for(let u of s){if(e.isJSXSpreadAttribute(u))continue;let f=T(u),x=_(u.value),h=D(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),x))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=H(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(U({node:u},n)):e.isJSXFragment(u)&&p.push(q({node:u},n));let g=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),g,...p])}let je=new Set(["input","textarea","select","option"]);function xe(i,n,r,o,t){function s(p,g){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),g])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),g])):p==="value"&&t&&je.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),g])):p==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),g])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),g])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),g]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let g=T(p);if(g!=="key"){if(g==="ref"){let u=_(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(g.startsWith("on")&&!g.includes("|")&&!w(g,o)){let u=g.slice(2).toLowerCase(),f=_(p.value);Ke.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(g.startsWith("on")&&(g.includes("|")||w(g,o))){let{eventName:u,modifiers:f}=E(g),x=_(p.value),h=Y(x,f),l=u.slice(2).toLowerCase(),b=f.filter(I=>ze.has(I)),y=[e.stringLiteral(l),h];if(b.length>0){let I=b.map(M=>e.objectProperty(e.identifier(M),e.booleanLiteral(!0)));y.push(e.objectExpression(I))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),y)));continue}if(S(g)){let u=v(g),f=p.value.expression;o.needsEffect=!0,u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="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(f),[])))]))),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(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=D(g);if(N(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let x=o.signalNames&&o.signalNames.fromDestructuredProps,h=e.isIdentifier(u)&&!(x&&x.has(u.name))&&(L(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],s(f,h))]);me(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(s(f,u)))}}}}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 De(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function G(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(!N(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(le))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return t?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function be(i,n,r,o,t){let s=[],a=0;for(let f of r){if(e.isJSXText(f)){H(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;s.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let x=f.openingElement.name.name;if(F(f)||x==="For"||x==="Show")s.push({type:"component",child:f,childIndex:a}),a++;else{let h=f.openingElement.attributes.some(ge)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&T(l)?.startsWith("on"))||!f.children.every(te);s.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:h}),a++}continue}e.isJSXFragment(f)&&s.push({type:"fragment",child:f})}let c=s.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,g=new Map;if(p){let f=null,x=0;for(let h of c){let l=h.childIndex,b=t.nextVarId();g.set(l,b);let y;if(f===null)y=ce(n,l);else{y=e.identifier(f);for(let I=x;I<l;I++)y=e.memberExpression(y,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(b),y)])),f=b,x=l}}function u(f){return g.has(f)?e.identifier(g.get(f)):ce(n,f)}for(let f of s){if(f.type==="expression"){let x=f.child.expression,h=u(f.childIndex);t.needsInsert=!0;let l=he(x,t);if(l){t.needsMapArray=!0;let y=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),I=e.isArrowFunctionExpression(l);I&&e.isExpression(l.body)?l.body=G(l.body,i,t):!y&&!I&&(l=G(l,i,t));let M=y||I?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,h])));continue}if(e.isCallExpression(x)&&e.isIdentifier(x.callee)&&(x.callee.name==="mapArray"||x.callee.name==="_$mapArray")){t.needsMapArray=!0,x.callee.name==="mapArray"&&(x.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(N(x,t.signalNames,t.importedIdentifiers)){x=G(x,i,t);let y=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],x),h]);me(x,t.signalNames,t.importedIdentifiers)&&e.addComment(y,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(y))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="component"){let x=U({node:f.child},t),h=u(f.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),x,h])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let x;g.has(f.childIndex)?x=g.get(f.childIndex):(x=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),ce(n,f.childIndex))]))),xe(i,x,f.child.openingElement.attributes,t,f.child.openingElement.name.name),be(i,x,f.child.children,f.child,t);continue}if(f.type==="fragment"){for(let x of f.child.children)if(e.isJSXExpressionContainer(x)&&!e.isJSXEmptyExpression(x.expression)){t.needsInsert=!0;let h=x.expression;N(h,t.signalNames,t.importedIdentifiers)?(h=G(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=X(o.name),s=o.attributes,a=r.children,c=null,p=[];for(let b of s){if(e.isJSXAttribute(b)){let y;if(e.isJSXNamespacedName(b.name)?y=`${b.name.namespace.name}:${b.name.name.name}`:y=b.name.name,y&&typeof y=="string"&&y.startsWith("client:")){let I=y.slice(7);b.value?c={type:I,value:b.value.value}:c={type:I};continue}}p.push(b)}function g(){let b=n._pendingSetup?n._pendingSetup.length:0,y=[],I=!1;for(let A of a)if(e.isJSXText(A)){let P=H(A.value);P&&y.push(e.stringLiteral(P))}else if(e.isJSXExpressionContainer(A))e.isJSXEmptyExpression(A.expression)||(I=!0,y.push(A.expression));else if(e.isJSXElement(A)){let P=A.openingElement.name.name;P!=="For"&&P!=="Show"&&P!=="Switch"&&(I=!0),y.push(U({node:A},n))}else e.isJSXFragment(A)&&(I=!0,y.push(q({node:A},n)));let M=e.arrayExpression(y);if(I){let A=n._pendingSetup?n._pendingSetup.splice(b):[];M=e.arrowFunctionExpression([],A.length>0?e.blockStatement([...A,e.returnStatement(M)]):M)}return M}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let b=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&b.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let y=null;for(let M of p){if(e.isJSXSpreadAttribute(M)){y=M.argument;continue}let A=T(M);if(A==="key")continue;let P=_(M.value);b.push(e.objectProperty(e.identifier(A),P))}let I=y?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),y,e.objectExpression(b)]):e.objectExpression(b);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),I,g()])}n.needsCreateComponent=!0;let u=[],f=!1,x=null;for(let b of p){if(e.isJSXSpreadAttribute(b)){f=!0,x=b.argument;continue}let y=T(b);if(y==="key")continue;if(S(y)){let M=v(y),A=b.value.expression;M==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(A),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(A),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):M==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(A),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(A),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(y.startsWith("on")&&(y.includes("|")||w(y,n))){let{eventName:M,modifiers:A}=E(y),P=_(b.value),W=Y(P,A);u.push(e.objectProperty(e.identifier(M),W));continue}let I=_(b.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(y)?e.identifier(y):e.stringLiteral(y),I))}let h;f?u.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),x,e.objectExpression(u)]):h=x:u.length>0?h=e.objectExpression(u):h=e.nullLiteral();let l=g();return e.callExpression(e.identifier("_$createComponent"),[t,h,l])}function Te(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,s=null,a=null,c=null;for(let P of o)if(e.isJSXAttribute(P)){let W=T(P);W==="each"?s=_(P.value):W==="key"?a=_(P.value):W==="fallback"&&(c=_(P.value))}if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ae(i,n);let p=null;for(let P of t)if(e.isJSXExpressionContainer(P)&&!e.isJSXEmptyExpression(P.expression)){p=P.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ae(i,n);n.needsMapArray=!0;let g=P=>{let W=[P,p];return a&&W.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),W)};if(!c)return g(s);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,x=`_for$${u}`,h=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let b=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),y=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),s)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(b,y)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(b),e.memberExpression(e.cloneNode(b),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),g(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let I=e.identifier("_parent"),M=e.identifier("_marker"),A=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([I,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(A,e.callExpression(e.identifier(x),[e.cloneNode(I),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(I),e.arrayExpression([e.identifier(h)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(A))])),e.identifier(x)])}function Je(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 l=T(h);l==="when"?s=_(h.value):l==="fallback"&&(a=_(h.value))}if(!s)throw O(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){c=h.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let h=n._pendingSetup.length,l=[];for(let y of t)if(e.isJSXText(y)){let I=H(y.value);I&&l.push(e.stringLiteral(I))}else e.isJSXElement(y)&&l.push(U({node:y},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let b=n._pendingSetup.splice(h);b.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...b,e.returnStatement(c)])),[]))}let p=Se(s,n),g=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(g)]):c,x=a||e.nullLiteral();if(N(p,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(g,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(g),f,x))]))}function Se(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&L(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Xe(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(U({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 Re(i,n){let{node:r}=i,o=C(r.openingElement.name.name,n),t=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!C("Match",n));if(!r.children.some(t)&&!J(r.openingElement.name.name,n))return ye(i,n);let s=l=>{throw O(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&s("cannot take a spread attribute"),T(l)==="fallback"&&(a=_(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){H(l.value)&&s("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s("cannot read its arms from an expression child")}t(l)||s("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&s("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let b=null;for(let A of l.openingElement.attributes)e.isJSXAttribute(A)&&T(A)==="when"&&(b=_(A.value));b||s('has a <Match> with no "when" prop');let y=n._pendingSetup.length,I=Xe(l.children,n),M=n._pendingSetup.splice(y);M.length>0&&(I=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(I)])),[])),p.push([Se(b,n),I])}let g=p.some(([l])=>N(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!g){let l=u;for(let b=p.length-1;b>=0;b--)l=e.conditionalExpression(p[b][0],p[b][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);let x=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))]));let h=u;for(let l=p.length-1;l>=0;l--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(x),[]),e.numericLiteral(l)),p[l][1],h);return e.arrowFunctionExpression([],h)}function We(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=he(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=G(o.body,r,n),o;if(s)return o;let c=G(o,r,n);return e.arrowFunctionExpression([],c)}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):N(i,n.signalNames,n.importedIdentifiers)?(i=G(i,r,n),e.arrowFunctionExpression([],i)):i}function q(i,n){let{node:r}=i,o=r.children,t=[];for(let s of o)if(e.isJSXText(s)){let a=H(s.value);a&&t.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||t.push(We(s.expression,n)):e.isJSXElement(s)?t.push(U({node:s},n)):e.isJSXFragment(s)&&t.push(q({node:s},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 s=t.get(o);s||(s=Q(i),t.set(o,s)),n.signalNames=s,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,g=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(g=!0),De(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!g&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function He(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 Ve(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 Be(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 s=i.node.loc?.start||{line:0,column:0},a=`${t}:${s.line}:${s.column+1}`,c=`${t}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let g={id:r,key:c,bindingName:o,filename:t,source:a,loc:s};if(n.serverActionIds.set(r,g),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(g)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Ue(i,n){if(!Ve(i,n))return;let r=He(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=Be(o);if(t.property){t.value!==null&&_e(i,n,t.value,r,n.serverActionFilename);return}let s=`wa1_${Qe(`${n.serverActionFilename}#${r}`)}`;_e(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._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=en(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/"),s=t||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((s||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),t?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),Ye.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){R(r)},CallExpression(r){Ue(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),ke.has(s)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.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&&nn(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){ve(i,n,U)},JSXFragment(i,n){ve(i,n,q)}}}}function nn(e,m,d){let w=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){w=E;break}if(w){let E=new Set(w.specifiers.filter(S=>m.isImportSpecifier(S)).map(S=>S.imported.name));for(let S of d)E.has(S.imported.name)||w.specifiers.push(S)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import K from"fs";import B from"path";var $e=new Set([".jsx",".tsx",".js",".ts"]),rn=new Set(["_layout","_error","_loading","_404"]);function on(e){let m=[],d=[],w=[];function E(v,$=""){if(!K.existsSync(v))return;let O=K.readdirSync(v,{withFileTypes:!0});for(let F of O){let C=B.join(v,F.name);if(F.isDirectory()){if(F.name.match(/^\((.+)\)$/)){E(C,$);continue}if(F.name==="api"&&$===""){S(C,"/api");continue}E(C,$+"/"+ie(F.name));continue}let J=B.extname(F.name);if(!$e.has(J))continue;let j=B.basename(F.name,J);if(j==="_layout"){d.push({filePath:C,urlPrefix:$||"/"});continue}if(rn.has(j))continue;let X=ie(j),R=j==="index"?$||"/":$+"/"+X;m.push({filePath:C,routePath:Ce(R),isDynamic:R.includes(":")||R.includes("*")})}}function S(v,$){if(!K.existsSync(v))return;let O=K.readdirSync(v,{withFileTypes:!0});for(let F of O){let C=B.join(v,F.name);if(F.isDirectory()){S(C,$+"/"+ie(F.name));continue}let J=B.extname(F.name);if(!$e.has(J))continue;let j=B.basename(F.name,J),X=ie(j),R=j==="index"?$:$+"/"+X;w.push({filePath:C,routePath:Ce(R)})}}return E(e),m.sort((v,$)=>{let O=Ie(v.routePath),F=Ie($.routePath);return O-F}),{pages:m,layouts:d,apiRoutes:w}}function ie(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function Ce(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Ie(e){return e.includes("*")?100:e.includes(":")?10:0}var tn=/export\s+const\s+page\s*=\s*\{/;function sn(e,m={}){let d=tn.exec(e);if(!d)return{mode:"client"};let w=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(fn(e,w))}}catch(E){return an(E,m.filePath),{mode:"client"}}}function an(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
2
2
  This page falls back to mode 'client', so static generation will skip it.
3
- \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var cn=e=>/[A-Za-z_$]/.test(e),fn=e=>/[A-Za-z0-9_$]/.test(e);function pn(e,m){let d=[],v=-1,E=0,w=m;for(;w<e.length;){let _=e[w];if(_==="/"&&e[w+1]==="/"){let k=e.indexOf(`
4
- `,w);w=k===-1?e.length:k,d.push(" ");continue}if(_==="/"&&e[w+1]==="*"){let k=e.indexOf("*/",w+2);if(k===-1)throw new SyntaxError("unterminated block comment");w=k+2,d.push(" ");continue}if(_==='"'||_==="'"||_==="`"){let k=dn(e,w);d.push(JSON.stringify(k.value)),v=-1,w=k.end;continue}if(cn(_)){let k=w+1;for(;k<e.length&&fn(e[k]);)k++;let j=e.slice(w,k);d.push(un(e,k)?JSON.stringify(j):j),v=-1,w=k;continue}if(_===" "||_===" "||_===`
5
- `||_==="\r"){d.push(_),w++;continue}if(_===","){d.push(","),v=d.length-1,w++;continue}if(_==="}"||_==="]"){if(v!==-1&&(d[v]=""),v=-1,d.push(_),w++,_==="}"&&--E===0)return d.join("");continue}_==="{"&&E++,d.push(_),v=-1,w++}throw new SyntaxError("unterminated object literal")}function un(e,m){let d=m;for(;d<e.length;){let v=e[d];if(v===" "||v===" "||v===`
6
- `||v==="\r"){d++;continue}if(v==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
- `,d);if(E===-1)return!1;d=E+1;continue}if(v==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return v===":"}return!1}var Fe={n:`
8
- `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function dn(e,m){let d=e[m],v="",E=m+1;for(;E<e.length;){let w=e[E];if(w==="\\"){let _=e[E+1];if(_===void 0)break;if(_===`
9
- `){E+=2;continue}if(_==="\r"){E+=e[E+2]===`
10
- `?3:2;continue}if(_==="u"){if(e[E+2]==="{"){let k=e.indexOf("}",E+3);if(k===-1)throw new SyntaxError("invalid unicode escape");v+=String.fromCodePoint(parseInt(e.slice(E+3,k),16)),E=k+1;continue}v+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(_==="x"){v+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}v+=Object.prototype.hasOwnProperty.call(Fe,_)?Fe[_]:_,E+=2;continue}if(w===d)return{value:v,end:E+1};if(d==="`"&&w==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(w===`
11
- `||w==="\r"))break;v+=w,E++}throw new SyntaxError("unterminated string literal")}function mn(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 Me(e,m){let{pages:d,layouts:v,apiRoutes:E}=tn(e),w=[],_=[],k=new Map;v.forEach(($,J)=>{let P=`_layout${J}`,T=ue($.filePath,m);w.push(`import ${P} from '${T}';`),k.set($.urlPrefix,P)}),d.forEach(($,J)=>{let P=`_page${J}`,T=ue($.filePath,m);w.push(`import ${P} from '${T}';`);let X={mode:"client"},V={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let A=Y.readFileSync($.filePath,"utf-8");X=an(A,{filePath:$.filePath}),V=mn(A)}catch{}let b=hn($.routePath,k),I={path:$.routePath,component:P,mode:X.mode||"client",layout:b||null,hasLoader:V.hasLoader};_.push(I)});let j=[];return E.forEach(($,J)=>{let P=`_api${J}`,T=ue($.filePath,m);w.push(`import * as ${P} from '${T}';`),j.push({path:$.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...w,"","export const routes = [",..._.map($=>` { path: '${$.path}', component: ${$.component}, mode: '${$.mode}'${$.layout?`, layout: ${$.layout}`:""}${$.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...j.map($=>` { path: '${$.path}', handlers: ${$.handlers} },`),"];","","export const pageModes = {",..._.map($=>` '${$.path}': '${$.mode}',`),"};"].join(`
12
- `)}function ue(e,m){return"/"+G.relative(m,e).split(G.sep).join("/")}function hn(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let v="/"+d.join("/");if(m.has(v))return m.get(v);d.pop()}return m.has("/")?m.get("/"):null}var gn=`
3
+ \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var ln=e=>/[A-Za-z_$]/.test(e),cn=e=>/[A-Za-z0-9_$]/.test(e);function fn(e,m){let d=[],w=-1,E=0,S=m;for(;S<e.length;){let v=e[S];if(v==="/"&&e[S+1]==="/"){let $=e.indexOf(`
4
+ `,S);S=$===-1?e.length:$,d.push(" ");continue}if(v==="/"&&e[S+1]==="*"){let $=e.indexOf("*/",S+2);if($===-1)throw new SyntaxError("unterminated block comment");S=$+2,d.push(" ");continue}if(v==='"'||v==="'"||v==="`"){let $=un(e,S);d.push(JSON.stringify($.value)),w=-1,S=$.end;continue}if(ln(v)){let $=S+1;for(;$<e.length&&cn(e[$]);)$++;let O=e.slice(S,$);d.push(pn(e,$)?JSON.stringify(O):O),w=-1,S=$;continue}if(v===" "||v===" "||v===`
5
+ `||v==="\r"){d.push(v),S++;continue}if(v===","){d.push(","),w=d.length-1,S++;continue}if(v==="}"||v==="]"){if(w!==-1&&(d[w]=""),w=-1,d.push(v),S++,v==="}"&&--E===0)return d.join("");continue}v==="{"&&E++,d.push(v),w=-1,S++}throw new SyntaxError("unterminated object literal")}function pn(e,m){let d=m;for(;d<e.length;){let w=e[d];if(w===" "||w===" "||w===`
6
+ `||w==="\r"){d++;continue}if(w==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
+ `,d);if(E===-1)return!1;d=E+1;continue}if(w==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return w===":"}return!1}var Ae={n:`
8
+ `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function un(e,m){let d=e[m],w="",E=m+1;for(;E<e.length;){let S=e[E];if(S==="\\"){let v=e[E+1];if(v===void 0)break;if(v===`
9
+ `){E+=2;continue}if(v==="\r"){E+=e[E+2]===`
10
+ `?3:2;continue}if(v==="u"){if(e[E+2]==="{"){let $=e.indexOf("}",E+3);if($===-1)throw new SyntaxError("invalid unicode escape");w+=String.fromCodePoint(parseInt(e.slice(E+3,$),16)),E=$+1;continue}w+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(v==="x"){w+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}w+=Object.prototype.hasOwnProperty.call(Ae,v)?Ae[v]:v,E+=2;continue}if(S===d)return{value:w,end:E+1};if(d==="`"&&S==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(S===`
11
+ `||S==="\r"))break;w+=S,E++}throw new SyntaxError("unterminated string literal")}function dn(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 Fe(e,m){let{pages:d,layouts:w,apiRoutes:E}=on(e),S=[],v=[],$=new Map;w.forEach((C,J)=>{let j=`_layout${J}`,X=pe(C.filePath,m);S.push(`import ${j} from '${X}';`),$.set(C.urlPrefix,j)}),d.forEach((C,J)=>{let j=`_page${J}`,X=pe(C.filePath,m);S.push(`import ${j} from '${X}';`);let R={mode:"client"},k={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let T=K.readFileSync(C.filePath,"utf-8");R=sn(T,{filePath:C.filePath}),k=dn(T)}catch{}let _=mn(C.routePath,$),D={path:C.routePath,component:j,mode:R.mode||"client",layout:_||null,hasLoader:k.hasLoader};v.push(D)});let O=[];return E.forEach((C,J)=>{let j=`_api${J}`,X=pe(C.filePath,m);S.push(`import * as ${j} from '${X}';`),O.push({path:C.routePath,handlers:j})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...S,"","export const routes = [",...v.map(C=>` { path: '${C.path}', component: ${C.component}, mode: '${C.mode}'${C.layout?`, layout: ${C.layout}`:""}${C.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...O.map(C=>` { path: '${C.path}', handlers: ${C.handlers} },`),"];","","export const pageModes = {",...v.map(C=>` '${C.path}': '${C.mode}',`),"};"].join(`
12
+ `)}function pe(e,m){return"/"+B.relative(m,e).split(B.sep).join("/")}function mn(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let w="/"+d.join("/");if(m.has(w))return m.get(w);d.pop()}return m.has("/")?m.get("/"):null}var hn=`
13
13
  :host {
14
14
  position: fixed;
15
15
  inset: 0;
@@ -195,12 +195,12 @@ import Q from"path";import{transformSync as En}from"@babel/core";var ze=new Set(
195
195
  white-space: pre-wrap;
196
196
  line-height: 1.5;
197
197
  }
198
- `,Pn=`
198
+ `,Ln=`
199
199
  class WhatErrorOverlay extends HTMLElement {
200
200
  constructor(err) {
201
201
  super();
202
202
  this.root = this.attachShadow({ mode: 'open' });
203
- this.root.innerHTML = '<style>${gn}</style>';
203
+ this.root.innerHTML = '<style>${hn}</style>';
204
204
  this._err = err;
205
205
  this.show(err);
206
206
  }
@@ -390,7 +390,7 @@ class WhatErrorOverlay extends HTMLElement {
390
390
  if (!customElements.get('what-error-overlay')) {
391
391
  customElements.define('what-error-overlay', WhatErrorOverlay);
392
392
  }
393
- `;function Le(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(d){return d?.type==="error"&&d.err?.plugin==="vite-plugin-what"&&(d.err._isCompilerError=!0),m(d)}}var Pe="virtual:what-routes",re="\0"+Pe,xn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,bn=/\.[cm]?[jt]sx?$/;function me(e,m){return e?Array.isArray(e)?e.some(d=>me(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function yn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var de=null;function Sn(){return de||(de=import("vite").then(e=>e.version||"").catch(()=>"")),de}var wn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,vn=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function _n(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:v=!0,production:E=!0,pages:w="src/pages",hot:_=!E,prodBundles:k=!0}=e,j="",M="",$=null,J=!1,P=new Map;function T(b){let I=P.get(b.id);if(I&&I.key!==b.key)throw new Error(`Duplicate server action ID "${b.id}". First declared by "${I.bindingName}" at ${I.source}; conflicts with "${b.bindingName}" at ${b.source}.`);P.set(b.id,b)}function X(b){for(let[I,A]of P)A.filename===b&&P.delete(I)}function V(b){let I=b.replace(/[?#].*$/,"");return j?Q.relative(j,I).split(Q.sep).join("/"):I}return{name:"vite-plugin-what",configResolved(b){j=b.root,M=Q.resolve(j,w),J=b.command==="serve"},configureServer(b){$=b,Le(b),b.watcher.on("add",I=>{if(I.startsWith(M)){let A=b.moduleGraph.getModuleById(re);A&&(b.moduleGraph.invalidateModule(A),b.ws.send({type:"full-reload"}))}}),b.watcher.on("unlink",I=>{if(X(V(I)),I.startsWith(M)){let A=b.moduleGraph.getModuleById(re);A&&(b.moduleGraph.invalidateModule(A),b.ws.send({type:"full-reload"}))}})},resolveId(b){if(b===Pe)return re},load(b){if(b===re)return Me(M,j)},transform(b,I){let A=I.replace(/[?#].*$/,""),K=me(m,A),U=bn.test(A),R=U&&xn.test(b);if(d&&me(d,A)||(U&&X(V(A)),!K&&!R))return null;try{let D=En(b,{filename:I,sourceMaps:v,configFile:!1,babelrc:!1,plugins:[[pe,{production:E,projectRoot:j||process.cwd(),onActionId:T}]],parserOpts:{plugins:["jsx","typescript"]}});if(!D||!D.code)return null;let oe=D.code;return _&&J&&!E&&kn(b,I)&&(oe+=Cn(I)),{code:oe,map:D.map}}catch(D){throw D.plugin="vite-plugin-what",D.id||(D.id=I),D.loc===void 0&&D._loc&&(D.loc={file:I,line:D._loc.line,column:D._loc.column}),console.error(`[what] Error transforming ${I}:`,D.message),D}},handleHotUpdate({file:b,server:I,modules:A}){if(_&&m.test(b)&&!(d&&d.test(b))&&$n(b))return I.ws.send({type:"full-reload"}),[]},async config(b,{mode:I,command:A}){let K=A==="build"&&I==="production"&&k,U=yn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Sn()});return{...K?{resolve:{conditions:["production"]}}:{},...U,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function kn(e,m){return!!(wn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function $n(e){let m=Q.basename(e,Q.extname(e));return vn.test(m)}function Cn(e){return`
393
+ `;function Me(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(d){return d?.type==="error"&&d.err?.plugin==="vite-plugin-what"&&(d.err._isCompilerError=!0),m(d)}}var Le="virtual:what-routes",re="\0"+Le,En=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,xn=/\.[cm]?[jt]sx?$/;function de(e,m){return e?Array.isArray(e)?e.some(d=>de(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function bn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var ue=null;function yn(){return ue||(ue=import("vite").then(e=>e.version||"").catch(()=>"")),ue}var Sn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,wn=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function vn(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:w=!0,production:E=!0,pages:S="src/pages",hot:v=!E,prodBundles:$=!0}=e,O="",F="",C=!1,J=new Map;function j(k){let _=J.get(k.id);if(_&&_.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${_.bindingName}" at ${_.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});J.set(k.id,k)}function X(k){for(let[_,D]of J)D.filename===k&&J.delete(_)}function R(k){let _=k.replace(/[?#].*$/,"");return O?Z.relative(O,_).split(Z.sep).join("/"):_}return{name:"vite-plugin-what",configResolved(k){O=k.root,F=Z.resolve(O,S),C=k.command==="serve"},configureServer(k){Me(k),k.watcher.on("add",_=>{if(_.startsWith(F)){let D=k.moduleGraph.getModuleById(re);D&&(k.moduleGraph.invalidateModule(D),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",_=>{if(X(R(_)),_.startsWith(F)){let D=k.moduleGraph.getModuleById(re);D&&(k.moduleGraph.invalidateModule(D),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===Le)return re},load(k){if(k===re)return Fe(F,O)},transform(k,_){let D=_.replace(/[?#].*$/,""),T=de(m,D),z=xn.test(D),Y=z&&En.test(k);if(d&&de(d,D)||(z&&X(R(D)),!T&&!Y))return null;try{let L=gn(k,{filename:_,sourceMaps:w,configFile:!1,babelrc:!1,plugins:[[fe,{production:E,projectRoot:O||process.cwd(),onActionId:j}]],parserOpts:{plugins:["jsx","typescript"]}});if(!L||!L.code)return null;let Q=L.code;return v&&C&&!E&&_n(k,_)&&(Q+=$n(_)),{code:Q,map:L.map}}catch(L){throw L.plugin="vite-plugin-what",L.id||(L.id=_),L.loc===void 0&&L._loc&&(L.loc={file:_,line:L._loc.line,column:L._loc.column}),console.error(`[what] Error transforming ${_}:`,L.message),L}},handleHotUpdate({file:k,server:_}){if(v&&m.test(k)&&!(d&&d.test(k))&&kn(k))return _.ws.send({type:"full-reload"}),[]},async config(k,{mode:_,command:D}){let T=D==="build"&&_==="production"&&$,z=bn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await yn()});return{...T?{resolve:{conditions:["production"]}}:{},...z,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function _n(e,m){return!!(Sn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function kn(e){let m=Z.basename(e,Z.extname(e));return wn.test(m)}function $n(e){return`
394
394
 
395
395
  // --- What Framework HMR Boundary ---
396
396
  if (import.meta.hot) {
@@ -403,4 +403,4 @@ if (import.meta.hot) {
403
403
  }
404
404
  });
405
405
  }
406
- `}export{_n as default,yn as jsxPreserveConfig,_n as what};
406
+ `}export{vn as default,bn as jsxPreserveConfig,vn as what};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-compiler",
3
- "version": "0.12.4",
3
+ "version": "0.13.0",
4
4
  "description": "JSX compiler for What Framework - transforms JSX to optimized DOM operations",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
@@ -49,7 +49,7 @@
49
49
  "license": "MIT",
50
50
  "peerDependencies": {
51
51
  "@babel/core": "^7.0.0",
52
- "what-core": "^0.12.4"
52
+ "what-core": "^0.13.0"
53
53
  },
54
54
  "files": [
55
55
  "src",
@@ -516,10 +516,9 @@ export default function whatBabelPlugin({ types: t }) {
516
516
  return signalNames;
517
517
  }
518
518
 
519
- // Legacy wrapper for backward compat (used in collectSignalNames calls)
520
- function collectSignalNames(path) {
521
- return collectSignalNamesFromScope(path);
522
- }
519
+ // A `collectSignalNames` wrapper lived here, commented "legacy wrapper for
520
+ // backward compat (used in collectSignalNames calls)". Nothing called it;
521
+ // every call site uses collectSignalNamesFromScope directly.
523
522
 
524
523
  // Check if a call expression is a safe (non-reactive) global call
525
524
  function isSafeGlobalCall(expr) {
@@ -1670,7 +1669,8 @@ export default function whatBabelPlugin({ types: t }) {
1670
1669
  let prevVar = null;
1671
1670
  let prevIndex = 0;
1672
1671
  for (const entry of entriesNeedingRef) {
1673
- const idx = entry.childIndex;
1672
+ // Only 'fragment' entries omit childIndex, and the filter above drops them.
1673
+ const idx = /** @type {number} */ (entry.childIndex);
1674
1674
  const markerVar = state.nextVarId();
1675
1675
  markerVars.set(idx, markerVar);
1676
1676
  let init;
@@ -11,7 +11,7 @@
11
11
  import path from 'path';
12
12
  import { transformSync } from '@babel/core';
13
13
  import whatBabelPlugin from './babel-plugin.js';
14
- import { generateRoutesModule, scanPages } from './file-router.js';
14
+ import { generateRoutesModule } from './file-router.js';
15
15
  import { setupErrorOverlay } from './error-overlay.js';
16
16
 
17
17
  const VIRTUAL_ROUTES_ID = 'virtual:what-routes';
@@ -44,6 +44,10 @@ function patternMatches(pattern, value) {
44
44
  * - version: `import('vite')` exports `version`; major ≥ 8 means rolldown.
45
45
  *
46
46
  * Exported for unit tests.
47
+ *
48
+ * @param {object} [signals]
49
+ * @param {string|number} [signals.rolldownVersion]
50
+ * @param {string|number} [signals.viteVersion]
47
51
  */
48
52
  export function jsxPreserveConfig({ rolldownVersion, viteVersion } = {}) {
49
53
  const major = parseInt(String(viteVersion ?? ''), 10);
@@ -92,17 +96,20 @@ export default function whatVitePlugin(options = {}) {
92
96
 
93
97
  let rootDir = '';
94
98
  let pagesDir = '';
95
- let server = null;
96
99
  let isDevMode = false;
97
100
  const actionIdRegistry = new Map();
98
101
 
99
102
  function registerActionId(metadata) {
100
103
  const existing = actionIdRegistry.get(metadata.id);
101
104
  if (existing && existing.key !== metadata.key) {
102
- throw new Error(
103
- `Duplicate server action ID "${metadata.id}". ` +
104
- `First declared by "${existing.bindingName}" at ${existing.source}; ` +
105
- `conflicts with "${metadata.bindingName}" at ${metadata.source}.`
105
+ // ERROR_CODES.DUPLICATE_ACTION_ID
106
+ throw Object.assign(
107
+ new Error(
108
+ `Duplicate server action ID "${metadata.id}". ` +
109
+ `First declared by "${existing.bindingName}" at ${existing.source}; ` +
110
+ `conflicts with "${metadata.bindingName}" at ${metadata.source}.`
111
+ ),
112
+ { code: 'ERR_DUPLICATE_ACTION_ID' },
106
113
  );
107
114
  }
108
115
  actionIdRegistry.set(metadata.id, metadata);
@@ -131,8 +138,6 @@ export default function whatVitePlugin(options = {}) {
131
138
  },
132
139
 
133
140
  configureServer(devServer) {
134
- server = devServer;
135
-
136
141
  // Set up What-branded error overlay
137
142
  setupErrorOverlay(devServer);
138
143
 
@@ -248,7 +253,7 @@ export default function whatVitePlugin(options = {}) {
248
253
  },
249
254
 
250
255
  // HMR: detect component vs utility files and handle accordingly
251
- handleHotUpdate({ file, server: devServer, modules }) {
256
+ handleHotUpdate({ file, server: devServer}) {
252
257
  if (!hot) return;
253
258
 
254
259
  // Only handle files we process