what-compiler 0.13.9 → 0.13.10

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 Re=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ve=new Set(["once","capture","passive"]),We=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Be=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),W=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),Ue=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),he=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),He=new Set(["For","Show","Switch","Match"]),Ge=new Set(["what-framework/server","what-server","what-server/actions"]);function Se(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function ze(e){let _=0xcbf29ce484222325n;for(let k=0;k<e.length;k++)_^=BigInt(e.charCodeAt(k)),_=BigInt.asUintN(64,_*0x100000001b3n);return _.toString(36)}function qe(e,_){let k=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),$=String(_||"").replace(/\\/g,"/").replace(/\/+$/,"");return $&&k.startsWith(`${$}/`)?k.slice($.length+1):k.replace(/^\.\//,"")}function J(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let _=e.split(/\r\n|\n|\r/),k=-1;for(let y=0;y<_.length;y++)/[^ \t]/.test(_[y])&&(k=y);if(k===-1)return"";let $="";for(let y=0;y<_.length;y++){let C=_[y].replace(/\t/g," "),T=y===0,B=y===_.length-1;T||(C=C.replace(/^ +/,"")),B||(C=C.replace(/ +$/,"")),C&&(y!==k&&(C+=" "),$+=C)}return $}function Ke({types:e}){let _=new Set,k=new Set;function $(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(a=>Re.has(a));return{eventName:o,modifiers:s}}function C(i){return i.startsWith("bind:")}function T(i){return i.slice(5)}function B(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,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${a}:${s.line}:${s.column+1}`:a})`)}function D(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&B(n.name)}function R(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function ge(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function xe(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function be(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:ye(n.node.callee,n.scope)}function ye(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?Q(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?Q(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function Q(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let o=i.path.node;if(!n(o))return!1;if(r!==null){let a=o.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let s=i.path.parent;return e.isImportDeclaration(s)&&Se(s.source.value)}function Y(i){return e.isJSXMemberExpression(i)?e.memberExpression(Y(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function ve(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let u=0;u<r.properties.length;u++){let E=r.properties[u];if(e.isRestElement(E))return;if(e.isObjectProperty(E)&&!E.computed&&e.isIdentifier(E.key,{name:"children"})){if(o!==-1||!e.isIdentifier(E.value))return;o=u}}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(u=>{let E=u.parentPath;if(!E||!E.isJSXExpressionContainer())return!1;let d=E.parentPath;if(!d||!d.isJSXElement()||!D(d.node))return!1;let l=d.node.openingElement.name;return!(e.isJSXIdentifier(l)&&He.has(l.name))}))return;let t=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(t.typeAnnotation=r.typeAnnotation),n[0]=t;let c=r.properties.filter((u,E)=>E!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let u=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(u,e.cloneNode(t))])),i.node._whatMovedProps=u}for(let u of s.referencePaths)u.replaceWith(e.memberExpression(e.cloneNode(t),e.identifier("children")));i.scope.crawl()}function we(i){return We.has(String(i).toLowerCase())}function A(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function j(i){return i==="className"?"class":i==="htmlFor"?"for":i}function ee(i,n){let r=j(F(i[n]));for(let o=n+1;o<i.length;o+=1){let s=i[o];if(!e.isJSXSpreadAttribute(s)&&j(F(s))===r)return!0}return!1}function F(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 ne(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function Ie(i){return!!i&&i.length>2&&/^on/i.test(i)}function ie(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 _e(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(t){let c=t.init;if(!c||!e.isCallExpression(c))return;let u=c.callee,E="";if(e.isIdentifier(u)?E=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(E=u.property.name),he.has(E)){let d=t.id;if(e.isIdentifier(d))n.add(d.name);else if(e.isArrayPattern(d))for(let l of d.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(d))for(let l of d.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function s(t){if(e.isObjectPattern(t))for(let c of t.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let t=a.path&&a.path.node;if(t){if(t.params)for(let c of t.params)s(c);t._whatMovedProps&&s(t._whatMovedProps)}a=a.parent}return n}function Ce(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&Ue.has(i.callee.property.name)}function re(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?W.has(n.object.name):e.isIdentifier(n)?W.has(n.name):!1}function oe(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)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&N(i.callee.object.name,n)||re(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)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&N(i.callee.object.name,n)?!0:re(i)?i.arguments.some(o=>w(o,n,r)):i.arguments.length===0&&!Ce(i)?!0: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 Ae(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 a=o[s];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of M(i.params[0],new Set))n.delete(o);return n}function ke(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 a of Object.keys(s)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||s.type==="MemberExpression"&&a==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&a==="key"&&!s.computed)continue;let t=s[a];t&&typeof t=="object"&&o(t)}}};return o(i),r}function se(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let a=V(r.consequent,n),t=V(r.alternate,n);if(a||t){let c=e.conditionalExpression(r.test,a||r.consequent,t||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=V(r.right,n);if(a){let t=e.logicalExpression(r.operator,r.left,a);return o?e.arrowFunctionExpression([],t):t}return null}return V(r,n)}function V(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 m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}}else if(e.isFunctionExpression(r)){let m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,a=null;for(let m of s)if(e.isJSXAttribute(m)&&F(m)==="key"){a=m;break}if(!a)return null;let t=A(a.value);if(!t)return null;let c=Ae(r);if(ke(t,c)){let m=e.isIdentifier(t)&&r.params[1]&&e.isIdentifier(r.params[1],{name:t.name});return null}o.openingElement.attributes=s.filter(m=>m!==a);let E=i.callee.object,d=e.arrowFunctionExpression([],E),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),p=e.arrowFunctionExpression([l],e.cloneNode(t,!0));return e.callExpression(e.identifier("_$mapArray"),[d,r,e.objectExpression([e.objectProperty(e.identifier("key"),p),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function U(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(D(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(U)}return!1}function te(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function H(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let o=J(r.value);o&&n.push({kind:"text",text:o});continue}if(e.isJSXFragment(r)){H(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function G(i){if(e.isJSXText(i)){let t=J(i.value);return t?ae(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(D(i))return"";let o=`<${r}`,s=n.attributes.findIndex(t=>e.isJSXSpreadAttribute(t));for(let[t,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||s!==-1&&t>s||ee(n.attributes,t))continue;let u=F(c);if(u==="key"||Ie(u)||u.startsWith("bind:")||u.includes("|"))continue;let E=u;if(u==="className"&&(E="class"),u==="htmlFor"&&(E="for"),!c.value)o+=` ${E}`;else if(e.isStringLiteral(c.value))o+=` ${E}="${$e(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&we(r))return o+=">",o;if(a)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let c=J(t.value);c&&(o+=ae(c))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)?D(t)?o+="<!--$-->":o+=G(t):e.isJSXFragment(t)&&(o+="<!--$-->".repeat(H(t).length));return o+=`</${r}>`,o}function ae(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function $e(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(!R(s,n)){if(s==="For")return Me(i,n);if(s==="Show")return Ne(i,n)}if(s==="Switch"&&(!R(s,n)||xe(r)))return De(i,n);if(D(r))return fe(i,n);let a=o.attributes,t=r.children,c=t.every(U),u=a.every(f=>!te(f)),E=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let x=F(f);return!x?.startsWith("on")&&!x?.startsWith("bind:")});if(c&&u&&E){let f=G(r);if(f){let x=de(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(x),[])}}let d=G(r);if(!d){let f=r.loc,x=n.filename||n.file?.opts?.filename||"<unknown>",h=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${x}${h}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,z(i,n)}let l=de(n,d);n.needsTemplate=!0;let p=n.nextVarId(),m=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier(l),[]))])];return le(m,p,a,n,s),ce(m,p,t,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...m),e.identifier(p)}function z(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,a=o.attributes,t=r.children,c=[];for(let d of a){if(e.isJSXSpreadAttribute(d))continue;let l=F(d),p=A(d.value),m=j(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(m)?e.identifier(m):e.stringLiteral(m),p))}let u=[];for(let d of t)if(e.isJSXText(d)){let l=J(d.value);l&&u.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(d)?e.isJSXEmptyExpression(d.expression)||u.push(d.expression):e.isJSXElement(d)?u.push(X({node:d},n)):e.isJSXFragment(d)&&u.push(P({node:d},n));let E=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),E,...u])}let Fe=new Set(["input","textarea","select","option"]);function le(i,n,r,o,s){function a(E,d){return E==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):E==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):E==="value"&&s&&Fe.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):E==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):E.startsWith("data-")||E.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(E),d])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(E),d]))}let t=!1;function c(){t||(t=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let u=!1;for(let[E,d]of r.entries()){if(e.isJSXSpreadAttribute(d)){u=!0,o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),d.argument])));continue}if(ee(r,E))continue;let l=F(d);if(l!=="key"){if(l==="ref"){let p=A(d.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",p),e.stringLiteral("function")),e.callExpression(e.cloneNode(p),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(p),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!$(l,o)){let p=l.slice(2).toLowerCase(),m=A(d.value);Be.has(p)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(p),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${p}`)),m)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(p),m])));continue}if(l.startsWith("on")&&(l.includes("|")||$(l,o))){let{eventName:p,modifiers:m}=y(l),f=A(d.value),x=ie(f,m),h=p.slice(2).toLowerCase(),S=m.filter(v=>Ve.has(v)),b=[e.stringLiteral(h),x];if(S.length>0){let v=S.map(g=>e.objectProperty(e.identifier(g),e.booleanLiteral(!0)));b.push(e.objectExpression(v))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),b)));continue}if(C(l)){let p=T(l),m=d.value.expression;o.needsEffect=!0,p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(d.value)){let p=d.value.expression,m=j(l);if(w(p,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let f=o.signalNames&&o.signalNames.fromDestructuredProps,x=e.isIdentifier(p)&&!(f&&f.has(p.name))&&(N(p.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(p.name))?e.callExpression(p,[]):p,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(m,x))]);oe(p,o.signalNames,o.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(a(m,p)));continue}u&&i.push(e.expressionStatement(a(j(l),A(d.value))))}}}function q(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(q);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"&&q(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 L(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(q))return i;let t=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let u=e.callExpression(e.identifier(t),[]);return s?e.conditionalExpression(u,i.consequent,i.alternate):e.logicalExpression(i.operator,u,i.right)}function ce(i,n,r,o,s){let a=[],t=0;for(let l of r){if(e.isJSXText(l)){J(l.value)&&t++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:t}),t++;continue}if(e.isJSXElement(l)){let p=l.openingElement.name.name;if(D(l)||p==="For"||p==="Show")a.push({type:"component",child:l,childIndex:t}),t++;else{let m=l.openingElement.attributes.some(te)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&F(f)?.startsWith("on"))||!l.children.every(U);a.push({type:"static",child:l,childIndex:t,hasAnythingDynamic:m}),t++}continue}if(e.isJSXFragment(l))for(let p of H(l))p.kind==="text"?a.push({type:"fragmentText",text:p.text,childIndex:t}):p.kind==="expression"?a.push({type:"expression",child:p.child,childIndex:t}):a.push({type:"component",child:p.child,childIndex:t}),t++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),u=c.length>=2,E=new Map;if(u){let l=null,p=0;for(let m of c){let f=m.childIndex,x=s.nextVarId();E.set(f,x);let h;if(l===null)h=K(n,f);else{h=e.identifier(l);for(let S=p;S<f;S++)h=e.memberExpression(h,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),h)])),l=x,p=f}}function d(l){return E.has(l)?e.identifier(E.get(l)):K(n,l)}for(let l of a){if(l.type==="expression"){let p=l.child.expression,m=d(l.childIndex);s.needsInsert=!0;let f=se(p,s);if(f){s.needsMapArray=!0;let h=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),S=e.isArrowFunctionExpression(f);S&&e.isExpression(f.body)?f.body=L(f.body,i,s):!h&&!S&&(f=L(f,i,s));let b=h||S?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),b,m])));continue}if(e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="mapArray"||p.callee.name==="_$mapArray")){s.needsMapArray=!0,p.callee.name==="mapArray"&&(p.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(w(p,s.signalNames,s.importedIdentifiers)){p=L(p,i,s);let h=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],p),m]);oe(p,s.signalNames,s.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="component"){let p=X({node:l.child},s),m=d(l.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let p;E.has(l.childIndex)?p=E.get(l.childIndex):(p=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),K(n,l.childIndex))]))),le(i,p,l.child.openingElement.attributes,s,l.child.openingElement.name.name),ce(i,p,l.child.children,l.child,s);continue}if(l.type==="fragmentText"){s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),d(l.childIndex)])));continue}}}function K(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 fe(i,n){let{node:r}=i,o=r.openingElement,s=Y(o.name),a=o.attributes,t=r.children,c=null,u=[];for(let h of a){if(e.isJSXAttribute(h)){let S;if(e.isJSXNamespacedName(h.name)?S=`${h.name.namespace.name}:${h.name.name.name}`:S=h.name.name,S&&typeof S=="string"&&S.startsWith("client:")){let b=S.slice(7);h.value?c={type:b,value:h.value.value}:c={type:b};continue}}u.push(h)}function E(){let h=n._pendingSetup?n._pendingSetup.length:0,S=[],b=!1;for(let g of t)if(e.isJSXText(g)){let I=J(g.value);I&&S.push(e.stringLiteral(I))}else if(e.isJSXExpressionContainer(g))e.isJSXEmptyExpression(g.expression)||(b=!0,S.push(ue(g.expression,n)));else if(e.isJSXElement(g)){let I=g.openingElement.name.name;I!=="For"&&I!=="Show"&&I!=="Switch"&&(b=!0),S.push(X({node:g},n))}else e.isJSXFragment(g)&&(b=!0,S.push(P({node:g},n)));let v=e.arrayExpression(S);if(b){let g=n._pendingSetup?n._pendingSetup.splice(h):[];v=e.arrowFunctionExpression([],g.length>0?e.blockStatement([...g,e.returnStatement(v)]):v)}return v}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 S=[],b=[],v=()=>{b.length>0&&(S.push(e.objectExpression(b)),b=[])};for(let I of u){if(e.isJSXSpreadAttribute(I)){v(),S.push(I.argument);continue}let O=F(I);if(O==="key")continue;let Te=A(I.value);b.push(e.objectProperty(ne(O),Te))}let g;return S.length===0?g=e.objectExpression([...b,...h]):(v(),g=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...S,e.objectExpression(h)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),g,E()])}let d=be(i);d?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],p=[],m=()=>{p.length>0&&(l.push(e.objectExpression(p)),p=[])};for(let h of u){if(e.isJSXSpreadAttribute(h)){m(),l.push(h.argument);continue}let S=F(h);if(S==="key")continue;if(C(S)){let v=T(S),g=h.value.expression;v==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(g),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):v==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(g),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(S.startsWith("on")&&(S.includes("|")||$(S,n))){let{eventName:v,modifiers:g}=y(S),I=A(h.value),O=ie(I,g);p.push(e.objectProperty(e.identifier(v),O));continue}let b=A(h.value);p.push(e.objectProperty(ne(S),b))}m();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let x=E();return e.callExpression(e.identifier(d?"_$componentVNode":"_$createComponent"),[s,f,x])}function Me(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null,c=null;for(let g of o)if(e.isJSXAttribute(g)){let I=F(g);I==="each"?a=A(g.value):I==="key"?t=A(g.value):I==="fallback"&&(c=A(g.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,z(i,n);let u=null;for(let g of s)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){u=g.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,z(i,n);n.needsMapArray=!0;let E=g=>{let I=[g,u];return t&&I.push(e.objectExpression([e.objectProperty(e.identifier("key"),t)])),e.callExpression(e.identifier("_$mapArray"),I)};if(!c)return E(a);n._pendingSetup||(n._pendingSetup=[]);let d=n.nextForIndex(),l=`_each$${d}`,p=`_for$${d}`,m=`_fb$${d}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let x=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),h=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,h)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(x),e.memberExpression(e.cloneNode(x),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),E(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let S=e.identifier("_parent"),b=e.identifier("_marker"),v=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([S,b],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(v,e.callExpression(e.identifier(p),[e.cloneNode(S),e.cloneNode(b)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(S),e.arrayExpression([e.identifier(m)]),e.cloneNode(b)])),e.returnStatement(e.cloneNode(v))])),e.identifier(p)])}function Ne(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null;for(let m of o)if(e.isJSXAttribute(m)){let f=F(m);f==="when"?a=A(m.value):f==="fallback"&&(t=A(m.value))}if(!a)throw Z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let m of s)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){c=m.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let m=n._pendingSetup.length,f=[];for(let h of s)if(e.isJSXText(h)){let S=J(h.value);S&&f.push(e.stringLiteral(S))}else e.isJSXElement(h)&&f.push(X({node:h},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let x=n._pendingSetup.splice(m);x.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...x,e.returnStatement(c)])),[]))}let u=pe(a,n),E=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),d=e.isFunction(c),l=d?e.callExpression(c,[e.cloneNode(E)]):c,p=t||e.nullLiteral();if(w(u,n.signalNames,n.importedIdentifiers)){let m=n.nextMemoId();n.needsMemo=!0;let f=d?u:e.unaryExpression("!",e.unaryExpression("!",u));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),u=e.callExpression(e.identifier(m),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(E,u)]),e.returnStatement(e.conditionalExpression(e.cloneNode(E),l,p))]))}function pe(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 Xe(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(P({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function De(i,n){let{node:r}=i,o=R(r.openingElement.name.name,n),s=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(o||!R("Match",n));if(!r.children.some(s)&&!ge(r.openingElement.name.name,n))return fe(i,n);let a=f=>{throw Z(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},t=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),F(f)==="fallback"&&(t=A(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){J(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}s(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let u=[];for(let f of c){let x=null;for(let v of f.openingElement.attributes)e.isJSXAttribute(v)&&F(v)==="when"&&(x=A(v.value));x||a('has a <Match> with no "when" prop');let h=n._pendingSetup.length,S=Xe(f.children,n),b=n._pendingSetup.splice(h);b.length>0&&(S=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...b,e.returnStatement(S)])),[])),u.push([pe(x,n),S])}let E=u.some(([f])=>w(f,n.signalNames,n.importedIdentifiers)),d=t||e.nullLiteral();if(!E){let f=d;for(let x=u.length-1;x>=0;x--)f=e.conditionalExpression(u[x][0],u[x][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=u.length-1;f>=0;f--)l=e.conditionalExpression(u[f][0],e.numericLiteral(f),l);let p=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let m=d;for(let f=u.length-1;f>=0;f--)m=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(p),[]),e.numericLiteral(f)),u[f][1],m);return e.arrowFunctionExpression([],m)}function ue(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=se(i,n);if(o){n.needsMapArray=!0;let a=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=L(o.body,r,n),o;if(a)return o;let c=L(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=L(i,r,n),e.arrowFunctionExpression([],i)):i}function P(i,n){let{node:r}=i,o=r.children,s=[];for(let a of o)if(e.isJSXText(a)){let t=J(a.value);t&&s.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||s.push(ue(a.expression,n)):e.isJSXElement(a)?s.push(X({node:a},n)):e.isJSXFragment(a)&&s.push(P({node:a},n));return s.length===1?s[0]:e.arrayExpression(s)}function de(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 me(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let a=s.get(o);a||(a=_e(i),s.set(o,a)),n.signalNames=a,n._pendingSetup=[];let t=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let u=i,E=!1,d=!1;for(;u&&!u.isStatement();)(u.isArrowFunctionExpression()||u.isFunctionExpression())&&(E=!0),Je(u)&&(d=!0),u=u.parentPath;u&&u.isStatement()&&(u.listKey==="body"||u.listKey==="consequent")&&Array.isArray(u.container)&&!E&&!d?(u.insertBefore(c),i.replaceWith(t)):(c.push(e.returnStatement(t)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(t)}function Le(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 je(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 Pe(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 Ee(i,n,r,o,s){let a=i.node.loc?.start||{line:0,column:0},t=`${s}:${a.line}:${a.column+1}`,c=`${s}#${o}`,u=n.serverActionIds.get(r);if(u)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${u.bindingName}" at ${u.source}; conflicts with "${o}" at ${t}.`);let E={id:r,key:c,bindingName:o,filename:s,source:t,loc:a};if(n.serverActionIds.set(r,E),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(E)}catch(d){throw i.buildCodeFrameError(d instanceof Error?d.message:String(d))}}function Oe(i,n){if(!je(i,n))return;let r=Le(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=Pe(o);if(s.property){s.value!==null&&Ee(i,n,s.value,r,n.serverActionFilename);return}let a=`wa1_${ze(`${n.serverActionFilename}#${r}`)}`;Ee(i,n,a,r,n.serverActionFilename);let t=e.objectProperty(e.identifier("id"),e.stringLiteral(a));o?e.isObjectExpression(o)?o.properties.unshift(t):i.node.arguments[1]=e.objectExpression([t,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([t]))}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.needsComponentVNode=!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=qe(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=Se(o),a=s||o.startsWith("./")||o.startsWith("../");for(let t of r.specifiers){let c=null;(e.isImportSpecifier(t)&&e.isIdentifier(t.local)||e.isImportDefaultSpecifier(t)&&e.isIdentifier(t.local)||e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local))&&(c=t.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),Ge.has(o)&&(e.isImportSpecifier(t)&&e.isIdentifier(t.imported,{name:"action"})&&e.isIdentifier(t.local)?n.serverActionBindings.add(t.local.name):e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local)&&n.serverActionNamespaces.add(t.local.name))}}i.traverse({Function(r){ve(r)},CallExpression(r){Oe(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,a="";if(e.isIdentifier(s)?a=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(a=s.property.name),he.has(a)){let t=r.node.id;if(e.isIdentifier(t))n.signalNames.add(t.name);else if(e.isArrayPattern(t))for(let c of t.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(t))for(let c of t.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 a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),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 a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){s=a;break}if(s){let a=new Set(s.specifiers.filter(t=>e.isImportSpecifier(t)).map(t=>t.imported.name));for(let t of r)a.has(t.imported.name)||s.specifiers.push(t)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Ze(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(t=>e.stringLiteral(t))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){me(i,n,X)},JSXFragment(i,n){me(i,n,P)}}}}function Ze(e,_,k){let $=null;for(let y of e.node.body)if(_.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){$=y;break}if($){let y=new Set($.specifiers.filter(C=>_.isImportSpecifier(C)).map(C=>C.imported.name));for(let C of k)y.has(C.imported.name)||$.specifiers.push(C)}else{let y=_.importDeclaration(k,_.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Ke as default};
1
+ var Be=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ue=new Set(["once","capture","passive"]),He=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ge=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),W=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),qe=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),ge=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),ze=new Set(["For","Show","Switch","Match"]),Ke=new Set(["what-framework/server","what-server","what-server/actions"]);function Se(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function Ze(e){let A=0xcbf29ce484222325n;for(let k=0;k<e.length;k++)A^=BigInt(e.charCodeAt(k)),A=BigInt.asUintN(64,A*0x100000001b3n);return A.toString(36)}function Qe(e,A){let k=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),$=String(A||"").replace(/\\/g,"/").replace(/\/+$/,"");return $&&k.startsWith(`${$}/`)?k.slice($.length+1):k.replace(/^\.\//,"")}function M(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let A=e.split(/\r\n|\n|\r/),k=-1;for(let y=0;y<A.length;y++)/[^ \t]/.test(A[y])&&(k=y);if(k===-1)return"";let $="";for(let y=0;y<A.length;y++){let C=A[y].replace(/\t/g," "),O=y===0,B=y===A.length-1;O||(C=C.replace(/^ +/,"")),B||(C=C.replace(/ +$/,"")),C&&(y!==k&&(C+=" "),$+=C)}return $}function Ye({types:e}){let A=new Set,k=new Set;function $(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(a=>Be.has(a));return{eventName:o,modifiers:s}}function C(i){return i.startsWith("bind:")}function O(i){return i.slice(5)}function B(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,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${a}:${s.line}:${s.column+1}`:a})`)}function D(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&B(n.name)}function R(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function xe(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function be(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function ye(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:ve(n.node.callee,n.scope)}function ve(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?Q(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?Q(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function Q(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let o=i.path.node;if(!n(o))return!1;if(r!==null){let a=o.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let s=i.path.parent;return e.isImportDeclaration(s)&&Se(s.source.value)}function Y(i){return e.isJSXMemberExpression(i)?e.memberExpression(Y(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function we(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let u=0;u<r.properties.length;u++){let E=r.properties[u];if(e.isRestElement(E))return;if(e.isObjectProperty(E)&&!E.computed&&e.isIdentifier(E.key,{name:"children"})){if(o!==-1||!e.isIdentifier(E.value))return;o=u}}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(u=>{let E=u.parentPath;if(!E||!E.isJSXExpressionContainer())return!1;let d=E.parentPath;if(!d||!d.isJSXElement()||!D(d.node))return!1;let l=d.node.openingElement.name;return!(e.isJSXIdentifier(l)&&ze.has(l.name))}))return;let t=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(t.typeAnnotation=r.typeAnnotation),n[0]=t;let c=r.properties.filter((u,E)=>E!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let u=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(u,e.cloneNode(t))])),i.node._whatMovedProps=u}for(let u of s.referencePaths)u.replaceWith(e.memberExpression(e.cloneNode(t),e.identifier("children")));i.scope.crawl()}function Ie(i){return He.has(String(i).toLowerCase())}function _(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}let Ae=new Map([["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"],["acceptCharset","accept-charset"]]);function L(i){return Ae.get(i)||i}function ee(i,n){let r=L(F(i[n]));for(let o=n+1;o<i.length;o+=1){let s=i[o];if(!e.isJSXSpreadAttribute(s)&&L(F(s))===r)return!0}return!1}function F(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 ne(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function Ce(i){return!!i&&i.length>2&&/^on/i.test(i)}function ie(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 J(i,n){return n.has(i)}function _e(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(t){let c=t.init;if(!c||!e.isCallExpression(c))return;let u=c.callee,E="";if(e.isIdentifier(u)?E=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(E=u.property.name),ge.has(E)){let d=t.id;if(e.isIdentifier(d))n.add(d.name);else if(e.isArrayPattern(d))for(let l of d.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(d))for(let l of d.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function s(t){if(e.isObjectPattern(t))for(let c of t.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let t=a.path&&a.path.node;if(t){if(t.params)for(let c of t.params)s(c);t._whatMovedProps&&s(t._whatMovedProps)}a=a.parent}return n}function ke(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&qe.has(i.callee.property.name)}function re(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?W.has(n.object.name):e.isIdentifier(n)?W.has(n.name):!1}function oe(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)||re(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)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)?!0:re(i)?i.arguments.some(o=>w(o,n,r)):i.arguments.length===0&&!ke(i)?!0: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)?J(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 N(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":N(i.left,n);break;case"RestElement":N(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)N(r,n);break;case"ObjectPattern":for(let r of i.properties)N(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function $e(i){let n=new Set;for(let o=1;o<i.params.length;o++)N(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)N(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":N(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 a=o[s];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of N(i.params[0],new Set))n.delete(o);return n}function Fe(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 a of Object.keys(s)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||s.type==="MemberExpression"&&a==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&a==="key"&&!s.computed)continue;let t=s[a];t&&typeof t=="object"&&o(t)}}};return o(i),r}function se(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let a=V(r.consequent,n),t=V(r.alternate,n);if(a||t){let c=e.conditionalExpression(r.test,a||r.consequent,t||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=V(r.right,n);if(a){let t=e.logicalExpression(r.operator,r.left,a);return o?e.arrowFunctionExpression([],t):t}return null}return V(r,n)}function V(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 m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}}else if(e.isFunctionExpression(r)){let m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,a=null;for(let m of s)if(e.isJSXAttribute(m)&&F(m)==="key"){a=m;break}if(!a)return null;let t=_(a.value);if(!t)return null;let c=$e(r);if(Fe(t,c)){let m=e.isIdentifier(t)&&r.params[1]&&e.isIdentifier(r.params[1],{name:t.name});return null}o.openingElement.attributes=s.filter(m=>m!==a);let E=i.callee.object,d=e.arrowFunctionExpression([],E),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),p=e.arrowFunctionExpression([l],e.cloneNode(t,!0));return e.callExpression(e.identifier("_$mapArray"),[d,r,e.objectExpression([e.objectProperty(e.identifier("key"),p),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function U(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(D(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(U)}return!1}function te(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function H(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let o=M(r.value);o&&n.push({kind:"text",text:o});continue}if(e.isJSXFragment(r)){H(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function G(i){if(e.isJSXText(i)){let t=M(i.value);return t?ae(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(D(i))return"";let o=`<${r}`,s=n.attributes.findIndex(t=>e.isJSXSpreadAttribute(t));for(let[t,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||s!==-1&&t>s||ee(n.attributes,t))continue;let u=F(c);if(u==="key"||Ce(u)||u.startsWith("bind:")||u.includes("|"))continue;let E=L(u);if(!c.value)o+=` ${E}`;else if(e.isStringLiteral(c.value))o+=` ${E}="${Me(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&Ie(r))return o+=">",o;if(a)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let c=M(t.value);c&&(o+=ae(c))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)?D(t)?o+="<!--$-->":o+=G(t):e.isJSXFragment(t)&&(o+="<!--$-->".repeat(H(t).length));return o+=`</${r}>`,o}function ae(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Me(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name;if(!R(s,n)){if(s==="For")return Xe(i,n);if(s==="Show")return De(i,n)}if(s==="Switch"&&(!R(s,n)||be(r)))return Pe(i,n);if(D(r))return fe(i,n);let a=o.attributes,t=r.children,c=t.every(U),u=a.every(f=>!te(f)),E=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let x=F(f);return!x?.startsWith("on")&&!x?.startsWith("bind:")});if(c&&u&&E){let f=G(r);if(f){let x=me(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(x),[])}}let d=G(r);if(!d){let f=r.loc,x=n.filename||n.file?.opts?.filename||"<unknown>",h=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${x}${h}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,q(i,n)}let l=me(n,d);n.needsTemplate=!0;let p=n.nextVarId(),m=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier(l),[]))])];return le(m,p,a,n,s),ce(m,p,t,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...m),e.identifier(p)}function q(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,a=o.attributes,t=r.children,c=[];for(let d of a){if(e.isJSXSpreadAttribute(d))continue;let l=F(d),p=_(d.value),m=L(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(m)?e.identifier(m):e.stringLiteral(m),p))}let u=[];for(let d of t)if(e.isJSXText(d)){let l=M(d.value);l&&u.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(d)?e.isJSXEmptyExpression(d.expression)||u.push(d.expression):e.isJSXElement(d)?u.push(X({node:d},n)):e.isJSXFragment(d)&&u.push(P({node:d},n));let E=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),E,...u])}let Ne=new Set(["input","textarea","select","option"]);function le(i,n,r,o,s){function a(E,d){return E==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):E==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):E==="value"&&s&&Ne.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):E==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):E.startsWith("data-")||E.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(E),d])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(E),d]))}let t=!1;function c(){t||(t=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let u=!1;for(let[E,d]of r.entries()){if(e.isJSXSpreadAttribute(d)){u=!0,o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),d.argument])));continue}if(ee(r,E))continue;let l=F(d);if(l!=="key"){if(l==="ref"){let p=_(d.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",p),e.stringLiteral("function")),e.callExpression(e.cloneNode(p),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(p),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!$(l,o)){let p=l.slice(2).toLowerCase(),m=_(d.value);Ge.has(p)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(p),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${p}`)),m)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(p),m])));continue}if(l.startsWith("on")&&(l.includes("|")||$(l,o))){let{eventName:p,modifiers:m}=y(l),f=_(d.value),x=ie(f,m),h=p.slice(2).toLowerCase(),g=m.filter(v=>Ue.has(v)),b=[e.stringLiteral(h),x];if(g.length>0){let v=g.map(S=>e.objectProperty(e.identifier(S),e.booleanLiteral(!0)));b.push(e.objectExpression(v))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),b)));continue}if(C(l)){let p=O(l),m=d.value.expression;o.needsEffect=!0,p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(d.value)){let p=d.value.expression,m=L(l);if(w(p,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let f=o.signalNames&&o.signalNames.fromDestructuredProps,x=e.isIdentifier(p)&&!(f&&f.has(p.name))&&J(p.name,o.signalNames)?e.callExpression(p,[]):p,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(m,x))]);oe(p,o.signalNames,o.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(a(m,p)));continue}u&&i.push(e.expressionStatement(a(L(l),_(d.value))))}}}function z(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(z);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"&&z(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 j(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(z))return i;let t=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let u=e.callExpression(e.identifier(t),[]);return s?e.conditionalExpression(u,i.consequent,i.alternate):e.logicalExpression(i.operator,u,i.right)}function ce(i,n,r,o,s){let a=[],t=0;for(let l of r){if(e.isJSXText(l)){M(l.value)&&t++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:t}),t++;continue}if(e.isJSXElement(l)){let p=l.openingElement.name.name;if(D(l)||p==="For"||p==="Show")a.push({type:"component",child:l,childIndex:t}),t++;else{let m=l.openingElement.attributes.some(te)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&F(f)?.startsWith("on"))||!l.children.every(U);a.push({type:"static",child:l,childIndex:t,hasAnythingDynamic:m}),t++}continue}if(e.isJSXFragment(l))for(let p of H(l))p.kind==="text"?a.push({type:"fragmentText",text:p.text,childIndex:t}):p.kind==="expression"?a.push({type:"expression",child:p.child,childIndex:t}):a.push({type:"component",child:p.child,childIndex:t}),t++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),u=c.length>=2,E=new Map;if(u){let l=null,p=0;for(let m of c){let f=m.childIndex,x=s.nextVarId();E.set(f,x);let h;if(l===null)h=K(n,f);else{h=e.identifier(l);for(let g=p;g<f;g++)h=e.memberExpression(h,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),h)])),l=x,p=f}}function d(l){return E.has(l)?e.identifier(E.get(l)):K(n,l)}for(let l of a){if(l.type==="expression"){let p=l.child.expression,m=d(l.childIndex);s.needsInsert=!0;let f=se(p,s);if(f){s.needsMapArray=!0;let h=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),g=e.isArrowFunctionExpression(f);g&&e.isExpression(f.body)?f.body=j(f.body,i,s):!h&&!g&&(f=j(f,i,s));let b=h||g?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),b,m])));continue}if(e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="mapArray"||p.callee.name==="_$mapArray")){s.needsMapArray=!0,p.callee.name==="mapArray"&&(p.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(w(p,s.signalNames,s.importedIdentifiers)){p=j(p,i,s);let h=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],p),m]);oe(p,s.signalNames,s.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="component"){let p=X({node:l.child},s),m=d(l.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let p;E.has(l.childIndex)?p=E.get(l.childIndex):(p=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),K(n,l.childIndex))]))),le(i,p,l.child.openingElement.attributes,s,l.child.openingElement.name.name),ce(i,p,l.child.children,l.child,s);continue}if(l.type==="fragmentText"){s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),d(l.childIndex)])));continue}}}function K(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 fe(i,n){let{node:r}=i,o=r.openingElement,s=Y(o.name),a=o.attributes,t=r.children,c=null,u=[];for(let h of a){if(e.isJSXAttribute(h)){let g;if(e.isJSXNamespacedName(h.name)?g=`${h.name.namespace.name}:${h.name.name.name}`:g=h.name.name,g&&typeof g=="string"&&g.startsWith("client:")){let b=g.slice(7);h.value?c={type:b,value:h.value.value}:c={type:b};continue}}u.push(h)}function E(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],b=!1;for(let S of t)if(e.isJSXText(S)){let I=M(S.value);I&&g.push(e.stringLiteral(I))}else if(e.isJSXExpressionContainer(S))e.isJSXEmptyExpression(S.expression)||(b=!0,g.push(de(S.expression,n)));else if(e.isJSXElement(S)){let I=S.openingElement.name.name;I!=="For"&&I!=="Show"&&I!=="Switch"&&(b=!0),g.push(X({node:S},n))}else e.isJSXFragment(S)&&(b=!0,g.push(P({node:S},n)));let v=e.arrayExpression(g);if(b){let S=n._pendingSetup?n._pendingSetup.splice(h):[];v=e.arrowFunctionExpression([],S.length>0?e.blockStatement([...S,e.returnStatement(v)]):v)}return v}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=[],b=[],v=()=>{b.length>0&&(g.push(e.objectExpression(b)),b=[])};for(let I of u){if(e.isJSXSpreadAttribute(I)){v(),g.push(I.argument);continue}let T=F(I);if(T==="key")continue;let We=_(I.value);b.push(e.objectProperty(ne(T),We))}let S;return g.length===0?S=e.objectExpression([...b,...h]):(v(),S=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...g,e.objectExpression(h)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),S,E()])}let d=ye(i);d?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],p=[],m=()=>{p.length>0&&(l.push(e.objectExpression(p)),p=[])};for(let h of u){if(e.isJSXSpreadAttribute(h)){m(),l.push(h.argument);continue}let g=F(h);if(g==="key")continue;if(C(g)){let v=O(g),S=h.value.expression;v==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(S),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):v==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(S),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(g.startsWith("on")&&(g.includes("|")||$(g,n))){let{eventName:v,modifiers:S}=y(g),I=_(h.value),T=ie(I,S);p.push(e.objectProperty(e.identifier(v),T));continue}let b=_(h.value);p.push(e.objectProperty(ne(g),b))}m();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let x=E();return e.callExpression(e.identifier(d?"_$componentVNode":"_$createComponent"),[s,f,x])}function Xe(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null,c=null;for(let S of o)if(e.isJSXAttribute(S)){let I=F(S);I==="each"?a=_(S.value):I==="key"?t=_(S.value):I==="fallback"&&(c=_(S.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,q(i,n);let u=null;for(let S of s)if(e.isJSXExpressionContainer(S)&&!e.isJSXEmptyExpression(S.expression)){u=S.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,q(i,n);n.needsMapArray=!0;let E=S=>{let I=[S,u];return t&&I.push(e.objectExpression([e.objectProperty(e.identifier("key"),t)])),e.callExpression(e.identifier("_$mapArray"),I)};if(!c)return E(a);n._pendingSetup||(n._pendingSetup=[]);let d=n.nextForIndex(),l=`_each$${d}`,p=`_for$${d}`,m=`_fb$${d}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let x=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),h=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,h)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(x),e.memberExpression(e.cloneNode(x),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),E(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let g=e.identifier("_parent"),b=e.identifier("_marker"),v=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([g,b],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(v,e.callExpression(e.identifier(p),[e.cloneNode(g),e.cloneNode(b)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(g),e.arrayExpression([e.identifier(m)]),e.cloneNode(b)])),e.returnStatement(e.cloneNode(v))])),e.identifier(p)])}function De(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null;for(let m of o)if(e.isJSXAttribute(m)){let f=F(m);f==="when"?a=_(m.value):f==="fallback"&&(t=_(m.value))}if(!a)throw Z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let m of s)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){c=m.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let m=n._pendingSetup.length,f=[];for(let h of s)if(e.isJSXText(h)){let g=M(h.value);g&&f.push(e.stringLiteral(g))}else e.isJSXElement(h)&&f.push(X({node:h},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let x=n._pendingSetup.splice(m);x.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...x,e.returnStatement(c)])),[]))}let u=pe(a,n),E=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),d=e.isFunction(c),l=d?e.callExpression(c,[e.cloneNode(E)]):c,p=t||e.nullLiteral();if(w(u,n.signalNames,n.importedIdentifiers)){let m=n.nextMemoId();n.needsMemo=!0;let f=d?u:e.unaryExpression("!",e.unaryExpression("!",u));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),u=e.callExpression(e.identifier(m),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(E,u)]),e.returnStatement(e.conditionalExpression(e.cloneNode(E),l,p))]))}function pe(i,n){if(e.isCallExpression(i))return i;if(e.isArrowFunctionExpression(i)&&e.isExpression(i.body))return i.body;let r=n.signalNames&&n.signalNames.fromDestructuredProps,o=a=>r&&r.has(a)||n.importedIdentifiers&&n.importedIdentifiers.has(a);if(e.isIdentifier(i))return o(i.name)?ue(i):n.signalNames&&J(i.name,n.signalNames)?e.callExpression(i,[]):i;let s=Le(i);return s&&o(s.name)?ue(i):i}function Le(i){if(!e.isMemberExpression(i))return null;let n=i;for(;e.isMemberExpression(n);){if(n.computed||!e.isIdentifier(n.property))return null;n=n.object}return e.isIdentifier(n)?n:null}function ue(i){return e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",i),e.stringLiteral("function")),e.callExpression(e.cloneNode(i),[]),e.cloneNode(i))}function je(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let s=M(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(P({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Pe(i,n){let{node:r}=i,o=R(r.openingElement.name.name,n),s=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(o||!R("Match",n));if(!r.children.some(s)&&!xe(r.openingElement.name.name,n))return fe(i,n);let a=f=>{throw Z(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},t=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),F(f)==="fallback"&&(t=_(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){M(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}s(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let u=[];for(let f of c){let x=null;for(let v of f.openingElement.attributes)e.isJSXAttribute(v)&&F(v)==="when"&&(x=_(v.value));x||a('has a <Match> with no "when" prop');let h=n._pendingSetup.length,g=je(f.children,n),b=n._pendingSetup.splice(h);b.length>0&&(g=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...b,e.returnStatement(g)])),[])),u.push([pe(x,n),g])}let E=u.some(([f])=>w(f,n.signalNames,n.importedIdentifiers)),d=t||e.nullLiteral();if(!E){let f=d;for(let x=u.length-1;x>=0;x--)f=e.conditionalExpression(u[x][0],u[x][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=u.length-1;f>=0;f--)l=e.conditionalExpression(u[f][0],e.numericLiteral(f),l);let p=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let m=d;for(let f=u.length-1;f>=0;f--)m=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(p),[]),e.numericLiteral(f)),u[f][1],m);return e.arrowFunctionExpression([],m)}function de(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=se(i,n);if(o){n.needsMapArray=!0;let a=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=j(o.body,r,n),o;if(a)return o;let c=j(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=j(i,r,n),e.arrowFunctionExpression([],i)):i}function P(i,n){let{node:r}=i,o=r.children,s=[];for(let a of o)if(e.isJSXText(a)){let t=M(a.value);t&&s.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||s.push(de(a.expression,n)):e.isJSXElement(a)?s.push(X({node:a},n)):e.isJSXFragment(a)&&s.push(P({node:a},n));return s.length===1?s[0]:e.arrayExpression(s)}function me(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 Ee(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let a=s.get(o);a||(a=_e(i),s.set(o,a)),n.signalNames=a,n._pendingSetup=[];let t=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let u=i,E=!1,d=!1;for(;u&&!u.isStatement();)(u.isArrowFunctionExpression()||u.isFunctionExpression())&&(E=!0),Je(u)&&(d=!0),u=u.parentPath;u&&u.isStatement()&&(u.listKey==="body"||u.listKey==="consequent")&&Array.isArray(u.container)&&!E&&!d?(u.insertBefore(c),i.replaceWith(t)):(c.push(e.returnStatement(t)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(t)}function Te(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 Oe(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 Re(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 he(i,n,r,o,s){let a=i.node.loc?.start||{line:0,column:0},t=`${s}:${a.line}:${a.column+1}`,c=`${s}#${o}`,u=n.serverActionIds.get(r);if(u)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${u.bindingName}" at ${u.source}; conflicts with "${o}" at ${t}.`);let E={id:r,key:c,bindingName:o,filename:s,source:t,loc:a};if(n.serverActionIds.set(r,E),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(E)}catch(d){throw i.buildCodeFrameError(d instanceof Error?d.message:String(d))}}function Ve(i,n){if(!Oe(i,n))return;let r=Te(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=Re(o);if(s.property){s.value!==null&&he(i,n,s.value,r,n.serverActionFilename);return}let a=`wa1_${Ze(`${n.serverActionFilename}#${r}`)}`;he(i,n,a,r,n.serverActionFilename);let t=e.objectProperty(e.identifier("id"),e.stringLiteral(a));o?e.isObjectExpression(o)?o.properties.unshift(t):i.node.arguments[1]=e.objectExpression([t,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([t]))}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.needsComponentVNode=!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=Qe(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=Se(o),a=s||o.startsWith("./")||o.startsWith("../");for(let t of r.specifiers){let c=null;(e.isImportSpecifier(t)&&e.isIdentifier(t.local)||e.isImportDefaultSpecifier(t)&&e.isIdentifier(t.local)||e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local))&&(c=t.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),Ke.has(o)&&(e.isImportSpecifier(t)&&e.isIdentifier(t.imported,{name:"action"})&&e.isIdentifier(t.local)?n.serverActionBindings.add(t.local.name):e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local)&&n.serverActionNamespaces.add(t.local.name))}}i.traverse({Function(r){we(r)},CallExpression(r){Ve(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,a="";if(e.isIdentifier(s)?a=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(a=s.property.name),ge.has(a)){let t=r.node.id;if(e.isIdentifier(t))n.signalNames.add(t.name);else if(e.isArrayPattern(t))for(let c of t.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(t))for(let c of t.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 a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),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 a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){s=a;break}if(s){let a=new Set(s.specifiers.filter(t=>e.isImportSpecifier(t)).map(t=>t.imported.name));for(let t of r)a.has(t.imported.name)||s.specifiers.push(t)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&en(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(t=>e.stringLiteral(t))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Ee(i,n,X)},JSXFragment(i,n){Ee(i,n,P)}}}}function en(e,A,k){let $=null;for(let y of e.node.body)if(A.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){$=y;break}if($){let y=new Set($.specifiers.filter(C=>A.isImportSpecifier(C)).map(C=>C.imported.name));for(let C of k)y.has(C.imported.name)||$.specifiers.push(C)}else{let y=A.importDeclaration(k,A.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Ye as default};
package/dist/index.min.js CHANGED
@@ -1,15 +1,15 @@
1
- var sn=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),an=new Set(["once","capture","passive"]),ln=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),cn=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),se=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),fn=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),Pe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),pn=new Set(["For","Show","Switch","Match"]),un=new Set(["what-framework/server","what-server","what-server/actions"]);function Ne(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function dn(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 mn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),y=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return y&&d.startsWith(`${y}/`)?d.slice(y.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 y="";for(let E=0;E<m.length;E++){let b=m[E].replace(/\t/g," "),w=E===0,C=E===m.length-1;w||(b=b.replace(/^ +/,"")),C||(b=b.replace(/ +$/,"")),b&&(E!==d&&(b+=" "),y+=b)}return y}function ae({types:e}){let m=new Set,d=new Set;function y(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(o=>o!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),t=r[0],o=r.slice(1).filter(a=>sn.has(a));return{eventName:t,modifiers:o}}function b(i){return i.startsWith("bind:")}function w(i){return i.slice(5)}function C(i){return/^[A-Z]/.test(i)}function T(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let t=i?.node;if(t&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(t,r);let o=t?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${o?`${a}:${o.line}:${o.column+1}`:a})`)}function A(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&C(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 W(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:V(n.node.callee,n.scope)}function V(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?B(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?B(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function B(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let t=i.path.node;if(!n(t))return!1;if(r!==null){let a=t.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let o=i.path.parent;return e.isImportDeclaration(o)&&Ne(o.source.value)}function k(i){return e.isJSXMemberExpression(i)?e.memberExpression(k(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function L(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],t=-1;for(let u=0;u<r.properties.length;u++){let x=r.properties[u];if(e.isRestElement(x))return;if(e.isObjectProperty(x)&&!x.computed&&e.isIdentifier(x.key,{name:"children"})){if(t!==-1||!e.isIdentifier(x.value))return;t=u}}if(t===-1)return;let o=i.scope.getBinding(r.properties[t].value.name);if(!o||o.constantViolations.length>0||o.referencePaths.length===0||!o.referencePaths.every(u=>{let x=u.parentPath;if(!x||!x.isJSXExpressionContainer())return!1;let h=x.parentPath;if(!h||!h.isJSXElement()||!A(h.node))return!1;let l=h.node.openingElement.name;return!(e.isJSXIdentifier(l)&&pn.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let c=r.properties.filter((u,x)=>x!==t);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let u=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(u,e.cloneNode(s))])),i.node._whatMovedProps=u}for(let u of o.referencePaths)u.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function X(i){return ln.has(String(i).toLowerCase())}function F(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function U(i){return i==="className"?"class":i==="htmlFor"?"for":i}function ee(i,n){let r=U(R(i[n]));for(let t=n+1;t<i.length;t+=1){let o=i[t];if(!e.isJSXSpreadAttribute(o)&&U(R(o))===r)return!0}return!1}function R(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 te(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function D(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 t of n)switch(t){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 G(i,n){return n.has(i)}function Ve(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function t(s){let c=s.init;if(!c||!e.isCallExpression(c))return;let u=c.callee,x="";if(e.isIdentifier(u)?x=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(x=u.property.name),Pe.has(x)){let h=s.id;if(e.isIdentifier(h))n.add(h.name);else if(e.isArrayPattern(h))for(let l of h.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(h))for(let l of h.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function o(s){if(e.isObjectPattern(s))for(let c of s.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&t(c.path.node);let s=a.path&&a.path.node;if(s){if(s.params)for(let c of s.params)o(c);s._whatMovedProps&&o(s._whatMovedProps)}a=a.parent}return n}function He(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&fn.has(i.callee.property.name)}function ye(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?se.has(n.object.name):e.isIdentifier(n)?se.has(n.name):!1}function Se(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&G(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&G(i.callee.object.name,n)||ye(i))return!1;if(i.arguments.some(t=>O(t,n,r)))return!0}return!1}function O(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&G(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&G(i.callee.object.name,n)?!0:ye(i)?i.arguments.some(t=>O(t,n,r)):i.arguments.length===0&&!He(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(t=>O(t,n,r)):O(i.callee,n,r)||i.arguments.some(t=>O(t,n,r)):e.isIdentifier(i)?G(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(t=>O(t,n,r)):e.isObjectExpression(i)?i.properties.some(t=>e.isObjectProperty(t)&&O(t.value,n,r)):e.isArrayExpression(i)?i.elements.some(t=>t&&O(t,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function z(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":z(i.left,n);break;case"RestElement":z(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)z(r,n);break;case"ObjectPattern":for(let r of i.properties)z(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function Be(i){let n=new Set;for(let t=1;t<i.params.length;t++)z(i.params[t],n);let r=t=>{if(!(!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(r);return}switch(t.type){case"VariableDeclaration":for(let o of t.declarations)z(o.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":t.id&&n.add(t.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":z(t.param,n),r(t.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(t.init),r(t.left),r(t.body);return;default:break}for(let o of Object.keys(t)){if(o==="loc"||o==="start"||o==="end"||o==="type"||o==="leadingComments"||o==="trailingComments"||o==="innerComments")continue;let a=t[o];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let t of z(i.params[0],new Set))n.delete(t);return n}function Ue(i,n){if(n.size===0)return null;let r=null,t=o=>{if(!(r||!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(t);return}if(o.type==="Identifier"){n.has(o.name)&&(r=o.name);return}for(let a of Object.keys(o)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||o.type==="MemberExpression"&&a==="property"&&!o.computed||(o.type==="ObjectProperty"||o.type==="ObjectMethod")&&a==="key"&&!o.computed)continue;let s=o[a];s&&typeof s=="object"&&t(s)}}};return t(i),r}function we(i,n){let r=i,t=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,t=!0),e.isConditionalExpression(r)){let a=oe(r.consequent,n),s=oe(r.alternate,n);if(a||s){let c=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return t?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=oe(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return t?e.arrowFunctionExpression([],s):s}return null}return oe(r,n)}function oe(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 t=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))t=r.body;else if(e.isBlockStatement(r.body)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}}else if(e.isFunctionExpression(r)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}if(!t||!e.isJSXElement(t))return null;let o=t.openingElement.attributes,a=null;for(let g of o)if(e.isJSXAttribute(g)&&R(g)==="key"){a=g;break}if(!a)return null;let s=F(a.value);if(!s)return null;let c=Be(r);if(Ue(s,c)){let g=e.isIdentifier(s)&&r.params[1]&&e.isIdentifier(r.params[1],{name:s.name});return null}t.openingElement.attributes=o.filter(g=>g!==a);let x=i.callee.object,h=e.arrowFunctionExpression([],x),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),p=e.arrowFunctionExpression([l],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[h,r,e.objectExpression([e.objectProperty(e.identifier("key"),p),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function fe(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(A(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let t=r.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(fe)}return!1}function ve(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function pe(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let t=H(r.value);t&&n.push({kind:"text",text:t});continue}if(e.isJSXFragment(r)){pe(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function ue(i){if(e.isJSXText(i)){let s=H(i.value);return s?_e(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(i))return"";let t=`<${r}`,o=n.attributes.findIndex(s=>e.isJSXSpreadAttribute(s));for(let[s,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||o!==-1&&s>o||ee(n.attributes,s))continue;let u=R(c);if(u==="key"||D(u)||u.startsWith("bind:")||u.includes("|"))continue;let x=u;if(u==="className"&&(x="class"),u==="htmlFor"&&(x="for"),!c.value)t+=` ${x}`;else if(e.isStringLiteral(c.value))t+=` ${x}="${Ge(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&X(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of i.children)if(e.isJSXText(s)){let c=H(s.value);c&&(t+=_e(c))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)?A(s)?t+="<!--$-->":t+=ue(s):e.isJSXFragment(s)&&(t+="<!--$-->".repeat(pe(s).length));return t+=`</${r}>`,t}function _e(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ge(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function K(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name;if(!_(o,n)){if(o==="For")return Ke(i,n);if(o==="Show")return Ze(i,n)}if(o==="Switch"&&(!_(o,n)||P(r)))return Qe(i,n);if(A(r))return $e(i,n);let a=t.attributes,s=r.children,c=s.every(fe),u=a.every(f=>!ve(f)),x=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let I=R(f);return!I?.startsWith("on")&&!I?.startsWith("bind:")});if(c&&u&&x){let f=ue(r);if(f){let I=Le(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(I),[])}}let h=ue(r);if(!h){let f=r.loc,I=n.filename||n.file?.opts?.filename||"<unknown>",S=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${o}> at ${I}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,de(i,n)}let l=Le(n,h);n.needsTemplate=!0;let p=n.nextVarId(),g=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier(l),[]))])];return ke(g,p,a,n,o),Ce(g,p,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...g),e.identifier(p)}function de(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name,a=t.attributes,s=r.children,c=[];for(let h of a){if(e.isJSXSpreadAttribute(h))continue;let l=R(h),p=F(h.value),g=U(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),p))}let u=[];for(let h of s)if(e.isJSXText(h)){let l=H(h.value);l&&u.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||u.push(h.expression):e.isJSXElement(h)?u.push(K({node:h},n)):e.isJSXFragment(h)&&u.push(ne({node:h},n));let x=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(o),x,...u])}let ze=new Set(["input","textarea","select","option"]);function ke(i,n,r,t,o){function a(x,h){return x==="class"?(t.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),h])):x==="style"?(t.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),h])):x==="value"&&o&&ze.has(o)?(t.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),h])):x==="checked"&&o==="input"?(t.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),h])):x.startsWith("data-")||x.startsWith("aria-")?(t.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(x),h])):(t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(x),h]))}let s=!1;function c(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let u=!1;for(let[x,h]of r.entries()){if(e.isJSXSpreadAttribute(h)){u=!0,t.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),h.argument])));continue}if(ee(r,x))continue;let l=R(h);if(l!=="key"){if(l==="ref"){let p=F(h.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",p),e.stringLiteral("function")),e.callExpression(e.cloneNode(p),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(p),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!y(l,t)){let p=l.slice(2).toLowerCase(),g=F(h.value);cn.has(p)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(p),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${p}`)),g)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(p),g])));continue}if(l.startsWith("on")&&(l.includes("|")||y(l,t))){let{eventName:p,modifiers:g}=E(l),f=F(h.value),I=Z(f,g),S=p.slice(2).toLowerCase(),v=g.filter(N=>an.has(N)),M=[e.stringLiteral(S),I];if(v.length>0){let N=v.map($=>e.objectProperty(e.identifier($),e.booleanLiteral(!0)));M.push(e.objectExpression(N))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),M)));continue}if(b(l)){let p=w(l),g=h.value.expression;t.needsEffect=!0,p==="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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):p==="checked"&&(t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(h.value)){let p=h.value.expression,g=U(l);if(O(p,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let f=t.signalNames&&t.signalNames.fromDestructuredProps,I=e.isIdentifier(p)&&!(f&&f.has(p.name))&&(G(p.name,t.signalNames)||t.importedIdentifiers&&t.importedIdentifiers.has(p.name))?e.callExpression(p,[]):p,S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(g,I))]);Se(p,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: effect 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(a(g,p)));continue}u&&i.push(e.expressionStatement(a(U(l),F(h.value))))}}}function me(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(me);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"&&me(r))return!0}return!1}function qe(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 Y(i,n,r){let t=null,o=!1;if(e.isConditionalExpression(i))t=i.test,o=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))t=i.left;else return i;if(!O(t,r.signalNames,r.importedIdentifiers)||!(o?[i.consequent,i.alternate]:[i.right]).some(me))return i;let s=r.nextMemoId();r.needsMemo=!0;let c=o?e.unaryExpression("!",e.unaryExpression("!",t)):t;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let u=e.callExpression(e.identifier(s),[]);return o?e.conditionalExpression(u,i.consequent,i.alternate):e.logicalExpression(i.operator,u,i.right)}function Ce(i,n,r,t,o){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let p=l.openingElement.name.name;if(A(l)||p==="For"||p==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let g=l.openingElement.attributes.some(ve)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&R(f)?.startsWith("on"))||!l.children.every(fe);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:g}),s++}continue}if(e.isJSXFragment(l))for(let p of pe(l))p.kind==="text"?a.push({type:"fragmentText",text:p.text,childIndex:s}):p.kind==="expression"?a.push({type:"expression",child:p.child,childIndex:s}):a.push({type:"component",child:p.child,childIndex:s}),s++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),u=c.length>=2,x=new Map;if(u){let l=null,p=0;for(let g of c){let f=g.childIndex,I=o.nextVarId();x.set(f,I);let S;if(l===null)S=he(n,f);else{S=e.identifier(l);for(let v=p;v<f;v++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(I),S)])),l=I,p=f}}function h(l){return x.has(l)?e.identifier(x.get(l)):he(n,l)}for(let l of a){if(l.type==="expression"){let p=l.child.expression,g=h(l.childIndex);o.needsInsert=!0;let f=we(p,o);if(f){o.needsMapArray=!0;let S=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),v=e.isArrowFunctionExpression(f);v&&e.isExpression(f.body)?f.body=Y(f.body,i,o):!S&&!v&&(f=Y(f,i,o));let M=S||v?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,g])));continue}if(e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="mapArray"||p.callee.name==="_$mapArray")){o.needsMapArray=!0,p.callee.name==="mapArray"&&(p.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,g])));continue}if(O(p,o.signalNames,o.importedIdentifiers)){p=Y(p,i,o);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],p),g]);Se(p,o.signalNames,o.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),p,g])));continue}if(l.type==="component"){let p=K({node:l.child},o),g=h(l.childIndex);o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,g])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let p;x.has(l.childIndex)?p=x.get(l.childIndex):(p=o.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),he(n,l.childIndex))]))),ke(i,p,l.child.openingElement.attributes,o,l.child.openingElement.name.name),Ce(i,p,l.child.children,l.child,o);continue}if(l.type==="fragmentText"){o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),h(l.childIndex)])));continue}}}function he(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 t=0;t<n;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function $e(i,n){let{node:r}=i,t=r.openingElement,o=k(t.name),a=t.attributes,s=r.children,c=null,u=[];for(let S of a){if(e.isJSXAttribute(S)){let v;if(e.isJSXNamespacedName(S.name)?v=`${S.name.namespace.name}:${S.name.name.name}`:v=S.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let M=v.slice(7);S.value?c={type:M,value:S.value.value}:c={type:M};continue}}u.push(S)}function x(){let S=n._pendingSetup?n._pendingSetup.length:0,v=[],M=!1;for(let $ of s)if(e.isJSXText($)){let j=H($.value);j&&v.push(e.stringLiteral(j))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(M=!0,v.push(Ae($.expression,n)));else if(e.isJSXElement($)){let j=$.openingElement.name.name;j!=="For"&&j!=="Show"&&j!=="Switch"&&(M=!0),v.push(K({node:$},n))}else e.isJSXFragment($)&&(M=!0,v.push(ne({node:$},n)));let N=e.arrayExpression(v);if(M){let $=n._pendingSetup?n._pendingSetup.splice(S):[];N=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(N)]):N)}return N}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let S=[e.objectProperty(e.identifier("component"),o),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&S.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let v=[],M=[],N=()=>{M.length>0&&(v.push(e.objectExpression(M)),M=[])};for(let j of u){if(e.isJSXSpreadAttribute(j)){N(),v.push(j.argument);continue}let ie=R(j);if(ie==="key")continue;let on=F(j.value);M.push(e.objectProperty(te(ie),on))}let $;return v.length===0?$=e.objectExpression([...M,...S]):(N(),$=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...v,e.objectExpression(S)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),$,x()])}let h=W(i);h?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],p=[],g=()=>{p.length>0&&(l.push(e.objectExpression(p)),p=[])};for(let S of u){if(e.isJSXSpreadAttribute(S)){g(),l.push(S.argument);continue}let v=R(S);if(v==="key")continue;if(b(v)){let N=w(v),$=S.value.expression;N==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):N==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||y(v,n))){let{eventName:N,modifiers:$}=E(v),j=F(S.value),ie=Z(j,$);p.push(e.objectProperty(e.identifier(N),ie));continue}let M=F(S.value);p.push(e.objectProperty(te(v),M))}g();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let I=x();return e.callExpression(e.identifier(h?"_$componentVNode":"_$createComponent"),[o,f,I])}function Ke(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null,c=null;for(let $ of t)if(e.isJSXAttribute($)){let j=R($);j==="each"?a=F($.value):j==="key"?s=F($.value):j==="fallback"&&(c=F($.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,de(i,n);let u=null;for(let $ of o)if(e.isJSXExpressionContainer($)&&!e.isJSXEmptyExpression($.expression)){u=$.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,de(i,n);n.needsMapArray=!0;let x=$=>{let j=[$,u];return s&&j.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),j)};if(!c)return x(a);n._pendingSetup||(n._pendingSetup=[]);let h=n.nextForIndex(),l=`_each$${h}`,p=`_for$${h}`,g=`_fb$${h}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let I=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(I,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(I),e.memberExpression(e.cloneNode(I),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),x(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let v=e.identifier("_parent"),M=e.identifier("_marker"),N=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([v,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(N,e.callExpression(e.identifier(p),[e.cloneNode(v),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(v),e.arrayExpression([e.identifier(g)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(N))])),e.identifier(p)])}function Ze(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null;for(let g of t)if(e.isJSXAttribute(g)){let f=R(g);f==="when"?a=F(g.value):f==="fallback"&&(s=F(g.value))}if(!a)throw T(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let g of o)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){c=g.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let g=n._pendingSetup.length,f=[];for(let S of o)if(e.isJSXText(S)){let v=H(S.value);v&&f.push(e.stringLiteral(v))}else e.isJSXElement(S)&&f.push(K({node:S},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let I=n._pendingSetup.splice(g);I.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...I,e.returnStatement(c)])),[]))}let u=Ie(a,n),x=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),h=e.isFunction(c),l=h?e.callExpression(c,[e.cloneNode(x)]):c,p=s||e.nullLiteral();if(O(u,n.signalNames,n.importedIdentifiers)){let g=n.nextMemoId();n.needsMemo=!0;let f=h?u:e.unaryExpression("!",e.unaryExpression("!",u));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),u=e.callExpression(e.identifier(g),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,u)]),e.returnStatement(e.conditionalExpression(e.cloneNode(x),l,p))]))}function Ie(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&G(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Ye(i,n){let r=[];for(let t of i)if(e.isJSXText(t)){let o=H(t.value);o&&r.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||r.push(t.expression):e.isJSXElement(t)?r.push(K({node:t},n)):e.isJSXFragment(t)&&r.push(ne({node:t},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Qe(i,n){let{node:r}=i,t=_(r.openingElement.name.name,n),o=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(t||!_("Match",n));if(!r.children.some(o)&&!J(r.openingElement.name.name,n))return $e(i,n);let a=f=>{throw T(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),R(f)==="fallback"&&(s=F(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){H(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}o(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let u=[];for(let f of c){let I=null;for(let N of f.openingElement.attributes)e.isJSXAttribute(N)&&R(N)==="when"&&(I=F(N.value));I||a('has a <Match> with no "when" prop');let S=n._pendingSetup.length,v=Ye(f.children,n),M=n._pendingSetup.splice(S);M.length>0&&(v=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(v)])),[])),u.push([Ie(I,n),v])}let x=u.some(([f])=>O(f,n.signalNames,n.importedIdentifiers)),h=s||e.nullLiteral();if(!x){let f=h;for(let I=u.length-1;I>=0;I--)f=e.conditionalExpression(u[I][0],u[I][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=u.length-1;f>=0;f--)l=e.conditionalExpression(u[f][0],e.numericLiteral(f),l);let p=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let g=h;for(let f=u.length-1;f>=0;f--)g=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(p),[]),e.numericLiteral(f)),u[f][1],g);return e.arrowFunctionExpression([],g)}function Ae(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,t=we(i,n);if(t){n.needsMapArray=!0;let a=e.isCallExpression(t)&&e.isIdentifier(t.callee)&&(t.callee.name==="_$mapArray"||t.callee.name==="mapArray");if(e.isArrowFunctionExpression(t)&&e.isExpression(t.body))return t.body=Y(t.body,r,n),t;if(a)return t;let c=Y(t,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=Y(i,r,n),e.arrowFunctionExpression([],i)):i}function ne(i,n){let{node:r}=i,t=r.children,o=[];for(let a of t)if(e.isJSXText(a)){let s=H(a.value);s&&o.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||o.push(Ae(a.expression,n)):e.isJSXElement(a)?o.push(K({node:a},n)):e.isJSXFragment(a)&&o.push(ne({node:a},n));return o.length===1?o[0]:e.arrayExpression(o)}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 Me(i,n,r){let t=i.scope,o=n._signalNamesCache;o||(o=n._signalNamesCache=new WeakMap);let a=o.get(t);a||(a=Ve(i),o.set(t,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let u=i,x=!1,h=!1;for(;u&&!u.isStatement();)(u.isArrowFunctionExpression()||u.isFunctionExpression())&&(x=!0),qe(u)&&(h=!0),u=u.parentPath;u&&u.isStatement()&&(u.listKey==="body"||u.listKey==="consequent")&&Array.isArray(u.container)&&!x&&!h?(u.insertBefore(c),i.replaceWith(s)):(c.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(s)}function en(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 nn(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 rn(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,t,o){let a=i.node.loc?.start||{line:0,column:0},s=`${o}:${a.line}:${a.column+1}`,c=`${o}#${t}`,u=n.serverActionIds.get(r);if(u)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${u.bindingName}" at ${u.source}; conflicts with "${t}" at ${s}.`);let x={id:r,key:c,bindingName:t,filename:o,source:s,loc:a};if(n.serverActionIds.set(r,x),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(x)}catch(h){throw i.buildCodeFrameError(h instanceof Error?h.message:String(h))}}function tn(i,n){if(!nn(i,n))return;let r=en(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 t=i.node.arguments[1],o=rn(t);if(o.property){o.value!==null&&Fe(i,n,o.value,r,n.serverActionFilename);return}let a=`wa1_${dn(`${n.serverActionFilename}#${r}`)}`;Fe(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));t?e.isObjectExpression(t)?t.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(t)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsComponentVNode=!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=mn(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 t=r.source.value,o=Ne(t),a=o||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let c=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(c=s.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),o?n.whatImports.add(c):t.startsWith(".")||n.foreignImports.add(c)),un.has(t)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){L(r)},CallExpression(r){tn(r,n)},VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let o=t.callee,a="";if(e.isIdentifier(o)?a=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(a=o.property.name),Pe.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let c of s.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let o of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(o.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(n.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let o=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){o=a;break}if(o){let a=new Set(o.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||o.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&hn(i,e,t),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let o=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[o]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Me(i,n,K)},JSXFragment(i,n){Me(i,n,ne)}}}}function hn(e,m,d){let y=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){y=E;break}if(y){let E=new Set(y.specifiers.filter(b=>m.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of d)E.has(b.imported.name)||y.specifiers.push(b)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import Q from"path";import{createRequire as $n}from"node:module";import{transformSync as In}from"@babel/core";import re from"fs";import q from"path";var Oe=new Set([".jsx",".tsx",".js",".ts"]),gn=new Set(["_layout","_error","_loading","_404"]);function Je(e){let m=[],d=[],y=[];function E(w,C=""){if(!re.existsSync(w))return;let T=re.readdirSync(w,{withFileTypes:!0});for(let A of T){let _=q.join(w,A.name);if(A.isDirectory()){if(A.name.match(/^\((.+)\)$/)){E(_,C);continue}if(A.name==="api"&&C===""){b(_,"/api");continue}E(_,C+"/"+le(A.name));continue}let J=q.extname(A.name);if(!Oe.has(J))continue;let P=q.basename(A.name,J);if(P==="_layout"){d.push({filePath:_,urlPrefix:C||"/"});continue}if(gn.has(P))continue;let W=le(P),V=P==="index"?C||"/":C+"/"+W;m.push({filePath:_,routePath:je(V),isDynamic:V.includes(":")||V.includes("*")})}}function b(w,C){if(!re.existsSync(w))return;let T=re.readdirSync(w,{withFileTypes:!0});for(let A of T){let _=q.join(w,A.name);if(A.isDirectory()){b(_,C+"/"+le(A.name));continue}let J=q.extname(A.name);if(!Oe.has(J))continue;let P=q.basename(A.name,J),W=le(P),V=P==="index"?C:C+"/"+W;y.push({filePath:_,routePath:je(V)})}}return E(e),m.sort((w,C)=>{let T=De(w.routePath),A=De(C.routePath);return T-A}),{pages:m,layouts:d,apiRoutes:y}}function le(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function je(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function De(e){return e.includes("*")?100:e.includes(":")?10:0}var En=/export\s+const\s+page\s*=\s*\{/;function Xe(e,m={}){let d=En.exec(e);if(!d)return{mode:"client"};let y=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(Sn(e,y))}}catch(E){return xn(E,m.filePath),{mode:"client"}}}function xn(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
1
+ var cn=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),fn=new Set(["once","capture","passive"]),un=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),pn=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),se=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),dn=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),Oe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),mn=new Set(["For","Show","Switch","Match"]),hn=new Set(["what-framework/server","what-server","what-server/actions"]);function je(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function gn(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(/[?#].*$/,""),y=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return y&&d.startsWith(`${y}/`)?d.slice(y.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 y="";for(let E=0;E<m.length;E++){let b=m[E].replace(/\t/g," "),w=E===0,C=E===m.length-1;w||(b=b.replace(/^ +/,"")),C||(b=b.replace(/ +$/,"")),b&&(E!==d&&(b+=" "),y+=b)}return y}function ae({types:e}){let m=new Set,d=new Set;function y(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(o=>o!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),t=r[0],o=r.slice(1).filter(a=>cn.has(a));return{eventName:t,modifiers:o}}function b(i){return i.startsWith("bind:")}function w(i){return i.slice(5)}function C(i){return/^[A-Z]/.test(i)}function D(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let t=i?.node;if(t&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(t,r);let o=t?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${o?`${a}:${o.line}:${o.column+1}`:a})`)}function A(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&C(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 W(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:V(n.node.callee,n.scope)}function V(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?B(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?B(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function B(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let t=i.path.node;if(!n(t))return!1;if(r!==null){let a=t.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let o=i.path.parent;return e.isImportDeclaration(o)&&je(o.source.value)}function k(i){return e.isJSXMemberExpression(i)?e.memberExpression(k(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function L(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],t=-1;for(let p=0;p<r.properties.length;p++){let x=r.properties[p];if(e.isRestElement(x))return;if(e.isObjectProperty(x)&&!x.computed&&e.isIdentifier(x.key,{name:"children"})){if(t!==-1||!e.isIdentifier(x.value))return;t=p}}if(t===-1)return;let o=i.scope.getBinding(r.properties[t].value.name);if(!o||o.constantViolations.length>0||o.referencePaths.length===0||!o.referencePaths.every(p=>{let x=p.parentPath;if(!x||!x.isJSXExpressionContainer())return!1;let h=x.parentPath;if(!h||!h.isJSXElement()||!A(h.node))return!1;let l=h.node.openingElement.name;return!(e.isJSXIdentifier(l)&&mn.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let c=r.properties.filter((p,x)=>x!==t);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(s))])),i.node._whatMovedProps=p}for(let p of o.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function R(i){return un.has(String(i).toLowerCase())}function F(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}let Q=new Map([["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"],["acceptCharset","accept-charset"]]);function U(i){return Q.get(i)||i}function te(i,n){let r=U(X(i[n]));for(let t=n+1;t<i.length;t+=1){let o=i[t];if(!e.isJSXSpreadAttribute(o)&&U(X(o))===r)return!0}return!1}function X(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function O(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function ee(i){return!!i&&i.length>2&&/^on/i.test(i)}function fe(i,n){if(n.length===0)return i;let r=i;for(let t of n)switch(t){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 q(i,n){return n.has(i)}function Be(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function t(s){let c=s.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,x="";if(e.isIdentifier(p)?x=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(x=p.property.name),Oe.has(x)){let h=s.id;if(e.isIdentifier(h))n.add(h.name);else if(e.isArrayPattern(h))for(let l of h.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(h))for(let l of h.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function o(s){if(e.isObjectPattern(s))for(let c of s.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&t(c.path.node);let s=a.path&&a.path.node;if(s){if(s.params)for(let c of s.params)o(c);s._whatMovedProps&&o(s._whatMovedProps)}a=a.parent}return n}function Ue(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&dn.has(i.callee.property.name)}function Se(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?se.has(n.object.name):e.isIdentifier(n)?se.has(n.name):!1}function we(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)||Se(i))return!1;if(i.arguments.some(t=>j(t,n,r)))return!0}return!1}function j(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)?!0:Se(i)?i.arguments.some(t=>j(t,n,r)):i.arguments.length===0&&!Ue(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(t=>j(t,n,r)):j(i.callee,n,r)||i.arguments.some(t=>j(t,n,r)):e.isIdentifier(i)?q(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?j(i.object,n,r):e.isConditionalExpression(i)?j(i.test,n,r)||j(i.consequent,n,r)||j(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?j(i.left,n,r)||j(i.right,n,r):e.isUnaryExpression(i)?j(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(t=>j(t,n,r)):e.isObjectExpression(i)?i.properties.some(t=>e.isObjectProperty(t)&&j(t.value,n,r)):e.isArrayExpression(i)?i.elements.some(t=>t&&j(t,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function G(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":G(i.left,n);break;case"RestElement":G(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)G(r,n);break;case"ObjectPattern":for(let r of i.properties)G(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function Ge(i){let n=new Set;for(let t=1;t<i.params.length;t++)G(i.params[t],n);let r=t=>{if(!(!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(r);return}switch(t.type){case"VariableDeclaration":for(let o of t.declarations)G(o.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":t.id&&n.add(t.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":G(t.param,n),r(t.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(t.init),r(t.left),r(t.body);return;default:break}for(let o of Object.keys(t)){if(o==="loc"||o==="start"||o==="end"||o==="type"||o==="leadingComments"||o==="trailingComments"||o==="innerComments")continue;let a=t[o];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let t of G(i.params[0],new Set))n.delete(t);return n}function ze(i,n){if(n.size===0)return null;let r=null,t=o=>{if(!(r||!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(t);return}if(o.type==="Identifier"){n.has(o.name)&&(r=o.name);return}for(let a of Object.keys(o)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||o.type==="MemberExpression"&&a==="property"&&!o.computed||(o.type==="ObjectProperty"||o.type==="ObjectMethod")&&a==="key"&&!o.computed)continue;let s=o[a];s&&typeof s=="object"&&t(s)}}};return t(i),r}function ve(i,n){let r=i,t=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,t=!0),e.isConditionalExpression(r)){let a=oe(r.consequent,n),s=oe(r.alternate,n);if(a||s){let c=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return t?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=oe(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return t?e.arrowFunctionExpression([],s):s}return null}return oe(r,n)}function oe(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 t=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))t=r.body;else if(e.isBlockStatement(r.body)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}}else if(e.isFunctionExpression(r)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}if(!t||!e.isJSXElement(t))return null;let o=t.openingElement.attributes,a=null;for(let g of o)if(e.isJSXAttribute(g)&&X(g)==="key"){a=g;break}if(!a)return null;let s=F(a.value);if(!s)return null;let c=Ge(r);if(ze(s,c)){let g=e.isIdentifier(s)&&r.params[1]&&e.isIdentifier(r.params[1],{name:s.name});return null}t.openingElement.attributes=o.filter(g=>g!==a);let x=i.callee.object,h=e.arrowFunctionExpression([],x),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),u=e.arrowFunctionExpression([l],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[h,r,e.objectExpression([e.objectProperty(e.identifier("key"),u),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function ue(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(A(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let t=r.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(ue)}return!1}function _e(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function pe(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let t=H(r.value);t&&n.push({kind:"text",text:t});continue}if(e.isJSXFragment(r)){pe(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function de(i){if(e.isJSXText(i)){let s=H(i.value);return s?ke(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(i))return"";let t=`<${r}`,o=n.attributes.findIndex(s=>e.isJSXSpreadAttribute(s));for(let[s,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||o!==-1&&s>o||te(n.attributes,s))continue;let p=X(c);if(p==="key"||ee(p)||p.startsWith("bind:")||p.includes("|"))continue;let x=U(p);if(!c.value)t+=` ${x}`;else if(e.isStringLiteral(c.value))t+=` ${x}="${qe(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&R(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of i.children)if(e.isJSXText(s)){let c=H(s.value);c&&(t+=ke(c))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)?A(s)?t+="<!--$-->":t+=de(s):e.isJSXFragment(s)&&(t+="<!--$-->".repeat(pe(s).length));return t+=`</${r}>`,t}function ke(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function qe(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function K(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name;if(!_(o,n)){if(o==="For")return Ye(i,n);if(o==="Show")return Qe(i,n)}if(o==="Switch"&&(!_(o,n)||P(r)))return rn(i,n);if(A(r))return Ie(i,n);let a=t.attributes,s=r.children,c=s.every(ue),p=a.every(f=>!_e(f)),x=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let I=X(f);return!I?.startsWith("on")&&!I?.startsWith("bind:")});if(c&&p&&x){let f=de(r);if(f){let I=Fe(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(I),[])}}let h=de(r);if(!h){let f=r.loc,I=n.filename||n.file?.opts?.filename||"<unknown>",S=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${o}> at ${I}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,me(i,n)}let l=Fe(n,h);n.needsTemplate=!0;let u=n.nextVarId(),g=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier(l),[]))])];return Ce(g,u,a,n,o),$e(g,u,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...g),e.identifier(u)}function me(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name,a=t.attributes,s=r.children,c=[];for(let h of a){if(e.isJSXSpreadAttribute(h))continue;let l=X(h),u=F(h.value),g=U(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),u))}let p=[];for(let h of s)if(e.isJSXText(h)){let l=H(h.value);l&&p.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||p.push(h.expression):e.isJSXElement(h)?p.push(K({node:h},n)):e.isJSXFragment(h)&&p.push(ne({node:h},n));let x=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(o),x,...p])}let Ke=new Set(["input","textarea","select","option"]);function Ce(i,n,r,t,o){function a(x,h){return x==="class"?(t.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),h])):x==="style"?(t.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),h])):x==="value"&&o&&Ke.has(o)?(t.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),h])):x==="checked"&&o==="input"?(t.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),h])):x.startsWith("data-")||x.startsWith("aria-")?(t.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(x),h])):(t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(x),h]))}let s=!1;function c(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let p=!1;for(let[x,h]of r.entries()){if(e.isJSXSpreadAttribute(h)){p=!0,t.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),h.argument])));continue}if(te(r,x))continue;let l=X(h);if(l!=="key"){if(l==="ref"){let u=F(h.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(l.startsWith("on")&&!l.includes("|")&&!y(l,t)){let u=l.slice(2).toLowerCase(),g=F(h.value);pn.has(u)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),g)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),g])));continue}if(l.startsWith("on")&&(l.includes("|")||y(l,t))){let{eventName:u,modifiers:g}=E(l),f=F(h.value),I=fe(f,g),S=u.slice(2).toLowerCase(),v=g.filter(N=>fn.has(N)),M=[e.stringLiteral(S),I];if(v.length>0){let N=v.map($=>e.objectProperty(e.identifier($),e.booleanLiteral(!0)));M.push(e.objectExpression(N))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),M)));continue}if(b(l)){let u=w(l),g=h.value.expression;t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(h.value)){let u=h.value.expression,g=U(l);if(j(u,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let f=t.signalNames&&t.signalNames.fromDestructuredProps,I=e.isIdentifier(u)&&!(f&&f.has(u.name))&&q(u.name,t.signalNames)?e.callExpression(u,[]):u,S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(g,I))]);we(u,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: effect 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(a(g,u)));continue}p&&i.push(e.expressionStatement(a(U(l),F(h.value))))}}}function he(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(he);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"&&he(r))return!0}return!1}function Ze(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 Z(i,n,r){let t=null,o=!1;if(e.isConditionalExpression(i))t=i.test,o=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))t=i.left;else return i;if(!j(t,r.signalNames,r.importedIdentifiers)||!(o?[i.consequent,i.alternate]:[i.right]).some(he))return i;let s=r.nextMemoId();r.needsMemo=!0;let c=o?e.unaryExpression("!",e.unaryExpression("!",t)):t;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(s),[]);return o?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function $e(i,n,r,t,o){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let u=l.openingElement.name.name;if(A(l)||u==="For"||u==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let g=l.openingElement.attributes.some(_e)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&X(f)?.startsWith("on"))||!l.children.every(ue);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:g}),s++}continue}if(e.isJSXFragment(l))for(let u of pe(l))u.kind==="text"?a.push({type:"fragmentText",text:u.text,childIndex:s}):u.kind==="expression"?a.push({type:"expression",child:u.child,childIndex:s}):a.push({type:"component",child:u.child,childIndex:s}),s++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),p=c.length>=2,x=new Map;if(p){let l=null,u=0;for(let g of c){let f=g.childIndex,I=o.nextVarId();x.set(f,I);let S;if(l===null)S=ge(n,f);else{S=e.identifier(l);for(let v=u;v<f;v++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(I),S)])),l=I,u=f}}function h(l){return x.has(l)?e.identifier(x.get(l)):ge(n,l)}for(let l of a){if(l.type==="expression"){let u=l.child.expression,g=h(l.childIndex);o.needsInsert=!0;let f=ve(u,o);if(f){o.needsMapArray=!0;let S=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),v=e.isArrowFunctionExpression(f);v&&e.isExpression(f.body)?f.body=Z(f.body,i,o):!S&&!v&&(f=Z(f,i,o));let M=S||v?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,g])));continue}if(e.isCallExpression(u)&&e.isIdentifier(u.callee)&&(u.callee.name==="mapArray"||u.callee.name==="_$mapArray")){o.needsMapArray=!0,u.callee.name==="mapArray"&&(u.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(j(u,o.signalNames,o.importedIdentifiers)){u=Z(u,i,o);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],u),g]);we(u,o.signalNames,o.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),u,g])));continue}if(l.type==="component"){let u=K({node:l.child},o),g=h(l.childIndex);o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let u;x.has(l.childIndex)?u=x.get(l.childIndex):(u=o.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),ge(n,l.childIndex))]))),Ce(i,u,l.child.openingElement.attributes,o,l.child.openingElement.name.name),$e(i,u,l.child.children,l.child,o);continue}if(l.type==="fragmentText"){o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),h(l.childIndex)])));continue}}}function ge(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 t=0;t<n;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function Ie(i,n){let{node:r}=i,t=r.openingElement,o=k(t.name),a=t.attributes,s=r.children,c=null,p=[];for(let S of a){if(e.isJSXAttribute(S)){let v;if(e.isJSXNamespacedName(S.name)?v=`${S.name.namespace.name}:${S.name.name.name}`:v=S.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let M=v.slice(7);S.value?c={type:M,value:S.value.value}:c={type:M};continue}}p.push(S)}function x(){let S=n._pendingSetup?n._pendingSetup.length:0,v=[],M=!1;for(let $ of s)if(e.isJSXText($)){let T=H($.value);T&&v.push(e.stringLiteral(T))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(M=!0,v.push(Me($.expression,n)));else if(e.isJSXElement($)){let T=$.openingElement.name.name;T!=="For"&&T!=="Show"&&T!=="Switch"&&(M=!0),v.push(K({node:$},n))}else e.isJSXFragment($)&&(M=!0,v.push(ne({node:$},n)));let N=e.arrayExpression(v);if(M){let $=n._pendingSetup?n._pendingSetup.splice(S):[];N=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(N)]):N)}return N}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let S=[e.objectProperty(e.identifier("component"),o),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&S.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let v=[],M=[],N=()=>{M.length>0&&(v.push(e.objectExpression(M)),M=[])};for(let T of p){if(e.isJSXSpreadAttribute(T)){N(),v.push(T.argument);continue}let ie=X(T);if(ie==="key")continue;let ln=F(T.value);M.push(e.objectProperty(O(ie),ln))}let $;return v.length===0?$=e.objectExpression([...M,...S]):(N(),$=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...v,e.objectExpression(S)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),$,x()])}let h=W(i);h?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],u=[],g=()=>{u.length>0&&(l.push(e.objectExpression(u)),u=[])};for(let S of p){if(e.isJSXSpreadAttribute(S)){g(),l.push(S.argument);continue}let v=X(S);if(v==="key")continue;if(b(v)){let N=w(v),$=S.value.expression;N==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):N==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||y(v,n))){let{eventName:N,modifiers:$}=E(v),T=F(S.value),ie=fe(T,$);u.push(e.objectProperty(e.identifier(N),ie));continue}let M=F(S.value);u.push(e.objectProperty(O(v),M))}g();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let I=x();return e.callExpression(e.identifier(h?"_$componentVNode":"_$createComponent"),[o,f,I])}function Ye(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null,c=null;for(let $ of t)if(e.isJSXAttribute($)){let T=X($);T==="each"?a=F($.value):T==="key"?s=F($.value):T==="fallback"&&(c=F($.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,me(i,n);let p=null;for(let $ of o)if(e.isJSXExpressionContainer($)&&!e.isJSXEmptyExpression($.expression)){p=$.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,me(i,n);n.needsMapArray=!0;let x=$=>{let T=[$,p];return s&&T.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),T)};if(!c)return x(a);n._pendingSetup||(n._pendingSetup=[]);let h=n.nextForIndex(),l=`_each$${h}`,u=`_for$${h}`,g=`_fb$${h}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let I=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(I,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(I),e.memberExpression(e.cloneNode(I),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),x(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let v=e.identifier("_parent"),M=e.identifier("_marker"),N=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([v,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(N,e.callExpression(e.identifier(u),[e.cloneNode(v),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(v),e.arrayExpression([e.identifier(g)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(N))])),e.identifier(u)])}function Qe(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null;for(let g of t)if(e.isJSXAttribute(g)){let f=X(g);f==="when"?a=F(g.value):f==="fallback"&&(s=F(g.value))}if(!a)throw D(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let g of o)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){c=g.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let g=n._pendingSetup.length,f=[];for(let S of o)if(e.isJSXText(S)){let v=H(S.value);v&&f.push(e.stringLiteral(v))}else e.isJSXElement(S)&&f.push(K({node:S},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let I=n._pendingSetup.splice(g);I.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...I,e.returnStatement(c)])),[]))}let p=Ae(a,n),x=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),h=e.isFunction(c),l=h?e.callExpression(c,[e.cloneNode(x)]):c,u=s||e.nullLiteral();if(j(p,n.signalNames,n.importedIdentifiers)){let g=n.nextMemoId();n.needsMemo=!0;let f=h?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),p=e.callExpression(e.identifier(g),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(x),l,u))]))}function Ae(i,n){if(e.isCallExpression(i))return i;if(e.isArrowFunctionExpression(i)&&e.isExpression(i.body))return i.body;let r=n.signalNames&&n.signalNames.fromDestructuredProps,t=a=>r&&r.has(a)||n.importedIdentifiers&&n.importedIdentifiers.has(a);if(e.isIdentifier(i))return t(i.name)?Le(i):n.signalNames&&q(i.name,n.signalNames)?e.callExpression(i,[]):i;let o=en(i);return o&&t(o.name)?Le(i):i}function en(i){if(!e.isMemberExpression(i))return null;let n=i;for(;e.isMemberExpression(n);){if(n.computed||!e.isIdentifier(n.property))return null;n=n.object}return e.isIdentifier(n)?n:null}function Le(i){return e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",i),e.stringLiteral("function")),e.callExpression(e.cloneNode(i),[]),e.cloneNode(i))}function nn(i,n){let r=[];for(let t of i)if(e.isJSXText(t)){let o=H(t.value);o&&r.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||r.push(t.expression):e.isJSXElement(t)?r.push(K({node:t},n)):e.isJSXFragment(t)&&r.push(ne({node:t},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function rn(i,n){let{node:r}=i,t=_(r.openingElement.name.name,n),o=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(t||!_("Match",n));if(!r.children.some(o)&&!J(r.openingElement.name.name,n))return Ie(i,n);let a=f=>{throw D(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),X(f)==="fallback"&&(s=F(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){H(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}o(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let f of c){let I=null;for(let N of f.openingElement.attributes)e.isJSXAttribute(N)&&X(N)==="when"&&(I=F(N.value));I||a('has a <Match> with no "when" prop');let S=n._pendingSetup.length,v=nn(f.children,n),M=n._pendingSetup.splice(S);M.length>0&&(v=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(v)])),[])),p.push([Ae(I,n),v])}let x=p.some(([f])=>j(f,n.signalNames,n.importedIdentifiers)),h=s||e.nullLiteral();if(!x){let f=h;for(let I=p.length-1;I>=0;I--)f=e.conditionalExpression(p[I][0],p[I][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=p.length-1;f>=0;f--)l=e.conditionalExpression(p[f][0],e.numericLiteral(f),l);let u=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let g=h;for(let f=p.length-1;f>=0;f--)g=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(u),[]),e.numericLiteral(f)),p[f][1],g);return e.arrowFunctionExpression([],g)}function Me(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,t=ve(i,n);if(t){n.needsMapArray=!0;let a=e.isCallExpression(t)&&e.isIdentifier(t.callee)&&(t.callee.name==="_$mapArray"||t.callee.name==="mapArray");if(e.isArrowFunctionExpression(t)&&e.isExpression(t.body))return t.body=Z(t.body,r,n),t;if(a)return t;let c=Z(t,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):j(i,n.signalNames,n.importedIdentifiers)?(i=Z(i,r,n),e.arrowFunctionExpression([],i)):i}function ne(i,n){let{node:r}=i,t=r.children,o=[];for(let a of t)if(e.isJSXText(a)){let s=H(a.value);s&&o.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||o.push(Me(a.expression,n)):e.isJSXElement(a)?o.push(K({node:a},n)):e.isJSXFragment(a)&&o.push(ne({node:a},n));return o.length===1?o[0]:e.arrayExpression(o)}function Fe(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 Pe(i,n,r){let t=i.scope,o=n._signalNamesCache;o||(o=n._signalNamesCache=new WeakMap);let a=o.get(t);a||(a=Be(i),o.set(t,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,x=!1,h=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(x=!0),Ze(p)&&(h=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!x&&!h?(p.insertBefore(c),i.replaceWith(s)):(c.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(s)}function tn(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 on(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 sn(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 Ne(i,n,r,t,o){let a=i.node.loc?.start||{line:0,column:0},s=`${o}:${a.line}:${a.column+1}`,c=`${o}#${t}`,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 "${t}" at ${s}.`);let x={id:r,key:c,bindingName:t,filename:o,source:s,loc:a};if(n.serverActionIds.set(r,x),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(x)}catch(h){throw i.buildCodeFrameError(h instanceof Error?h.message:String(h))}}function an(i,n){if(!on(i,n))return;let r=tn(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 t=i.node.arguments[1],o=sn(t);if(o.property){o.value!==null&&Ne(i,n,o.value,r,n.serverActionFilename);return}let a=`wa1_${gn(`${n.serverActionFilename}#${r}`)}`;Ne(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));t?e.isObjectExpression(t)?t.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(t)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsComponentVNode=!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 t=r.source.value,o=je(t),a=o||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let c=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(c=s.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),o?n.whatImports.add(c):t.startsWith(".")||n.foreignImports.add(c)),hn.has(t)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){L(r)},CallExpression(r){an(r,n)},VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let o=t.callee,a="";if(e.isIdentifier(o)?a=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(a=o.property.name),Oe.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let c of s.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let o of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(o.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(n.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let o=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){o=a;break}if(o){let a=new Set(o.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||o.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&xn(i,e,t),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let o=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[o]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Pe(i,n,K)},JSXFragment(i,n){Pe(i,n,ne)}}}}function xn(e,m,d){let y=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){y=E;break}if(y){let E=new Set(y.specifiers.filter(b=>m.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of d)E.has(b.imported.name)||y.specifiers.push(b)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import Y from"path";import{createRequire as Ln}from"node:module";import{transformSync as Mn}from"@babel/core";import re from"fs";import z from"path";var Te=new Set([".jsx",".tsx",".js",".ts"]),bn=new Set(["_layout","_error","_loading","_404"]);function Xe(e){let m=[],d=[],y=[];function E(w,C=""){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){if(A.name.match(/^\((.+)\)$/)){E(_,C);continue}if(A.name==="api"&&C===""){b(_,"/api");continue}E(_,C+"/"+le(A.name));continue}let J=z.extname(A.name);if(!Te.has(J))continue;let P=z.basename(A.name,J);if(P==="_layout"){d.push({filePath:_,urlPrefix:C||"/"});continue}if(bn.has(P))continue;let W=le(P),V=P==="index"?C||"/":C+"/"+W;m.push({filePath:_,routePath:De(V),isDynamic:V.includes(":")||V.includes("*")})}}function b(w,C){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){b(_,C+"/"+le(A.name));continue}let J=z.extname(A.name);if(!Te.has(J))continue;let P=z.basename(A.name,J),W=le(P),V=P==="index"?C:C+"/"+W;y.push({filePath:_,routePath:De(V)})}}return E(e),m.sort((w,C)=>{let D=Je(w.routePath),A=Je(C.routePath);return D-A}),{pages:m,layouts:d,apiRoutes:y}}function le(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function De(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Je(e){return e.includes("*")?100:e.includes(":")?10:0}var yn=/export\s+const\s+page\s*=\s*\{/;function We(e,m={}){let d=yn.exec(e);if(!d)return{mode:"client"};let y=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(_n(e,y))}}catch(E){return Sn(E,m.filePath),{mode:"client"}}}function Sn(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 bn=e=>/[A-Za-z_$]/.test(e),yn=e=>/[A-Za-z0-9_$]/.test(e);function Sn(e,m){let d=[],y=-1,E=0,b=m;for(;b<e.length;){let w=e[b];if(w==="/"&&e[b+1]==="/"){let C=e.indexOf(`
4
- `,b);b=C===-1?e.length:C,d.push(" ");continue}if(w==="/"&&e[b+1]==="*"){let C=e.indexOf("*/",b+2);if(C===-1)throw new SyntaxError("unterminated block comment");b=C+2,d.push(" ");continue}if(w==='"'||w==="'"||w==="`"){let C=vn(e,b);d.push(JSON.stringify(C.value)),y=-1,b=C.end;continue}if(bn(w)){let C=b+1;for(;C<e.length&&yn(e[C]);)C++;let T=e.slice(b,C);d.push(wn(e,C)?JSON.stringify(T):T),y=-1,b=C;continue}if(w===" "||w===" "||w===`
5
- `||w==="\r"){d.push(w),b++;continue}if(w===","){d.push(","),y=d.length-1,b++;continue}if(w==="}"||w==="]"){if(y!==-1&&(d[y]=""),y=-1,d.push(w),b++,w==="}"&&--E===0)return d.join("");continue}w==="{"&&E++,d.push(w),y=-1,b++}throw new SyntaxError("unterminated object literal")}function wn(e,m){let d=m;for(;d<e.length;){let y=e[d];if(y===" "||y===" "||y===`
3
+ \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var wn=e=>/[A-Za-z_$]/.test(e),vn=e=>/[A-Za-z0-9_$]/.test(e);function _n(e,m){let d=[],y=-1,E=0,b=m;for(;b<e.length;){let w=e[b];if(w==="/"&&e[b+1]==="/"){let C=e.indexOf(`
4
+ `,b);b=C===-1?e.length:C,d.push(" ");continue}if(w==="/"&&e[b+1]==="*"){let C=e.indexOf("*/",b+2);if(C===-1)throw new SyntaxError("unterminated block comment");b=C+2,d.push(" ");continue}if(w==='"'||w==="'"||w==="`"){let C=Cn(e,b);d.push(JSON.stringify(C.value)),y=-1,b=C.end;continue}if(wn(w)){let C=b+1;for(;C<e.length&&vn(e[C]);)C++;let D=e.slice(b,C);d.push(kn(e,C)?JSON.stringify(D):D),y=-1,b=C;continue}if(w===" "||w===" "||w===`
5
+ `||w==="\r"){d.push(w),b++;continue}if(w===","){d.push(","),y=d.length-1,b++;continue}if(w==="}"||w==="]"){if(y!==-1&&(d[y]=""),y=-1,d.push(w),b++,w==="}"&&--E===0)return d.join("");continue}w==="{"&&E++,d.push(w),y=-1,b++}throw new SyntaxError("unterminated object literal")}function kn(e,m){let d=m;for(;d<e.length;){let y=e[d];if(y===" "||y===" "||y===`
6
6
  `||y==="\r"){d++;continue}if(y==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
- `,d);if(E===-1)return!1;d=E+1;continue}if(y==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return y===":"}return!1}var Te={n:`
8
- `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function vn(e,m){let d=e[m],y="",E=m+1;for(;E<e.length;){let b=e[E];if(b==="\\"){let w=e[E+1];if(w===void 0)break;if(w===`
7
+ `,d);if(E===-1)return!1;d=E+1;continue}if(y==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return y===":"}return!1}var Re={n:`
8
+ `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function Cn(e,m){let d=e[m],y="",E=m+1;for(;E<e.length;){let b=e[E];if(b==="\\"){let w=e[E+1];if(w===void 0)break;if(w===`
9
9
  `){E+=2;continue}if(w==="\r"){E+=e[E+2]===`
10
- `?3:2;continue}if(w==="u"){if(e[E+2]==="{"){let C=e.indexOf("}",E+3);if(C===-1)throw new SyntaxError("invalid unicode escape");y+=String.fromCodePoint(parseInt(e.slice(E+3,C),16)),E=C+1;continue}y+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(w==="x"){y+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}y+=Object.prototype.hasOwnProperty.call(Te,w)?Te[w]:w,E+=2;continue}if(b===d)return{value:y,end:E+1};if(d==="`"&&b==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(b===`
11
- `||b==="\r"))break;y+=b,E++}throw new SyntaxError("unterminated string literal")}function _n(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 Ee(e,m){let{pages:d,layouts:y,apiRoutes:E}=Je(e),b=[],w=[],C=new Map;y.forEach((_,J)=>{let P=`_layout${J}`,W=ge(_.filePath,m);b.push(`import ${P} from '${W}';`),C.set(_.urlPrefix,P)}),d.forEach((_,J)=>{let P=`_page${J}`,W=ge(_.filePath,m);b.push(`import ${P} from '${W}';`);let V={mode:"client"},B={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let X=re.readFileSync(_.filePath,"utf-8");V=Xe(X,{filePath:_.filePath}),B=_n(X)}catch{}let k=kn(_.routePath,C),L={path:_.routePath,component:P,mode:V.mode||"client",layout:k||null,hasLoader:B.hasLoader};w.push(L)});let T=[];return E.forEach((_,J)=>{let P=`_api${J}`,W=ge(_.filePath,m);b.push(`import * as ${P} from '${W}';`),T.push({path:_.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...b,"","export const routes = [",...w.map(_=>` { path: '${_.path}', component: ${_.component}, mode: '${_.mode}'${_.layout?`, layout: ${_.layout}`:""}${_.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...T.map(_=>` { path: '${_.path}', handlers: ${_.handlers} },`),"];","","export const pageModes = {",...w.map(_=>` '${_.path}': '${_.mode}',`),"};"].join(`
12
- `)}function ge(e,m){return"/"+q.relative(m,e).split(q.sep).join("/")}function kn(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let y="/"+d.join("/");if(m.has(y))return m.get(y);d.pop()}return m.has("/")?m.get("/"):null}var Cn=`
10
+ `?3:2;continue}if(w==="u"){if(e[E+2]==="{"){let C=e.indexOf("}",E+3);if(C===-1)throw new SyntaxError("invalid unicode escape");y+=String.fromCodePoint(parseInt(e.slice(E+3,C),16)),E=C+1;continue}y+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(w==="x"){y+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}y+=Object.prototype.hasOwnProperty.call(Re,w)?Re[w]:w,E+=2;continue}if(b===d)return{value:y,end:E+1};if(d==="`"&&b==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(b===`
11
+ `||b==="\r"))break;y+=b,E++}throw new SyntaxError("unterminated string literal")}function $n(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 xe(e,m){let{pages:d,layouts:y,apiRoutes:E}=Xe(e),b=[],w=[],C=new Map;y.forEach((_,J)=>{let P=`_layout${J}`,W=Ee(_.filePath,m);b.push(`import ${P} from '${W}';`),C.set(_.urlPrefix,P)}),d.forEach((_,J)=>{let P=`_page${J}`,W=Ee(_.filePath,m);b.push(`import ${P} from '${W}';`);let V={mode:"client"},B={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let R=re.readFileSync(_.filePath,"utf-8");V=We(R,{filePath:_.filePath}),B=$n(R)}catch{}let k=In(_.routePath,C),L={path:_.routePath,component:P,mode:V.mode||"client",layout:k||null,hasLoader:B.hasLoader};w.push(L)});let D=[];return E.forEach((_,J)=>{let P=`_api${J}`,W=Ee(_.filePath,m);b.push(`import * as ${P} from '${W}';`),D.push({path:_.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...b,"","export const routes = [",...w.map(_=>` { path: '${_.path}', component: ${_.component}, mode: '${_.mode}'${_.layout?`, layout: ${_.layout}`:""}${_.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...D.map(_=>` { path: '${_.path}', handlers: ${_.handlers} },`),"];","","export const pageModes = {",...w.map(_=>` '${_.path}': '${_.mode}',`),"};"].join(`
12
+ `)}function Ee(e,m){return"/"+z.relative(m,e).split(z.sep).join("/")}function In(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let y="/"+d.join("/");if(m.has(y))return m.get(y);d.pop()}return m.has("/")?m.get("/"):null}var An=`
13
13
  :host {
14
14
  position: fixed;
15
15
  inset: 0;
@@ -195,12 +195,12 @@ var sn=new Set(["preventDefault","stopPropagation","once","capture","passive","s
195
195
  white-space: pre-wrap;
196
196
  line-height: 1.5;
197
197
  }
198
- `,Un=`
198
+ `,qn=`
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>${Cn}</style>';
203
+ this.root.innerHTML = '<style>${An}</style>';
204
204
  this._err = err;
205
205
  this.show(err);
206
206
  }
@@ -390,13 +390,13 @@ class WhatErrorOverlay extends HTMLElement {
390
390
  if (!customElements.get('what-error-overlay')) {
391
391
  customElements.define('what-error-overlay', WhatErrorOverlay);
392
392
  }
393
- `;function Re(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 We="virtual:what-routes",ce="\0"+We,An=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,Ln=/\.[cm]?[jt]sx?$/;function xe(e,m){return e?Array.isArray(e)?e.some(d=>xe(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function Mn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}async function Fn(e){try{return $n(Q.resolve(e||process.cwd(),"package.json"))("vite/package.json").version||""}catch{return import("vite").then(m=>m.version||"").catch(()=>"")}}var Pn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,Nn=/(?:store|signal|state|context|util|helper|lib|config)\b/i,On=/\b_\$(?:template|createComponent)\b/;function jn(e){return On.test(e)}function Dn(e){return Object.assign(new Error(`[what-compiler] ${e} is being compiled for the server, but what-compiler's JSX output is client-only. It lowers JSX to module-scope _$template() calls that run document.createElement() at import time, so this module throws "document is not defined" the moment a server imports it.
393
+ `;function Ve(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 He="virtual:what-routes",ce="\0"+He,Fn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,Pn=/\.[cm]?[jt]sx?$/;function be(e,m){return e?Array.isArray(e)?e.some(d=>be(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function Nn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}async function On(e){try{return Ln(Y.resolve(e||process.cwd(),"package.json"))("vite/package.json").version||""}catch{return import("vite").then(m=>m.version||"").catch(()=>"")}}var jn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,Tn=/(?:store|signal|state|context|util|helper|lib|config)\b/i,Dn=/\b_\$(?:template|createComponent)\b/;function Jn(e){return Dn.test(e)}function Rn(e){return Object.assign(new Error(`[what-compiler] ${e} is being compiled for the server, but what-compiler's JSX output is client-only. It lowers JSX to module-scope _$template() calls that run document.createElement() at import time, so this module throws "document is not defined" the moment a server imports it.
394
394
 
395
395
  Server-rendered views have two supported spellings:
396
396
  1. Author them with h() from what-framework.
397
397
  2. Compile them with the automatic JSX runtime instead of what-compiler (jsxImportSource: "what-framework"), which emits h() calls that renderToString and renderToHydratableString understand.
398
398
 
399
- If a DOM already exists in this process on purpose, set ssrGuard: false on the plugin. The likeliest reason is a test runner: Vitest applies an SSR transform under \`environment: 'node'\`, so a component test that shims a DOM itself lands here. Note that with the guard off the result is a full client render, not SSR.`),{code:"ERR_COMPILED_JSX_IN_SSR",id:e,plugin:"vite-plugin-what"})}function Tn(e,m){if(e&&e.ssr)return!0;let d=m&&m.environment;return!!(d&&d.name==="ssr")}function be(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:y=!0,production:E=!0,pages:b="src/pages",hot:w=!E,prodBundles:C=!0,ssrGuard:T=!0}=e,A="",_="",J=!1,P=new Map;function W(k){let L=P.get(k.id);if(L&&L.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${L.bindingName}" at ${L.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});P.set(k.id,k)}function V(k){for(let[L,X]of P)X.filename===k&&P.delete(L)}function B(k){let L=k.replace(/[?#].*$/,"");return A?Q.relative(A,L).split(Q.sep).join("/"):L}return{name:"vite-plugin-what",configResolved(k){A=k.root,_=Q.resolve(A,b),J=k.command==="serve"},configureServer(k){Re(k),k.watcher.on("add",L=>{if(L.startsWith(_)){let X=k.moduleGraph.getModuleById(ce);X&&(k.moduleGraph.invalidateModule(X),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",L=>{if(V(B(L)),L.startsWith(_)){let X=k.moduleGraph.getModuleById(ce);X&&(k.moduleGraph.invalidateModule(X),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===We)return ce},load(k){if(k===ce)return Ee(_,A)},transform(k,L,X){let F=L.replace(/[?#].*$/,""),U=xe(m,F),ee=Ln.test(F),R=ee&&An.test(k);if(d&&xe(d,F)||(ee&&V(B(F)),!U&&!R))return null;let te=T&&Tn(X,this);try{let D=In(k,{filename:L,sourceMaps:y,configFile:!1,babelrc:!1,plugins:[[ae,{production:E,projectRoot:A||process.cwd(),onActionId:W}]],parserOpts:{plugins:["jsx","typescript"]}});if(!D||!D.code)return null;let Z=D.code;if(te&&jn(Z))throw Dn(F);return w&&J&&!E&&Jn(k,L)&&(Z+=Rn(L)),{code:Z,map:D.map}}catch(D){throw D&&D.code==="ERR_COMPILED_JSX_IN_SSR"||(D.plugin="vite-plugin-what",D.id||(D.id=L),D.loc===void 0&&D._loc&&(D.loc={file:L,line:D._loc.line,column:D._loc.column}),console.error(`[what] Error transforming ${L}:`,D.message)),D}},handleHotUpdate({file:k,server:L}){if(w&&m.test(k)&&!(d&&d.test(k))&&Xn(k))return L.ws.send({type:"full-reload"}),[]},async config(k,{mode:L,command:X}){let F=X==="build"&&L==="production"&&C,U=Mn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Fn(k.root)});return{...F?{resolve:{conditions:["production"]}}:{},...U,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function Jn(e,m){return!!(Pn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function Xn(e){let m=Q.basename(e,Q.extname(e));return Nn.test(m)}function Rn(e){return`
399
+ If a DOM already exists in this process on purpose, set ssrGuard: false on the plugin. The likeliest reason is a test runner: Vitest applies an SSR transform under \`environment: 'node'\`, so a component test that shims a DOM itself lands here. Note that with the guard off the result is a full client render, not SSR.`),{code:"ERR_COMPILED_JSX_IN_SSR",id:e,plugin:"vite-plugin-what"})}function Xn(e,m){if(e&&e.ssr)return!0;let d=m&&m.environment;return!!(d&&d.name==="ssr")}function ye(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:y=!0,production:E=!0,pages:b="src/pages",hot:w=!E,prodBundles:C=!0,ssrGuard:D=!0}=e,A="",_="",J=!1,P=new Map;function W(k){let L=P.get(k.id);if(L&&L.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${L.bindingName}" at ${L.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});P.set(k.id,k)}function V(k){for(let[L,R]of P)R.filename===k&&P.delete(L)}function B(k){let L=k.replace(/[?#].*$/,"");return A?Y.relative(A,L).split(Y.sep).join("/"):L}return{name:"vite-plugin-what",configResolved(k){A=k.root,_=Y.resolve(A,b),J=k.command==="serve"},configureServer(k){Ve(k),k.watcher.on("add",L=>{if(L.startsWith(_)){let R=k.moduleGraph.getModuleById(ce);R&&(k.moduleGraph.invalidateModule(R),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",L=>{if(V(B(L)),L.startsWith(_)){let R=k.moduleGraph.getModuleById(ce);R&&(k.moduleGraph.invalidateModule(R),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===He)return ce},load(k){if(k===ce)return xe(_,A)},transform(k,L,R){let F=L.replace(/[?#].*$/,""),Q=be(m,F),U=Pn.test(F),te=U&&Fn.test(k);if(d&&be(d,F)||(U&&V(B(F)),!Q&&!te))return null;let X=D&&Xn(R,this);try{let O=Mn(k,{filename:L,sourceMaps:y,configFile:!1,babelrc:!1,plugins:[[ae,{production:E,projectRoot:A||process.cwd(),onActionId:W}]],parserOpts:{plugins:["jsx","typescript"]}});if(!O||!O.code)return null;let ee=O.code;if(X&&Jn(ee))throw Rn(F);return w&&J&&!E&&Wn(k,L)&&(ee+=Hn(L)),{code:ee,map:O.map}}catch(O){throw O&&O.code==="ERR_COMPILED_JSX_IN_SSR"||(O.plugin="vite-plugin-what",O.id||(O.id=L),O.loc===void 0&&O._loc&&(O.loc={file:L,line:O._loc.line,column:O._loc.column}),console.error(`[what] Error transforming ${L}:`,O.message)),O}},handleHotUpdate({file:k,server:L}){if(w&&m.test(k)&&!(d&&d.test(k))&&Vn(k))return L.ws.send({type:"full-reload"}),[]},async config(k,{mode:L,command:R}){let F=R==="build"&&L==="production"&&C,Q=Nn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await On(k.root)});return{...F?{resolve:{conditions:["production"]}}:{},...Q,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function Wn(e,m){return!!(jn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function Vn(e){let m=Y.basename(e,Y.extname(e));return Tn.test(m)}function Hn(e){return`
400
400
 
401
401
  // --- What Framework HMR Boundary ---
402
402
  if (import.meta.hot) {
@@ -409,4 +409,4 @@ if (import.meta.hot) {
409
409
  }
410
410
  });
411
411
  }
412
- `}import{h as ri,Fragment as ti,mount as oi,Island as si}from"what-core";export{ti as Fragment,si as Island,ae as babelPlugin,Xe as extractPageConfig,Ee as generateRoutesModule,ri as h,oi as mount,Je as scanPages,be as vitePlugin,be as what};
412
+ `}import{h as si,Fragment as ai,mount as li,Island as ci}from"what-core";export{ai as Fragment,ci as Island,ae as babelPlugin,We as extractPageConfig,xe as generateRoutesModule,si as h,li as mount,Xe as scanPages,ye as vitePlugin,ye as what};
@@ -1,15 +1,15 @@
1
- import Q from"path";import{createRequire as Cn}from"node:module";import{transformSync as $n}from"@babel/core";var rn=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),tn=new Set(["once","capture","passive"]),on=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),sn=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),se=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),an=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),Me=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),ln=new Set(["For","Show","Switch","Match"]),cn=new Set(["what-framework/server","what-server","what-server/actions"]);function Fe(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function fn(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 pn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),y=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return y&&d.startsWith(`${y}/`)?d.slice(y.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 y="";for(let E=0;E<m.length;E++){let b=m[E].replace(/\t/g," "),w=E===0,C=E===m.length-1;w||(b=b.replace(/^ +/,"")),C||(b=b.replace(/ +$/,"")),b&&(E!==d&&(b+=" "),y+=b)}return y}function he({types:e}){let m=new Set,d=new Set;function y(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(o=>o!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),t=r[0],o=r.slice(1).filter(a=>rn.has(a));return{eventName:t,modifiers:o}}function b(i){return i.startsWith("bind:")}function w(i){return i.slice(5)}function C(i){return/^[A-Z]/.test(i)}function T(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let t=i?.node;if(t&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(t,r);let o=t?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${o?`${a}:${o.line}:${o.column+1}`:a})`)}function A(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&C(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 W(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:V(n.node.callee,n.scope)}function V(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?B(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?B(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function B(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let t=i.path.node;if(!n(t))return!1;if(r!==null){let a=t.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let o=i.path.parent;return e.isImportDeclaration(o)&&Fe(o.source.value)}function k(i){return e.isJSXMemberExpression(i)?e.memberExpression(k(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function L(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],t=-1;for(let u=0;u<r.properties.length;u++){let x=r.properties[u];if(e.isRestElement(x))return;if(e.isObjectProperty(x)&&!x.computed&&e.isIdentifier(x.key,{name:"children"})){if(t!==-1||!e.isIdentifier(x.value))return;t=u}}if(t===-1)return;let o=i.scope.getBinding(r.properties[t].value.name);if(!o||o.constantViolations.length>0||o.referencePaths.length===0||!o.referencePaths.every(u=>{let x=u.parentPath;if(!x||!x.isJSXExpressionContainer())return!1;let h=x.parentPath;if(!h||!h.isJSXElement()||!A(h.node))return!1;let l=h.node.openingElement.name;return!(e.isJSXIdentifier(l)&&ln.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let c=r.properties.filter((u,x)=>x!==t);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let u=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(u,e.cloneNode(s))])),i.node._whatMovedProps=u}for(let u of o.referencePaths)u.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function X(i){return on.has(String(i).toLowerCase())}function F(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function U(i){return i==="className"?"class":i==="htmlFor"?"for":i}function ee(i,n){let r=U(R(i[n]));for(let t=n+1;t<i.length;t+=1){let o=i[t];if(!e.isJSXSpreadAttribute(o)&&U(R(o))===r)return!0}return!1}function R(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 te(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function D(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 t of n)switch(t){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 G(i,n){return n.has(i)}function Xe(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function t(s){let c=s.init;if(!c||!e.isCallExpression(c))return;let u=c.callee,x="";if(e.isIdentifier(u)?x=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(x=u.property.name),Me.has(x)){let h=s.id;if(e.isIdentifier(h))n.add(h.name);else if(e.isArrayPattern(h))for(let l of h.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(h))for(let l of h.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function o(s){if(e.isObjectPattern(s))for(let c of s.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&t(c.path.node);let s=a.path&&a.path.node;if(s){if(s.params)for(let c of s.params)o(c);s._whatMovedProps&&o(s._whatMovedProps)}a=a.parent}return n}function Re(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&an.has(i.callee.property.name)}function xe(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?se.has(n.object.name):e.isIdentifier(n)?se.has(n.name):!1}function be(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&G(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&G(i.callee.object.name,n)||xe(i))return!1;if(i.arguments.some(t=>O(t,n,r)))return!0}return!1}function O(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&G(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&G(i.callee.object.name,n)?!0:xe(i)?i.arguments.some(t=>O(t,n,r)):i.arguments.length===0&&!Re(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(t=>O(t,n,r)):O(i.callee,n,r)||i.arguments.some(t=>O(t,n,r)):e.isIdentifier(i)?G(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(t=>O(t,n,r)):e.isObjectExpression(i)?i.properties.some(t=>e.isObjectProperty(t)&&O(t.value,n,r)):e.isArrayExpression(i)?i.elements.some(t=>t&&O(t,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function z(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":z(i.left,n);break;case"RestElement":z(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)z(r,n);break;case"ObjectPattern":for(let r of i.properties)z(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function We(i){let n=new Set;for(let t=1;t<i.params.length;t++)z(i.params[t],n);let r=t=>{if(!(!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(r);return}switch(t.type){case"VariableDeclaration":for(let o of t.declarations)z(o.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":t.id&&n.add(t.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":z(t.param,n),r(t.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(t.init),r(t.left),r(t.body);return;default:break}for(let o of Object.keys(t)){if(o==="loc"||o==="start"||o==="end"||o==="type"||o==="leadingComments"||o==="trailingComments"||o==="innerComments")continue;let a=t[o];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let t of z(i.params[0],new Set))n.delete(t);return n}function Ve(i,n){if(n.size===0)return null;let r=null,t=o=>{if(!(r||!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(t);return}if(o.type==="Identifier"){n.has(o.name)&&(r=o.name);return}for(let a of Object.keys(o)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||o.type==="MemberExpression"&&a==="property"&&!o.computed||(o.type==="ObjectProperty"||o.type==="ObjectMethod")&&a==="key"&&!o.computed)continue;let s=o[a];s&&typeof s=="object"&&t(s)}}};return t(i),r}function ye(i,n){let r=i,t=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,t=!0),e.isConditionalExpression(r)){let a=oe(r.consequent,n),s=oe(r.alternate,n);if(a||s){let c=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return t?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=oe(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return t?e.arrowFunctionExpression([],s):s}return null}return oe(r,n)}function oe(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 t=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))t=r.body;else if(e.isBlockStatement(r.body)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}}else if(e.isFunctionExpression(r)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}if(!t||!e.isJSXElement(t))return null;let o=t.openingElement.attributes,a=null;for(let g of o)if(e.isJSXAttribute(g)&&R(g)==="key"){a=g;break}if(!a)return null;let s=F(a.value);if(!s)return null;let c=We(r);if(Ve(s,c)){let g=e.isIdentifier(s)&&r.params[1]&&e.isIdentifier(r.params[1],{name:s.name});return null}t.openingElement.attributes=o.filter(g=>g!==a);let x=i.callee.object,h=e.arrowFunctionExpression([],x),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),p=e.arrowFunctionExpression([l],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[h,r,e.objectExpression([e.objectProperty(e.identifier("key"),p),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function ce(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(A(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let t=r.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(ce)}return!1}function Se(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function fe(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let t=H(r.value);t&&n.push({kind:"text",text:t});continue}if(e.isJSXFragment(r)){fe(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function pe(i){if(e.isJSXText(i)){let s=H(i.value);return s?we(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(i))return"";let t=`<${r}`,o=n.attributes.findIndex(s=>e.isJSXSpreadAttribute(s));for(let[s,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||o!==-1&&s>o||ee(n.attributes,s))continue;let u=R(c);if(u==="key"||D(u)||u.startsWith("bind:")||u.includes("|"))continue;let x=u;if(u==="className"&&(x="class"),u==="htmlFor"&&(x="for"),!c.value)t+=` ${x}`;else if(e.isStringLiteral(c.value))t+=` ${x}="${He(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&X(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of i.children)if(e.isJSXText(s)){let c=H(s.value);c&&(t+=we(c))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)?A(s)?t+="<!--$-->":t+=pe(s):e.isJSXFragment(s)&&(t+="<!--$-->".repeat(fe(s).length));return t+=`</${r}>`,t}function we(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function He(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function K(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name;if(!_(o,n)){if(o==="For")return Ge(i,n);if(o==="Show")return ze(i,n)}if(o==="Switch"&&(!_(o,n)||P(r)))return Ke(i,n);if(A(r))return ke(i,n);let a=t.attributes,s=r.children,c=s.every(ce),u=a.every(f=>!Se(f)),x=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let I=R(f);return!I?.startsWith("on")&&!I?.startsWith("bind:")});if(c&&u&&x){let f=pe(r);if(f){let I=Ie(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(I),[])}}let h=pe(r);if(!h){let f=r.loc,I=n.filename||n.file?.opts?.filename||"<unknown>",S=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${o}> at ${I}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,ue(i,n)}let l=Ie(n,h);n.needsTemplate=!0;let p=n.nextVarId(),g=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier(l),[]))])];return ve(g,p,a,n,o),_e(g,p,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...g),e.identifier(p)}function ue(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name,a=t.attributes,s=r.children,c=[];for(let h of a){if(e.isJSXSpreadAttribute(h))continue;let l=R(h),p=F(h.value),g=U(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),p))}let u=[];for(let h of s)if(e.isJSXText(h)){let l=H(h.value);l&&u.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||u.push(h.expression):e.isJSXElement(h)?u.push(K({node:h},n)):e.isJSXFragment(h)&&u.push(ne({node:h},n));let x=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(o),x,...u])}let Be=new Set(["input","textarea","select","option"]);function ve(i,n,r,t,o){function a(x,h){return x==="class"?(t.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),h])):x==="style"?(t.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),h])):x==="value"&&o&&Be.has(o)?(t.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),h])):x==="checked"&&o==="input"?(t.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),h])):x.startsWith("data-")||x.startsWith("aria-")?(t.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(x),h])):(t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(x),h]))}let s=!1;function c(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let u=!1;for(let[x,h]of r.entries()){if(e.isJSXSpreadAttribute(h)){u=!0,t.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),h.argument])));continue}if(ee(r,x))continue;let l=R(h);if(l!=="key"){if(l==="ref"){let p=F(h.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",p),e.stringLiteral("function")),e.callExpression(e.cloneNode(p),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(p),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!y(l,t)){let p=l.slice(2).toLowerCase(),g=F(h.value);sn.has(p)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(p),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${p}`)),g)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(p),g])));continue}if(l.startsWith("on")&&(l.includes("|")||y(l,t))){let{eventName:p,modifiers:g}=E(l),f=F(h.value),I=Z(f,g),S=p.slice(2).toLowerCase(),v=g.filter(N=>tn.has(N)),M=[e.stringLiteral(S),I];if(v.length>0){let N=v.map($=>e.objectProperty(e.identifier($),e.booleanLiteral(!0)));M.push(e.objectExpression(N))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),M)));continue}if(b(l)){let p=w(l),g=h.value.expression;t.needsEffect=!0,p==="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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):p==="checked"&&(t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(h.value)){let p=h.value.expression,g=U(l);if(O(p,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let f=t.signalNames&&t.signalNames.fromDestructuredProps,I=e.isIdentifier(p)&&!(f&&f.has(p.name))&&(G(p.name,t.signalNames)||t.importedIdentifiers&&t.importedIdentifiers.has(p.name))?e.callExpression(p,[]):p,S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(g,I))]);be(p,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: effect 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(a(g,p)));continue}u&&i.push(e.expressionStatement(a(U(l),F(h.value))))}}}function de(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(de);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"&&de(r))return!0}return!1}function Ue(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 Y(i,n,r){let t=null,o=!1;if(e.isConditionalExpression(i))t=i.test,o=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))t=i.left;else return i;if(!O(t,r.signalNames,r.importedIdentifiers)||!(o?[i.consequent,i.alternate]:[i.right]).some(de))return i;let s=r.nextMemoId();r.needsMemo=!0;let c=o?e.unaryExpression("!",e.unaryExpression("!",t)):t;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let u=e.callExpression(e.identifier(s),[]);return o?e.conditionalExpression(u,i.consequent,i.alternate):e.logicalExpression(i.operator,u,i.right)}function _e(i,n,r,t,o){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let p=l.openingElement.name.name;if(A(l)||p==="For"||p==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let g=l.openingElement.attributes.some(Se)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&R(f)?.startsWith("on"))||!l.children.every(ce);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:g}),s++}continue}if(e.isJSXFragment(l))for(let p of fe(l))p.kind==="text"?a.push({type:"fragmentText",text:p.text,childIndex:s}):p.kind==="expression"?a.push({type:"expression",child:p.child,childIndex:s}):a.push({type:"component",child:p.child,childIndex:s}),s++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),u=c.length>=2,x=new Map;if(u){let l=null,p=0;for(let g of c){let f=g.childIndex,I=o.nextVarId();x.set(f,I);let S;if(l===null)S=me(n,f);else{S=e.identifier(l);for(let v=p;v<f;v++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(I),S)])),l=I,p=f}}function h(l){return x.has(l)?e.identifier(x.get(l)):me(n,l)}for(let l of a){if(l.type==="expression"){let p=l.child.expression,g=h(l.childIndex);o.needsInsert=!0;let f=ye(p,o);if(f){o.needsMapArray=!0;let S=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),v=e.isArrowFunctionExpression(f);v&&e.isExpression(f.body)?f.body=Y(f.body,i,o):!S&&!v&&(f=Y(f,i,o));let M=S||v?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,g])));continue}if(e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="mapArray"||p.callee.name==="_$mapArray")){o.needsMapArray=!0,p.callee.name==="mapArray"&&(p.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,g])));continue}if(O(p,o.signalNames,o.importedIdentifiers)){p=Y(p,i,o);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],p),g]);be(p,o.signalNames,o.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),p,g])));continue}if(l.type==="component"){let p=K({node:l.child},o),g=h(l.childIndex);o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,g])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let p;x.has(l.childIndex)?p=x.get(l.childIndex):(p=o.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),me(n,l.childIndex))]))),ve(i,p,l.child.openingElement.attributes,o,l.child.openingElement.name.name),_e(i,p,l.child.children,l.child,o);continue}if(l.type==="fragmentText"){o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),h(l.childIndex)])));continue}}}function me(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 t=0;t<n;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function ke(i,n){let{node:r}=i,t=r.openingElement,o=k(t.name),a=t.attributes,s=r.children,c=null,u=[];for(let S of a){if(e.isJSXAttribute(S)){let v;if(e.isJSXNamespacedName(S.name)?v=`${S.name.namespace.name}:${S.name.name.name}`:v=S.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let M=v.slice(7);S.value?c={type:M,value:S.value.value}:c={type:M};continue}}u.push(S)}function x(){let S=n._pendingSetup?n._pendingSetup.length:0,v=[],M=!1;for(let $ of s)if(e.isJSXText($)){let j=H($.value);j&&v.push(e.stringLiteral(j))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(M=!0,v.push($e($.expression,n)));else if(e.isJSXElement($)){let j=$.openingElement.name.name;j!=="For"&&j!=="Show"&&j!=="Switch"&&(M=!0),v.push(K({node:$},n))}else e.isJSXFragment($)&&(M=!0,v.push(ne({node:$},n)));let N=e.arrayExpression(v);if(M){let $=n._pendingSetup?n._pendingSetup.splice(S):[];N=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(N)]):N)}return N}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let S=[e.objectProperty(e.identifier("component"),o),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&S.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let v=[],M=[],N=()=>{M.length>0&&(v.push(e.objectExpression(M)),M=[])};for(let j of u){if(e.isJSXSpreadAttribute(j)){N(),v.push(j.argument);continue}let ie=R(j);if(ie==="key")continue;let nn=F(j.value);M.push(e.objectProperty(te(ie),nn))}let $;return v.length===0?$=e.objectExpression([...M,...S]):(N(),$=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...v,e.objectExpression(S)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),$,x()])}let h=W(i);h?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],p=[],g=()=>{p.length>0&&(l.push(e.objectExpression(p)),p=[])};for(let S of u){if(e.isJSXSpreadAttribute(S)){g(),l.push(S.argument);continue}let v=R(S);if(v==="key")continue;if(b(v)){let N=w(v),$=S.value.expression;N==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):N==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||y(v,n))){let{eventName:N,modifiers:$}=E(v),j=F(S.value),ie=Z(j,$);p.push(e.objectProperty(e.identifier(N),ie));continue}let M=F(S.value);p.push(e.objectProperty(te(v),M))}g();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let I=x();return e.callExpression(e.identifier(h?"_$componentVNode":"_$createComponent"),[o,f,I])}function Ge(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null,c=null;for(let $ of t)if(e.isJSXAttribute($)){let j=R($);j==="each"?a=F($.value):j==="key"?s=F($.value):j==="fallback"&&(c=F($.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ue(i,n);let u=null;for(let $ of o)if(e.isJSXExpressionContainer($)&&!e.isJSXEmptyExpression($.expression)){u=$.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ue(i,n);n.needsMapArray=!0;let x=$=>{let j=[$,u];return s&&j.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),j)};if(!c)return x(a);n._pendingSetup||(n._pendingSetup=[]);let h=n.nextForIndex(),l=`_each$${h}`,p=`_for$${h}`,g=`_fb$${h}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let I=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(I,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(I),e.memberExpression(e.cloneNode(I),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),x(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let v=e.identifier("_parent"),M=e.identifier("_marker"),N=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([v,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(N,e.callExpression(e.identifier(p),[e.cloneNode(v),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(v),e.arrayExpression([e.identifier(g)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(N))])),e.identifier(p)])}function ze(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null;for(let g of t)if(e.isJSXAttribute(g)){let f=R(g);f==="when"?a=F(g.value):f==="fallback"&&(s=F(g.value))}if(!a)throw T(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let g of o)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){c=g.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let g=n._pendingSetup.length,f=[];for(let S of o)if(e.isJSXText(S)){let v=H(S.value);v&&f.push(e.stringLiteral(v))}else e.isJSXElement(S)&&f.push(K({node:S},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let I=n._pendingSetup.splice(g);I.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...I,e.returnStatement(c)])),[]))}let u=Ce(a,n),x=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),h=e.isFunction(c),l=h?e.callExpression(c,[e.cloneNode(x)]):c,p=s||e.nullLiteral();if(O(u,n.signalNames,n.importedIdentifiers)){let g=n.nextMemoId();n.needsMemo=!0;let f=h?u:e.unaryExpression("!",e.unaryExpression("!",u));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),u=e.callExpression(e.identifier(g),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,u)]),e.returnStatement(e.conditionalExpression(e.cloneNode(x),l,p))]))}function Ce(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&G(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function qe(i,n){let r=[];for(let t of i)if(e.isJSXText(t)){let o=H(t.value);o&&r.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||r.push(t.expression):e.isJSXElement(t)?r.push(K({node:t},n)):e.isJSXFragment(t)&&r.push(ne({node:t},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Ke(i,n){let{node:r}=i,t=_(r.openingElement.name.name,n),o=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(t||!_("Match",n));if(!r.children.some(o)&&!J(r.openingElement.name.name,n))return ke(i,n);let a=f=>{throw T(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),R(f)==="fallback"&&(s=F(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){H(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}o(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let u=[];for(let f of c){let I=null;for(let N of f.openingElement.attributes)e.isJSXAttribute(N)&&R(N)==="when"&&(I=F(N.value));I||a('has a <Match> with no "when" prop');let S=n._pendingSetup.length,v=qe(f.children,n),M=n._pendingSetup.splice(S);M.length>0&&(v=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(v)])),[])),u.push([Ce(I,n),v])}let x=u.some(([f])=>O(f,n.signalNames,n.importedIdentifiers)),h=s||e.nullLiteral();if(!x){let f=h;for(let I=u.length-1;I>=0;I--)f=e.conditionalExpression(u[I][0],u[I][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=u.length-1;f>=0;f--)l=e.conditionalExpression(u[f][0],e.numericLiteral(f),l);let p=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let g=h;for(let f=u.length-1;f>=0;f--)g=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(p),[]),e.numericLiteral(f)),u[f][1],g);return e.arrowFunctionExpression([],g)}function $e(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,t=ye(i,n);if(t){n.needsMapArray=!0;let a=e.isCallExpression(t)&&e.isIdentifier(t.callee)&&(t.callee.name==="_$mapArray"||t.callee.name==="mapArray");if(e.isArrowFunctionExpression(t)&&e.isExpression(t.body))return t.body=Y(t.body,r,n),t;if(a)return t;let c=Y(t,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=Y(i,r,n),e.arrowFunctionExpression([],i)):i}function ne(i,n){let{node:r}=i,t=r.children,o=[];for(let a of t)if(e.isJSXText(a)){let s=H(a.value);s&&o.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||o.push($e(a.expression,n)):e.isJSXElement(a)?o.push(K({node:a},n)):e.isJSXFragment(a)&&o.push(ne({node:a},n));return o.length===1?o[0]:e.arrayExpression(o)}function Ie(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 Ae(i,n,r){let t=i.scope,o=n._signalNamesCache;o||(o=n._signalNamesCache=new WeakMap);let a=o.get(t);a||(a=Xe(i),o.set(t,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let u=i,x=!1,h=!1;for(;u&&!u.isStatement();)(u.isArrowFunctionExpression()||u.isFunctionExpression())&&(x=!0),Ue(u)&&(h=!0),u=u.parentPath;u&&u.isStatement()&&(u.listKey==="body"||u.listKey==="consequent")&&Array.isArray(u.container)&&!x&&!h?(u.insertBefore(c),i.replaceWith(s)):(c.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(s)}function Ze(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 Ye(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 Le(i,n,r,t,o){let a=i.node.loc?.start||{line:0,column:0},s=`${o}:${a.line}:${a.column+1}`,c=`${o}#${t}`,u=n.serverActionIds.get(r);if(u)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${u.bindingName}" at ${u.source}; conflicts with "${t}" at ${s}.`);let x={id:r,key:c,bindingName:t,filename:o,source:s,loc:a};if(n.serverActionIds.set(r,x),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(x)}catch(h){throw i.buildCodeFrameError(h instanceof Error?h.message:String(h))}}function en(i,n){if(!Ye(i,n))return;let r=Ze(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 t=i.node.arguments[1],o=Qe(t);if(o.property){o.value!==null&&Le(i,n,o.value,r,n.serverActionFilename);return}let a=`wa1_${fn(`${n.serverActionFilename}#${r}`)}`;Le(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));t?e.isObjectExpression(t)?t.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(t)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsComponentVNode=!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=pn(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 t=r.source.value,o=Fe(t),a=o||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let c=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(c=s.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),o?n.whatImports.add(c):t.startsWith(".")||n.foreignImports.add(c)),cn.has(t)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){L(r)},CallExpression(r){en(r,n)},VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let o=t.callee,a="";if(e.isIdentifier(o)?a=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(a=o.property.name),Me.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let c of s.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let o of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(o.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(n.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let o=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){o=a;break}if(o){let a=new Set(o.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||o.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&un(i,e,t),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let o=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[o]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Ae(i,n,K)},JSXFragment(i,n){Ae(i,n,ne)}}}}function un(e,m,d){let y=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){y=E;break}if(y){let E=new Set(y.specifiers.filter(b=>m.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of d)E.has(b.imported.name)||y.specifiers.push(b)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import re from"fs";import q from"path";var Pe=new Set([".jsx",".tsx",".js",".ts"]),dn=new Set(["_layout","_error","_loading","_404"]);function mn(e){let m=[],d=[],y=[];function E(w,C=""){if(!re.existsSync(w))return;let T=re.readdirSync(w,{withFileTypes:!0});for(let A of T){let _=q.join(w,A.name);if(A.isDirectory()){if(A.name.match(/^\((.+)\)$/)){E(_,C);continue}if(A.name==="api"&&C===""){b(_,"/api");continue}E(_,C+"/"+ae(A.name));continue}let J=q.extname(A.name);if(!Pe.has(J))continue;let P=q.basename(A.name,J);if(P==="_layout"){d.push({filePath:_,urlPrefix:C||"/"});continue}if(dn.has(P))continue;let W=ae(P),V=P==="index"?C||"/":C+"/"+W;m.push({filePath:_,routePath:Ne(V),isDynamic:V.includes(":")||V.includes("*")})}}function b(w,C){if(!re.existsSync(w))return;let T=re.readdirSync(w,{withFileTypes:!0});for(let A of T){let _=q.join(w,A.name);if(A.isDirectory()){b(_,C+"/"+ae(A.name));continue}let J=q.extname(A.name);if(!Pe.has(J))continue;let P=q.basename(A.name,J),W=ae(P),V=P==="index"?C:C+"/"+W;y.push({filePath:_,routePath:Ne(V)})}}return E(e),m.sort((w,C)=>{let T=Oe(w.routePath),A=Oe(C.routePath);return T-A}),{pages:m,layouts:d,apiRoutes:y}}function ae(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function Ne(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Oe(e){return e.includes("*")?100:e.includes(":")?10:0}var hn=/export\s+const\s+page\s*=\s*\{/;function gn(e,m={}){let d=hn.exec(e);if(!d)return{mode:"client"};let y=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(yn(e,y))}}catch(E){return En(E,m.filePath),{mode:"client"}}}function En(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
1
+ import Y from"path";import{createRequire as An}from"node:module";import{transformSync as Ln}from"@babel/core";var sn=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),an=new Set(["once","capture","passive"]),ln=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),cn=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),se=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),fn=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),Pe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),un=new Set(["For","Show","Switch","Match"]),pn=new Set(["what-framework/server","what-server","what-server/actions"]);function Ne(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function dn(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 mn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),y=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return y&&d.startsWith(`${y}/`)?d.slice(y.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 y="";for(let E=0;E<m.length;E++){let b=m[E].replace(/\t/g," "),w=E===0,C=E===m.length-1;w||(b=b.replace(/^ +/,"")),C||(b=b.replace(/ +$/,"")),b&&(E!==d&&(b+=" "),y+=b)}return y}function ge({types:e}){let m=new Set,d=new Set;function y(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(o=>o!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),t=r[0],o=r.slice(1).filter(a=>sn.has(a));return{eventName:t,modifiers:o}}function b(i){return i.startsWith("bind:")}function w(i){return i.slice(5)}function C(i){return/^[A-Z]/.test(i)}function D(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let t=i?.node;if(t&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(t,r);let o=t?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${o?`${a}:${o.line}:${o.column+1}`:a})`)}function A(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&C(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 W(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:V(n.node.callee,n.scope)}function V(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?B(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?B(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function B(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let t=i.path.node;if(!n(t))return!1;if(r!==null){let a=t.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let o=i.path.parent;return e.isImportDeclaration(o)&&Ne(o.source.value)}function k(i){return e.isJSXMemberExpression(i)?e.memberExpression(k(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function L(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],t=-1;for(let p=0;p<r.properties.length;p++){let x=r.properties[p];if(e.isRestElement(x))return;if(e.isObjectProperty(x)&&!x.computed&&e.isIdentifier(x.key,{name:"children"})){if(t!==-1||!e.isIdentifier(x.value))return;t=p}}if(t===-1)return;let o=i.scope.getBinding(r.properties[t].value.name);if(!o||o.constantViolations.length>0||o.referencePaths.length===0||!o.referencePaths.every(p=>{let x=p.parentPath;if(!x||!x.isJSXExpressionContainer())return!1;let h=x.parentPath;if(!h||!h.isJSXElement()||!A(h.node))return!1;let l=h.node.openingElement.name;return!(e.isJSXIdentifier(l)&&un.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let c=r.properties.filter((p,x)=>x!==t);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(s))])),i.node._whatMovedProps=p}for(let p of o.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function R(i){return ln.has(String(i).toLowerCase())}function F(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}let Q=new Map([["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"],["acceptCharset","accept-charset"]]);function U(i){return Q.get(i)||i}function te(i,n){let r=U(X(i[n]));for(let t=n+1;t<i.length;t+=1){let o=i[t];if(!e.isJSXSpreadAttribute(o)&&U(X(o))===r)return!0}return!1}function X(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function O(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function ee(i){return!!i&&i.length>2&&/^on/i.test(i)}function ce(i,n){if(n.length===0)return i;let r=i;for(let t of n)switch(t){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 q(i,n){return n.has(i)}function We(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function t(s){let c=s.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,x="";if(e.isIdentifier(p)?x=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(x=p.property.name),Pe.has(x)){let h=s.id;if(e.isIdentifier(h))n.add(h.name);else if(e.isArrayPattern(h))for(let l of h.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(h))for(let l of h.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function o(s){if(e.isObjectPattern(s))for(let c of s.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 a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&t(c.path.node);let s=a.path&&a.path.node;if(s){if(s.params)for(let c of s.params)o(c);s._whatMovedProps&&o(s._whatMovedProps)}a=a.parent}return n}function Ve(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&fn.has(i.callee.property.name)}function be(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?se.has(n.object.name):e.isIdentifier(n)?se.has(n.name):!1}function ye(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)||be(i))return!1;if(i.arguments.some(t=>j(t,n,r)))return!0}return!1}function j(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)?!0:be(i)?i.arguments.some(t=>j(t,n,r)):i.arguments.length===0&&!Ve(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(t=>j(t,n,r)):j(i.callee,n,r)||i.arguments.some(t=>j(t,n,r)):e.isIdentifier(i)?q(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?j(i.object,n,r):e.isConditionalExpression(i)?j(i.test,n,r)||j(i.consequent,n,r)||j(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?j(i.left,n,r)||j(i.right,n,r):e.isUnaryExpression(i)?j(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(t=>j(t,n,r)):e.isObjectExpression(i)?i.properties.some(t=>e.isObjectProperty(t)&&j(t.value,n,r)):e.isArrayExpression(i)?i.elements.some(t=>t&&j(t,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function G(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":G(i.left,n);break;case"RestElement":G(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)G(r,n);break;case"ObjectPattern":for(let r of i.properties)G(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function He(i){let n=new Set;for(let t=1;t<i.params.length;t++)G(i.params[t],n);let r=t=>{if(!(!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(r);return}switch(t.type){case"VariableDeclaration":for(let o of t.declarations)G(o.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":t.id&&n.add(t.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":G(t.param,n),r(t.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(t.init),r(t.left),r(t.body);return;default:break}for(let o of Object.keys(t)){if(o==="loc"||o==="start"||o==="end"||o==="type"||o==="leadingComments"||o==="trailingComments"||o==="innerComments")continue;let a=t[o];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let t of G(i.params[0],new Set))n.delete(t);return n}function Be(i,n){if(n.size===0)return null;let r=null,t=o=>{if(!(r||!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(t);return}if(o.type==="Identifier"){n.has(o.name)&&(r=o.name);return}for(let a of Object.keys(o)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||o.type==="MemberExpression"&&a==="property"&&!o.computed||(o.type==="ObjectProperty"||o.type==="ObjectMethod")&&a==="key"&&!o.computed)continue;let s=o[a];s&&typeof s=="object"&&t(s)}}};return t(i),r}function Se(i,n){let r=i,t=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,t=!0),e.isConditionalExpression(r)){let a=oe(r.consequent,n),s=oe(r.alternate,n);if(a||s){let c=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return t?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=oe(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return t?e.arrowFunctionExpression([],s):s}return null}return oe(r,n)}function oe(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 t=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))t=r.body;else if(e.isBlockStatement(r.body)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}}else if(e.isFunctionExpression(r)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}if(!t||!e.isJSXElement(t))return null;let o=t.openingElement.attributes,a=null;for(let g of o)if(e.isJSXAttribute(g)&&X(g)==="key"){a=g;break}if(!a)return null;let s=F(a.value);if(!s)return null;let c=He(r);if(Be(s,c)){let g=e.isIdentifier(s)&&r.params[1]&&e.isIdentifier(r.params[1],{name:s.name});return null}t.openingElement.attributes=o.filter(g=>g!==a);let x=i.callee.object,h=e.arrowFunctionExpression([],x),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),u=e.arrowFunctionExpression([l],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[h,r,e.objectExpression([e.objectProperty(e.identifier("key"),u),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function fe(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(A(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let t=r.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(fe)}return!1}function we(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function ue(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let t=H(r.value);t&&n.push({kind:"text",text:t});continue}if(e.isJSXFragment(r)){ue(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function pe(i){if(e.isJSXText(i)){let s=H(i.value);return s?ve(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(i))return"";let t=`<${r}`,o=n.attributes.findIndex(s=>e.isJSXSpreadAttribute(s));for(let[s,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||o!==-1&&s>o||te(n.attributes,s))continue;let p=X(c);if(p==="key"||ee(p)||p.startsWith("bind:")||p.includes("|"))continue;let x=U(p);if(!c.value)t+=` ${x}`;else if(e.isStringLiteral(c.value))t+=` ${x}="${Ue(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&R(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of i.children)if(e.isJSXText(s)){let c=H(s.value);c&&(t+=ve(c))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)?A(s)?t+="<!--$-->":t+=pe(s):e.isJSXFragment(s)&&(t+="<!--$-->".repeat(ue(s).length));return t+=`</${r}>`,t}function ve(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ue(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function K(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name;if(!_(o,n)){if(o==="For")return qe(i,n);if(o==="Show")return Ke(i,n)}if(o==="Switch"&&(!_(o,n)||P(r)))return Qe(i,n);if(A(r))return Ce(i,n);let a=t.attributes,s=r.children,c=s.every(fe),p=a.every(f=>!we(f)),x=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let I=X(f);return!I?.startsWith("on")&&!I?.startsWith("bind:")});if(c&&p&&x){let f=pe(r);if(f){let I=Le(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(I),[])}}let h=pe(r);if(!h){let f=r.loc,I=n.filename||n.file?.opts?.filename||"<unknown>",S=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${o}> at ${I}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,de(i,n)}let l=Le(n,h);n.needsTemplate=!0;let u=n.nextVarId(),g=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier(l),[]))])];return _e(g,u,a,n,o),ke(g,u,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...g),e.identifier(u)}function de(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name,a=t.attributes,s=r.children,c=[];for(let h of a){if(e.isJSXSpreadAttribute(h))continue;let l=X(h),u=F(h.value),g=U(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),u))}let p=[];for(let h of s)if(e.isJSXText(h)){let l=H(h.value);l&&p.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||p.push(h.expression):e.isJSXElement(h)?p.push(K({node:h},n)):e.isJSXFragment(h)&&p.push(ne({node:h},n));let x=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(o),x,...p])}let Ge=new Set(["input","textarea","select","option"]);function _e(i,n,r,t,o){function a(x,h){return x==="class"?(t.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),h])):x==="style"?(t.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),h])):x==="value"&&o&&Ge.has(o)?(t.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),h])):x==="checked"&&o==="input"?(t.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),h])):x.startsWith("data-")||x.startsWith("aria-")?(t.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(x),h])):(t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(x),h]))}let s=!1;function c(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let p=!1;for(let[x,h]of r.entries()){if(e.isJSXSpreadAttribute(h)){p=!0,t.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),h.argument])));continue}if(te(r,x))continue;let l=X(h);if(l!=="key"){if(l==="ref"){let u=F(h.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(l.startsWith("on")&&!l.includes("|")&&!y(l,t)){let u=l.slice(2).toLowerCase(),g=F(h.value);cn.has(u)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),g)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),g])));continue}if(l.startsWith("on")&&(l.includes("|")||y(l,t))){let{eventName:u,modifiers:g}=E(l),f=F(h.value),I=ce(f,g),S=u.slice(2).toLowerCase(),v=g.filter(N=>an.has(N)),M=[e.stringLiteral(S),I];if(v.length>0){let N=v.map($=>e.objectProperty(e.identifier($),e.booleanLiteral(!0)));M.push(e.objectExpression(N))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),M)));continue}if(b(l)){let u=w(l),g=h.value.expression;t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(h.value)){let u=h.value.expression,g=U(l);if(j(u,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let f=t.signalNames&&t.signalNames.fromDestructuredProps,I=e.isIdentifier(u)&&!(f&&f.has(u.name))&&q(u.name,t.signalNames)?e.callExpression(u,[]):u,S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(g,I))]);ye(u,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: effect 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(a(g,u)));continue}p&&i.push(e.expressionStatement(a(U(l),F(h.value))))}}}function me(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(me);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"&&me(r))return!0}return!1}function ze(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 Z(i,n,r){let t=null,o=!1;if(e.isConditionalExpression(i))t=i.test,o=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))t=i.left;else return i;if(!j(t,r.signalNames,r.importedIdentifiers)||!(o?[i.consequent,i.alternate]:[i.right]).some(me))return i;let s=r.nextMemoId();r.needsMemo=!0;let c=o?e.unaryExpression("!",e.unaryExpression("!",t)):t;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(s),[]);return o?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function ke(i,n,r,t,o){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let u=l.openingElement.name.name;if(A(l)||u==="For"||u==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let g=l.openingElement.attributes.some(we)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&X(f)?.startsWith("on"))||!l.children.every(fe);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:g}),s++}continue}if(e.isJSXFragment(l))for(let u of ue(l))u.kind==="text"?a.push({type:"fragmentText",text:u.text,childIndex:s}):u.kind==="expression"?a.push({type:"expression",child:u.child,childIndex:s}):a.push({type:"component",child:u.child,childIndex:s}),s++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),p=c.length>=2,x=new Map;if(p){let l=null,u=0;for(let g of c){let f=g.childIndex,I=o.nextVarId();x.set(f,I);let S;if(l===null)S=he(n,f);else{S=e.identifier(l);for(let v=u;v<f;v++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(I),S)])),l=I,u=f}}function h(l){return x.has(l)?e.identifier(x.get(l)):he(n,l)}for(let l of a){if(l.type==="expression"){let u=l.child.expression,g=h(l.childIndex);o.needsInsert=!0;let f=Se(u,o);if(f){o.needsMapArray=!0;let S=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),v=e.isArrowFunctionExpression(f);v&&e.isExpression(f.body)?f.body=Z(f.body,i,o):!S&&!v&&(f=Z(f,i,o));let M=S||v?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,g])));continue}if(e.isCallExpression(u)&&e.isIdentifier(u.callee)&&(u.callee.name==="mapArray"||u.callee.name==="_$mapArray")){o.needsMapArray=!0,u.callee.name==="mapArray"&&(u.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(j(u,o.signalNames,o.importedIdentifiers)){u=Z(u,i,o);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],u),g]);ye(u,o.signalNames,o.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),u,g])));continue}if(l.type==="component"){let u=K({node:l.child},o),g=h(l.childIndex);o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let u;x.has(l.childIndex)?u=x.get(l.childIndex):(u=o.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),he(n,l.childIndex))]))),_e(i,u,l.child.openingElement.attributes,o,l.child.openingElement.name.name),ke(i,u,l.child.children,l.child,o);continue}if(l.type==="fragmentText"){o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),h(l.childIndex)])));continue}}}function he(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 t=0;t<n;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function Ce(i,n){let{node:r}=i,t=r.openingElement,o=k(t.name),a=t.attributes,s=r.children,c=null,p=[];for(let S of a){if(e.isJSXAttribute(S)){let v;if(e.isJSXNamespacedName(S.name)?v=`${S.name.namespace.name}:${S.name.name.name}`:v=S.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let M=v.slice(7);S.value?c={type:M,value:S.value.value}:c={type:M};continue}}p.push(S)}function x(){let S=n._pendingSetup?n._pendingSetup.length:0,v=[],M=!1;for(let $ of s)if(e.isJSXText($)){let T=H($.value);T&&v.push(e.stringLiteral(T))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(M=!0,v.push(Ae($.expression,n)));else if(e.isJSXElement($)){let T=$.openingElement.name.name;T!=="For"&&T!=="Show"&&T!=="Switch"&&(M=!0),v.push(K({node:$},n))}else e.isJSXFragment($)&&(M=!0,v.push(ne({node:$},n)));let N=e.arrayExpression(v);if(M){let $=n._pendingSetup?n._pendingSetup.splice(S):[];N=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(N)]):N)}return N}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let S=[e.objectProperty(e.identifier("component"),o),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&S.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let v=[],M=[],N=()=>{M.length>0&&(v.push(e.objectExpression(M)),M=[])};for(let T of p){if(e.isJSXSpreadAttribute(T)){N(),v.push(T.argument);continue}let ie=X(T);if(ie==="key")continue;let on=F(T.value);M.push(e.objectProperty(O(ie),on))}let $;return v.length===0?$=e.objectExpression([...M,...S]):(N(),$=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...v,e.objectExpression(S)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),$,x()])}let h=W(i);h?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],u=[],g=()=>{u.length>0&&(l.push(e.objectExpression(u)),u=[])};for(let S of p){if(e.isJSXSpreadAttribute(S)){g(),l.push(S.argument);continue}let v=X(S);if(v==="key")continue;if(b(v)){let N=w(v),$=S.value.expression;N==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):N==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||y(v,n))){let{eventName:N,modifiers:$}=E(v),T=F(S.value),ie=ce(T,$);u.push(e.objectProperty(e.identifier(N),ie));continue}let M=F(S.value);u.push(e.objectProperty(O(v),M))}g();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let I=x();return e.callExpression(e.identifier(h?"_$componentVNode":"_$createComponent"),[o,f,I])}function qe(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null,c=null;for(let $ of t)if(e.isJSXAttribute($)){let T=X($);T==="each"?a=F($.value):T==="key"?s=F($.value):T==="fallback"&&(c=F($.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,de(i,n);let p=null;for(let $ of o)if(e.isJSXExpressionContainer($)&&!e.isJSXEmptyExpression($.expression)){p=$.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,de(i,n);n.needsMapArray=!0;let x=$=>{let T=[$,p];return s&&T.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),T)};if(!c)return x(a);n._pendingSetup||(n._pendingSetup=[]);let h=n.nextForIndex(),l=`_each$${h}`,u=`_for$${h}`,g=`_fb$${h}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let I=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(I,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(I),e.memberExpression(e.cloneNode(I),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),x(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let v=e.identifier("_parent"),M=e.identifier("_marker"),N=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([v,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(N,e.callExpression(e.identifier(u),[e.cloneNode(v),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(v),e.arrayExpression([e.identifier(g)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(N))])),e.identifier(u)])}function Ke(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null;for(let g of t)if(e.isJSXAttribute(g)){let f=X(g);f==="when"?a=F(g.value):f==="fallback"&&(s=F(g.value))}if(!a)throw D(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let g of o)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){c=g.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let g=n._pendingSetup.length,f=[];for(let S of o)if(e.isJSXText(S)){let v=H(S.value);v&&f.push(e.stringLiteral(v))}else e.isJSXElement(S)&&f.push(K({node:S},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let I=n._pendingSetup.splice(g);I.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...I,e.returnStatement(c)])),[]))}let p=$e(a,n),x=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),h=e.isFunction(c),l=h?e.callExpression(c,[e.cloneNode(x)]):c,u=s||e.nullLiteral();if(j(p,n.signalNames,n.importedIdentifiers)){let g=n.nextMemoId();n.needsMemo=!0;let f=h?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),p=e.callExpression(e.identifier(g),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(x),l,u))]))}function $e(i,n){if(e.isCallExpression(i))return i;if(e.isArrowFunctionExpression(i)&&e.isExpression(i.body))return i.body;let r=n.signalNames&&n.signalNames.fromDestructuredProps,t=a=>r&&r.has(a)||n.importedIdentifiers&&n.importedIdentifiers.has(a);if(e.isIdentifier(i))return t(i.name)?Ie(i):n.signalNames&&q(i.name,n.signalNames)?e.callExpression(i,[]):i;let o=Ze(i);return o&&t(o.name)?Ie(i):i}function Ze(i){if(!e.isMemberExpression(i))return null;let n=i;for(;e.isMemberExpression(n);){if(n.computed||!e.isIdentifier(n.property))return null;n=n.object}return e.isIdentifier(n)?n:null}function Ie(i){return e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",i),e.stringLiteral("function")),e.callExpression(e.cloneNode(i),[]),e.cloneNode(i))}function Ye(i,n){let r=[];for(let t of i)if(e.isJSXText(t)){let o=H(t.value);o&&r.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||r.push(t.expression):e.isJSXElement(t)?r.push(K({node:t},n)):e.isJSXFragment(t)&&r.push(ne({node:t},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Qe(i,n){let{node:r}=i,t=_(r.openingElement.name.name,n),o=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(t||!_("Match",n));if(!r.children.some(o)&&!J(r.openingElement.name.name,n))return Ce(i,n);let a=f=>{throw D(i,n,`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),X(f)==="fallback"&&(s=F(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){H(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}o(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let f of c){let I=null;for(let N of f.openingElement.attributes)e.isJSXAttribute(N)&&X(N)==="when"&&(I=F(N.value));I||a('has a <Match> with no "when" prop');let S=n._pendingSetup.length,v=Ye(f.children,n),M=n._pendingSetup.splice(S);M.length>0&&(v=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(v)])),[])),p.push([$e(I,n),v])}let x=p.some(([f])=>j(f,n.signalNames,n.importedIdentifiers)),h=s||e.nullLiteral();if(!x){let f=h;for(let I=p.length-1;I>=0;I--)f=e.conditionalExpression(p[I][0],p[I][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=p.length-1;f>=0;f--)l=e.conditionalExpression(p[f][0],e.numericLiteral(f),l);let u=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let g=h;for(let f=p.length-1;f>=0;f--)g=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(u),[]),e.numericLiteral(f)),p[f][1],g);return e.arrowFunctionExpression([],g)}function Ae(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,t=Se(i,n);if(t){n.needsMapArray=!0;let a=e.isCallExpression(t)&&e.isIdentifier(t.callee)&&(t.callee.name==="_$mapArray"||t.callee.name==="mapArray");if(e.isArrowFunctionExpression(t)&&e.isExpression(t.body))return t.body=Z(t.body,r,n),t;if(a)return t;let c=Z(t,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):j(i,n.signalNames,n.importedIdentifiers)?(i=Z(i,r,n),e.arrowFunctionExpression([],i)):i}function ne(i,n){let{node:r}=i,t=r.children,o=[];for(let a of t)if(e.isJSXText(a)){let s=H(a.value);s&&o.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||o.push(Ae(a.expression,n)):e.isJSXElement(a)?o.push(K({node:a},n)):e.isJSXFragment(a)&&o.push(ne({node:a},n));return o.length===1?o[0]:e.arrayExpression(o)}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 Me(i,n,r){let t=i.scope,o=n._signalNamesCache;o||(o=n._signalNamesCache=new WeakMap);let a=o.get(t);a||(a=We(i),o.set(t,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,x=!1,h=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(x=!0),ze(p)&&(h=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!x&&!h?(p.insertBefore(c),i.replaceWith(s)):(c.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(s)}function en(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 nn(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 rn(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,t,o){let a=i.node.loc?.start||{line:0,column:0},s=`${o}:${a.line}:${a.column+1}`,c=`${o}#${t}`,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 "${t}" at ${s}.`);let x={id:r,key:c,bindingName:t,filename:o,source:s,loc:a};if(n.serverActionIds.set(r,x),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(x)}catch(h){throw i.buildCodeFrameError(h instanceof Error?h.message:String(h))}}function tn(i,n){if(!nn(i,n))return;let r=en(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 t=i.node.arguments[1],o=rn(t);if(o.property){o.value!==null&&Fe(i,n,o.value,r,n.serverActionFilename);return}let a=`wa1_${dn(`${n.serverActionFilename}#${r}`)}`;Fe(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));t?e.isObjectExpression(t)?t.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(t)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsComponentVNode=!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=mn(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 t=r.source.value,o=Ne(t),a=o||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let c=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(c=s.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),o?n.whatImports.add(c):t.startsWith(".")||n.foreignImports.add(c)),pn.has(t)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){L(r)},CallExpression(r){tn(r,n)},VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let o=t.callee,a="";if(e.isIdentifier(o)?a=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(a=o.property.name),Pe.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let c of s.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let o of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(o.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(n.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let o=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){o=a;break}if(o){let a=new Set(o.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||o.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&hn(i,e,t),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let o=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[o]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Me(i,n,K)},JSXFragment(i,n){Me(i,n,ne)}}}}function hn(e,m,d){let y=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){y=E;break}if(y){let E=new Set(y.specifiers.filter(b=>m.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of d)E.has(b.imported.name)||y.specifiers.push(b)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import re from"fs";import z from"path";var Oe=new Set([".jsx",".tsx",".js",".ts"]),gn=new Set(["_layout","_error","_loading","_404"]);function En(e){let m=[],d=[],y=[];function E(w,C=""){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){if(A.name.match(/^\((.+)\)$/)){E(_,C);continue}if(A.name==="api"&&C===""){b(_,"/api");continue}E(_,C+"/"+ae(A.name));continue}let J=z.extname(A.name);if(!Oe.has(J))continue;let P=z.basename(A.name,J);if(P==="_layout"){d.push({filePath:_,urlPrefix:C||"/"});continue}if(gn.has(P))continue;let W=ae(P),V=P==="index"?C||"/":C+"/"+W;m.push({filePath:_,routePath:je(V),isDynamic:V.includes(":")||V.includes("*")})}}function b(w,C){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){b(_,C+"/"+ae(A.name));continue}let J=z.extname(A.name);if(!Oe.has(J))continue;let P=z.basename(A.name,J),W=ae(P),V=P==="index"?C:C+"/"+W;y.push({filePath:_,routePath:je(V)})}}return E(e),m.sort((w,C)=>{let D=Te(w.routePath),A=Te(C.routePath);return D-A}),{pages:m,layouts:d,apiRoutes:y}}function ae(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function je(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Te(e){return e.includes("*")?100:e.includes(":")?10:0}var xn=/export\s+const\s+page\s*=\s*\{/;function bn(e,m={}){let d=xn.exec(e);if(!d)return{mode:"client"};let y=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(vn(e,y))}}catch(E){return yn(E,m.filePath),{mode:"client"}}}function yn(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 xn=e=>/[A-Za-z_$]/.test(e),bn=e=>/[A-Za-z0-9_$]/.test(e);function yn(e,m){let d=[],y=-1,E=0,b=m;for(;b<e.length;){let w=e[b];if(w==="/"&&e[b+1]==="/"){let C=e.indexOf(`
4
- `,b);b=C===-1?e.length:C,d.push(" ");continue}if(w==="/"&&e[b+1]==="*"){let C=e.indexOf("*/",b+2);if(C===-1)throw new SyntaxError("unterminated block comment");b=C+2,d.push(" ");continue}if(w==='"'||w==="'"||w==="`"){let C=wn(e,b);d.push(JSON.stringify(C.value)),y=-1,b=C.end;continue}if(xn(w)){let C=b+1;for(;C<e.length&&bn(e[C]);)C++;let T=e.slice(b,C);d.push(Sn(e,C)?JSON.stringify(T):T),y=-1,b=C;continue}if(w===" "||w===" "||w===`
5
- `||w==="\r"){d.push(w),b++;continue}if(w===","){d.push(","),y=d.length-1,b++;continue}if(w==="}"||w==="]"){if(y!==-1&&(d[y]=""),y=-1,d.push(w),b++,w==="}"&&--E===0)return d.join("");continue}w==="{"&&E++,d.push(w),y=-1,b++}throw new SyntaxError("unterminated object literal")}function Sn(e,m){let d=m;for(;d<e.length;){let y=e[d];if(y===" "||y===" "||y===`
3
+ \`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var Sn=e=>/[A-Za-z_$]/.test(e),wn=e=>/[A-Za-z0-9_$]/.test(e);function vn(e,m){let d=[],y=-1,E=0,b=m;for(;b<e.length;){let w=e[b];if(w==="/"&&e[b+1]==="/"){let C=e.indexOf(`
4
+ `,b);b=C===-1?e.length:C,d.push(" ");continue}if(w==="/"&&e[b+1]==="*"){let C=e.indexOf("*/",b+2);if(C===-1)throw new SyntaxError("unterminated block comment");b=C+2,d.push(" ");continue}if(w==='"'||w==="'"||w==="`"){let C=kn(e,b);d.push(JSON.stringify(C.value)),y=-1,b=C.end;continue}if(Sn(w)){let C=b+1;for(;C<e.length&&wn(e[C]);)C++;let D=e.slice(b,C);d.push(_n(e,C)?JSON.stringify(D):D),y=-1,b=C;continue}if(w===" "||w===" "||w===`
5
+ `||w==="\r"){d.push(w),b++;continue}if(w===","){d.push(","),y=d.length-1,b++;continue}if(w==="}"||w==="]"){if(y!==-1&&(d[y]=""),y=-1,d.push(w),b++,w==="}"&&--E===0)return d.join("");continue}w==="{"&&E++,d.push(w),y=-1,b++}throw new SyntaxError("unterminated object literal")}function _n(e,m){let d=m;for(;d<e.length;){let y=e[d];if(y===" "||y===" "||y===`
6
6
  `||y==="\r"){d++;continue}if(y==="/"&&e[d+1]==="/"){let E=e.indexOf(`
7
- `,d);if(E===-1)return!1;d=E+1;continue}if(y==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return y===":"}return!1}var je={n:`
8
- `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function wn(e,m){let d=e[m],y="",E=m+1;for(;E<e.length;){let b=e[E];if(b==="\\"){let w=e[E+1];if(w===void 0)break;if(w===`
7
+ `,d);if(E===-1)return!1;d=E+1;continue}if(y==="/"&&e[d+1]==="*"){let E=e.indexOf("*/",d+2);if(E===-1)return!1;d=E+2;continue}return y===":"}return!1}var De={n:`
8
+ `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function kn(e,m){let d=e[m],y="",E=m+1;for(;E<e.length;){let b=e[E];if(b==="\\"){let w=e[E+1];if(w===void 0)break;if(w===`
9
9
  `){E+=2;continue}if(w==="\r"){E+=e[E+2]===`
10
- `?3:2;continue}if(w==="u"){if(e[E+2]==="{"){let C=e.indexOf("}",E+3);if(C===-1)throw new SyntaxError("invalid unicode escape");y+=String.fromCodePoint(parseInt(e.slice(E+3,C),16)),E=C+1;continue}y+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(w==="x"){y+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}y+=Object.prototype.hasOwnProperty.call(je,w)?je[w]:w,E+=2;continue}if(b===d)return{value:y,end:E+1};if(d==="`"&&b==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(b===`
11
- `||b==="\r"))break;y+=b,E++}throw new SyntaxError("unterminated string literal")}function vn(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:y,apiRoutes:E}=mn(e),b=[],w=[],C=new Map;y.forEach((_,J)=>{let P=`_layout${J}`,W=ge(_.filePath,m);b.push(`import ${P} from '${W}';`),C.set(_.urlPrefix,P)}),d.forEach((_,J)=>{let P=`_page${J}`,W=ge(_.filePath,m);b.push(`import ${P} from '${W}';`);let V={mode:"client"},B={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let X=re.readFileSync(_.filePath,"utf-8");V=gn(X,{filePath:_.filePath}),B=vn(X)}catch{}let k=_n(_.routePath,C),L={path:_.routePath,component:P,mode:V.mode||"client",layout:k||null,hasLoader:B.hasLoader};w.push(L)});let T=[];return E.forEach((_,J)=>{let P=`_api${J}`,W=ge(_.filePath,m);b.push(`import * as ${P} from '${W}';`),T.push({path:_.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...b,"","export const routes = [",...w.map(_=>` { path: '${_.path}', component: ${_.component}, mode: '${_.mode}'${_.layout?`, layout: ${_.layout}`:""}${_.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...T.map(_=>` { path: '${_.path}', handlers: ${_.handlers} },`),"];","","export const pageModes = {",...w.map(_=>` '${_.path}': '${_.mode}',`),"};"].join(`
12
- `)}function ge(e,m){return"/"+q.relative(m,e).split(q.sep).join("/")}function _n(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let y="/"+d.join("/");if(m.has(y))return m.get(y);d.pop()}return m.has("/")?m.get("/"):null}var kn=`
10
+ `?3:2;continue}if(w==="u"){if(e[E+2]==="{"){let C=e.indexOf("}",E+3);if(C===-1)throw new SyntaxError("invalid unicode escape");y+=String.fromCodePoint(parseInt(e.slice(E+3,C),16)),E=C+1;continue}y+=String.fromCharCode(parseInt(e.slice(E+2,E+6),16)),E+=6;continue}if(w==="x"){y+=String.fromCharCode(parseInt(e.slice(E+2,E+4),16)),E+=4;continue}y+=Object.prototype.hasOwnProperty.call(De,w)?De[w]:w,E+=2;continue}if(b===d)return{value:y,end:E+1};if(d==="`"&&b==="$"&&e[E+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(d!=="`"&&(b===`
11
+ `||b==="\r"))break;y+=b,E++}throw new SyntaxError("unterminated string literal")}function Cn(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 Je(e,m){let{pages:d,layouts:y,apiRoutes:E}=En(e),b=[],w=[],C=new Map;y.forEach((_,J)=>{let P=`_layout${J}`,W=Ee(_.filePath,m);b.push(`import ${P} from '${W}';`),C.set(_.urlPrefix,P)}),d.forEach((_,J)=>{let P=`_page${J}`,W=Ee(_.filePath,m);b.push(`import ${P} from '${W}';`);let V={mode:"client"},B={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let R=re.readFileSync(_.filePath,"utf-8");V=bn(R,{filePath:_.filePath}),B=Cn(R)}catch{}let k=$n(_.routePath,C),L={path:_.routePath,component:P,mode:V.mode||"client",layout:k||null,hasLoader:B.hasLoader};w.push(L)});let D=[];return E.forEach((_,J)=>{let P=`_api${J}`,W=Ee(_.filePath,m);b.push(`import * as ${P} from '${W}';`),D.push({path:_.routePath,handlers:P})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...b,"","export const routes = [",...w.map(_=>` { path: '${_.path}', component: ${_.component}, mode: '${_.mode}'${_.layout?`, layout: ${_.layout}`:""}${_.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...D.map(_=>` { path: '${_.path}', handlers: ${_.handlers} },`),"];","","export const pageModes = {",...w.map(_=>` '${_.path}': '${_.mode}',`),"};"].join(`
12
+ `)}function Ee(e,m){return"/"+z.relative(m,e).split(z.sep).join("/")}function $n(e,m){let d=e.split("/").filter(Boolean);for(;d.length>0;){let y="/"+d.join("/");if(m.has(y))return m.get(y);d.pop()}return m.has("/")?m.get("/"):null}var In=`
13
13
  :host {
14
14
  position: fixed;
15
15
  inset: 0;
@@ -195,12 +195,12 @@ import Q from"path";import{createRequire as Cn}from"node:module";import{transfor
195
195
  white-space: pre-wrap;
196
196
  line-height: 1.5;
197
197
  }
198
- `,Un=`
198
+ `,qn=`
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>${kn}</style>';
203
+ this.root.innerHTML = '<style>${In}</style>';
204
204
  this._err = err;
205
205
  this.show(err);
206
206
  }
@@ -390,13 +390,13 @@ class WhatErrorOverlay extends HTMLElement {
390
390
  if (!customElements.get('what-error-overlay')) {
391
391
  customElements.define('what-error-overlay', WhatErrorOverlay);
392
392
  }
393
- `;function Te(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",le="\0"+Je,In=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,An=/\.[cm]?[jt]sx?$/;function Ee(e,m){return e?Array.isArray(e)?e.some(d=>Ee(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function Ln({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}async function Mn(e){try{return Cn(Q.resolve(e||process.cwd(),"package.json"))("vite/package.json").version||""}catch{return import("vite").then(m=>m.version||"").catch(()=>"")}}var Fn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,Pn=/(?:store|signal|state|context|util|helper|lib|config)\b/i,Nn=/\b_\$(?:template|createComponent)\b/;function On(e){return Nn.test(e)}function jn(e){return Object.assign(new Error(`[what-compiler] ${e} is being compiled for the server, but what-compiler's JSX output is client-only. It lowers JSX to module-scope _$template() calls that run document.createElement() at import time, so this module throws "document is not defined" the moment a server imports it.
393
+ `;function Re(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 Xe="virtual:what-routes",le="\0"+Xe,Mn=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,Fn=/\.[cm]?[jt]sx?$/;function xe(e,m){return e?Array.isArray(e)?e.some(d=>xe(d,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function Pn({rolldownVersion:e,viteVersion:m}={}){let d=parseInt(String(m??""),10);return!!e||Number.isFinite(d)&&d>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}async function Nn(e){try{return An(Y.resolve(e||process.cwd(),"package.json"))("vite/package.json").version||""}catch{return import("vite").then(m=>m.version||"").catch(()=>"")}}var On=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,jn=/(?:store|signal|state|context|util|helper|lib|config)\b/i,Tn=/\b_\$(?:template|createComponent)\b/;function Dn(e){return Tn.test(e)}function Jn(e){return Object.assign(new Error(`[what-compiler] ${e} is being compiled for the server, but what-compiler's JSX output is client-only. It lowers JSX to module-scope _$template() calls that run document.createElement() at import time, so this module throws "document is not defined" the moment a server imports it.
394
394
 
395
395
  Server-rendered views have two supported spellings:
396
396
  1. Author them with h() from what-framework.
397
397
  2. Compile them with the automatic JSX runtime instead of what-compiler (jsxImportSource: "what-framework"), which emits h() calls that renderToString and renderToHydratableString understand.
398
398
 
399
- If a DOM already exists in this process on purpose, set ssrGuard: false on the plugin. The likeliest reason is a test runner: Vitest applies an SSR transform under \`environment: 'node'\`, so a component test that shims a DOM itself lands here. Note that with the guard off the result is a full client render, not SSR.`),{code:"ERR_COMPILED_JSX_IN_SSR",id:e,plugin:"vite-plugin-what"})}function Dn(e,m){if(e&&e.ssr)return!0;let d=m&&m.environment;return!!(d&&d.name==="ssr")}function Tn(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:y=!0,production:E=!0,pages:b="src/pages",hot:w=!E,prodBundles:C=!0,ssrGuard:T=!0}=e,A="",_="",J=!1,P=new Map;function W(k){let L=P.get(k.id);if(L&&L.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${L.bindingName}" at ${L.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});P.set(k.id,k)}function V(k){for(let[L,X]of P)X.filename===k&&P.delete(L)}function B(k){let L=k.replace(/[?#].*$/,"");return A?Q.relative(A,L).split(Q.sep).join("/"):L}return{name:"vite-plugin-what",configResolved(k){A=k.root,_=Q.resolve(A,b),J=k.command==="serve"},configureServer(k){Te(k),k.watcher.on("add",L=>{if(L.startsWith(_)){let X=k.moduleGraph.getModuleById(le);X&&(k.moduleGraph.invalidateModule(X),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",L=>{if(V(B(L)),L.startsWith(_)){let X=k.moduleGraph.getModuleById(le);X&&(k.moduleGraph.invalidateModule(X),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===Je)return le},load(k){if(k===le)return De(_,A)},transform(k,L,X){let F=L.replace(/[?#].*$/,""),U=Ee(m,F),ee=An.test(F),R=ee&&In.test(k);if(d&&Ee(d,F)||(ee&&V(B(F)),!U&&!R))return null;let te=T&&Dn(X,this);try{let D=$n(k,{filename:L,sourceMaps:y,configFile:!1,babelrc:!1,plugins:[[he,{production:E,projectRoot:A||process.cwd(),onActionId:W}]],parserOpts:{plugins:["jsx","typescript"]}});if(!D||!D.code)return null;let Z=D.code;if(te&&On(Z))throw jn(F);return w&&J&&!E&&Jn(k,L)&&(Z+=Rn(L)),{code:Z,map:D.map}}catch(D){throw D&&D.code==="ERR_COMPILED_JSX_IN_SSR"||(D.plugin="vite-plugin-what",D.id||(D.id=L),D.loc===void 0&&D._loc&&(D.loc={file:L,line:D._loc.line,column:D._loc.column}),console.error(`[what] Error transforming ${L}:`,D.message)),D}},handleHotUpdate({file:k,server:L}){if(w&&m.test(k)&&!(d&&d.test(k))&&Xn(k))return L.ws.send({type:"full-reload"}),[]},async config(k,{mode:L,command:X}){let F=X==="build"&&L==="production"&&C,U=Ln({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Mn(k.root)});return{...F?{resolve:{conditions:["production"]}}:{},...U,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function Jn(e,m){return!!(Fn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function Xn(e){let m=Q.basename(e,Q.extname(e));return Pn.test(m)}function Rn(e){return`
399
+ If a DOM already exists in this process on purpose, set ssrGuard: false on the plugin. The likeliest reason is a test runner: Vitest applies an SSR transform under \`environment: 'node'\`, so a component test that shims a DOM itself lands here. Note that with the guard off the result is a full client render, not SSR.`),{code:"ERR_COMPILED_JSX_IN_SSR",id:e,plugin:"vite-plugin-what"})}function Rn(e,m){if(e&&e.ssr)return!0;let d=m&&m.environment;return!!(d&&d.name==="ssr")}function Xn(e={}){let{include:m=/\.[jt]sx$/,exclude:d=/node_modules/,sourceMaps:y=!0,production:E=!0,pages:b="src/pages",hot:w=!E,prodBundles:C=!0,ssrGuard:D=!0}=e,A="",_="",J=!1,P=new Map;function W(k){let L=P.get(k.id);if(L&&L.key!==k.key)throw Object.assign(new Error(`Duplicate server action ID "${k.id}". First declared by "${L.bindingName}" at ${L.source}; conflicts with "${k.bindingName}" at ${k.source}.`),{code:"ERR_DUPLICATE_ACTION_ID"});P.set(k.id,k)}function V(k){for(let[L,R]of P)R.filename===k&&P.delete(L)}function B(k){let L=k.replace(/[?#].*$/,"");return A?Y.relative(A,L).split(Y.sep).join("/"):L}return{name:"vite-plugin-what",configResolved(k){A=k.root,_=Y.resolve(A,b),J=k.command==="serve"},configureServer(k){Re(k),k.watcher.on("add",L=>{if(L.startsWith(_)){let R=k.moduleGraph.getModuleById(le);R&&(k.moduleGraph.invalidateModule(R),k.ws.send({type:"full-reload"}))}}),k.watcher.on("unlink",L=>{if(V(B(L)),L.startsWith(_)){let R=k.moduleGraph.getModuleById(le);R&&(k.moduleGraph.invalidateModule(R),k.ws.send({type:"full-reload"}))}})},resolveId(k){if(k===Xe)return le},load(k){if(k===le)return Je(_,A)},transform(k,L,R){let F=L.replace(/[?#].*$/,""),Q=xe(m,F),U=Fn.test(F),te=U&&Mn.test(k);if(d&&xe(d,F)||(U&&V(B(F)),!Q&&!te))return null;let X=D&&Rn(R,this);try{let O=Ln(k,{filename:L,sourceMaps:y,configFile:!1,babelrc:!1,plugins:[[ge,{production:E,projectRoot:A||process.cwd(),onActionId:W}]],parserOpts:{plugins:["jsx","typescript"]}});if(!O||!O.code)return null;let ee=O.code;if(X&&Dn(ee))throw Jn(F);return w&&J&&!E&&Wn(k,L)&&(ee+=Hn(L)),{code:ee,map:O.map}}catch(O){throw O&&O.code==="ERR_COMPILED_JSX_IN_SSR"||(O.plugin="vite-plugin-what",O.id||(O.id=L),O.loc===void 0&&O._loc&&(O.loc={file:L,line:O._loc.line,column:O._loc.column}),console.error(`[what] Error transforming ${L}:`,O.message)),O}},handleHotUpdate({file:k,server:L}){if(w&&m.test(k)&&!(d&&d.test(k))&&Vn(k))return L.ws.send({type:"full-reload"}),[]},async config(k,{mode:L,command:R}){let F=R==="build"&&L==="production"&&C,Q=Pn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await Nn(k.root)});return{...F?{resolve:{conditions:["production"]}}:{},...Q,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function Wn(e,m){return!!(On.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function Vn(e){let m=Y.basename(e,Y.extname(e));return jn.test(m)}function Hn(e){return`
400
400
 
401
401
  // --- What Framework HMR Boundary ---
402
402
  if (import.meta.hot) {
@@ -409,4 +409,4 @@ if (import.meta.hot) {
409
409
  }
410
410
  });
411
411
  }
412
- `}export{Tn as default,Ln as jsxPreserveConfig,Tn as what};
412
+ `}export{Xn as default,Pn as jsxPreserveConfig,Xn as what};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-compiler",
3
- "version": "0.13.9",
3
+ "version": "0.13.10",
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.13.9"
52
+ "what-core": "^0.13.10"
53
53
  },
54
54
  "files": [
55
55
  "src",
@@ -411,10 +411,20 @@ export default function whatBabelPlugin({ types: t }) {
411
411
  return t.stringLiteral(value.value || '');
412
412
  }
413
413
 
414
+ // Prop names whose HTML attribute is not just the prop name in another case.
415
+ // A static attribute is baked into a template string that the HTML parser
416
+ // reads, and the parser only lowercases names, so an unrenamed
417
+ // `httpEquiv="refresh"` became a meaningless `httpequiv` attribute. The h()
418
+ // path and what-server rename the same set.
419
+ const ATTRIBUTE_ALIASES = new Map([
420
+ ['className', 'class'],
421
+ ['htmlFor', 'for'],
422
+ ['httpEquiv', 'http-equiv'],
423
+ ['acceptCharset', 'accept-charset'],
424
+ ]);
425
+
414
426
  function normalizeAttrName(attrName) {
415
- if (attrName === 'className') return 'class';
416
- if (attrName === 'htmlFor') return 'for';
417
- return attrName;
427
+ return ATTRIBUTE_ALIASES.get(attrName) || attrName;
418
428
  }
419
429
 
420
430
  // Is this attribute overwritten by a later one naming the same DOM property?
@@ -1200,9 +1210,7 @@ export default function whatBabelPlugin({ types: t }) {
1200
1210
  // matching how the runtime and SSR paths treat them.
1201
1211
  if (isEventAttrName(name) || name.startsWith('bind:') || name.includes('|')) continue;
1202
1212
 
1203
- let domName = name;
1204
- if (name === 'className') domName = 'class';
1205
- if (name === 'htmlFor') domName = 'for';
1213
+ const domName = normalizeAttrName(name);
1206
1214
 
1207
1215
  if (!attr.value) {
1208
1216
  html += ` ${domName}`;
@@ -1655,17 +1663,21 @@ export default function whatBabelPlugin({ types: t }) {
1655
1663
 
1656
1664
  if (isPotentiallyReactive(expr, state.signalNames, state.importedIdentifiers)) {
1657
1665
  state.needsEffect = true;
1658
- // Auto-invoke bare signal/imported identifiers: value={name} -> name()
1666
+ // Auto-invoke a bare identifier only when it is a PROVEN signal:
1667
+ // value={count} -> count() for a local `const count = signal(...)`.
1659
1668
  //
1660
- // Never a destructured prop: it holds whatever the parent passed,
1661
- // which for `_$createComponent` is a plain value, and calling it
1662
- // threw. The runtime setters resolve a function value themselves, so
1663
- // an uncalled identifier is correct for a prop either way.
1669
+ // Never a destructured prop or an import. Either one can hold any
1670
+ // value: a prop is whatever the parent passed, and an import is
1671
+ // whatever the other module exported (`href={DOCS_URL}` with a string
1672
+ // constant is the common case). Calling one of those threw
1673
+ // "X is not a function". The runtime setters resolve a function value
1674
+ // as a reactive accessor themselves, exactly as h() does, so the
1675
+ // uncalled identifier is correct for a plain value AND keeps an
1676
+ // imported signal live.
1664
1677
  const fromProps = state.signalNames && state.signalNames.fromDestructuredProps;
1665
1678
  const valueExpr = t.isIdentifier(expr) &&
1666
1679
  !(fromProps && fromProps.has(expr.name)) &&
1667
- (isSignalIdentifier(expr.name, state.signalNames) ||
1668
- (state.importedIdentifiers && state.importedIdentifiers.has(expr.name)))
1680
+ isSignalIdentifier(expr.name, state.signalNames)
1669
1681
  ? t.callExpression(expr, [])
1670
1682
  : expr;
1671
1683
  const effectCall = t.callExpression(t.identifier('_$effect'), [
@@ -2789,26 +2801,58 @@ export default function whatBabelPlugin({ types: t }) {
2789
2801
  // A `when` prop's shape determines how the condition is formed:
2790
2802
  // - call expression → use as-is when={cond()}
2791
2803
  // - arrow w/ expression body → use the body when={() => x > 5}
2792
- // - identifier that looks like a signal/import when={isOpen}
2793
- // → invoke it as accessor: isOpen()
2804
+ // - a proven local signal → invoke it: isOpen() when={isOpen}
2805
+ // - an import or a destructured prop, bare or as the root of a plain
2806
+ // member chain when={FLAG}, when={ns.open}
2807
+ // → resolve it at runtime, exactly as the Show
2808
+ // and Match components do for h():
2809
+ // typeof X === 'function' ? X() : X
2810
+ // Either one can hold a boolean or an accessor
2811
+ // and only the runtime knows which. Calling it
2812
+ // unconditionally threw on a boolean.
2794
2813
  // - anything else (member, literal, logical, etc.) when={user.isAdmin}
2795
2814
  // → use the raw expression. Do NOT invoke it:
2796
2815
  // non-functions would throw at runtime.
2797
2816
  function buildWhenCondition(whenExpr, state) {
2798
2817
  if (t.isCallExpression(whenExpr)) return whenExpr;
2799
2818
  if (t.isArrowFunctionExpression(whenExpr) && t.isExpression(whenExpr.body)) return whenExpr.body;
2800
- if (
2801
- t.isIdentifier(whenExpr) &&
2802
- (
2803
- (state.signalNames && isSignalIdentifier(whenExpr.name, state.signalNames)) ||
2804
- (state.importedIdentifiers && state.importedIdentifiers.has(whenExpr.name))
2805
- )
2806
- ) {
2807
- return t.callExpression(whenExpr, []);
2808
- }
2819
+ const fromProps = state.signalNames && state.signalNames.fromDestructuredProps;
2820
+ const isUnprovenBinding = name =>
2821
+ (fromProps && fromProps.has(name)) ||
2822
+ (state.importedIdentifiers && state.importedIdentifiers.has(name));
2823
+ if (t.isIdentifier(whenExpr)) {
2824
+ if (isUnprovenBinding(whenExpr.name)) return resolveAccessorAtRuntime(whenExpr);
2825
+ if (state.signalNames && isSignalIdentifier(whenExpr.name, state.signalNames)) {
2826
+ return t.callExpression(whenExpr, []);
2827
+ }
2828
+ return whenExpr;
2829
+ }
2830
+ const root = plainMemberChainRoot(whenExpr);
2831
+ if (root && isUnprovenBinding(root.name)) return resolveAccessorAtRuntime(whenExpr);
2809
2832
  return whenExpr;
2810
2833
  }
2811
2834
 
2835
+ // The root identifier of `a.b.c` with no computed keys, else null. Reading
2836
+ // such a chain twice is a pure lookup, so the runtime check below may
2837
+ // evaluate it more than once.
2838
+ function plainMemberChainRoot(expr) {
2839
+ if (!t.isMemberExpression(expr)) return null;
2840
+ let node = expr;
2841
+ while (t.isMemberExpression(node)) {
2842
+ if (node.computed || !t.isIdentifier(node.property)) return null;
2843
+ node = node.object;
2844
+ }
2845
+ return t.isIdentifier(node) ? node : null;
2846
+ }
2847
+
2848
+ function resolveAccessorAtRuntime(ref) {
2849
+ return t.conditionalExpression(
2850
+ t.binaryExpression('===', t.unaryExpression('typeof', ref), t.stringLiteral('function')),
2851
+ t.callExpression(t.cloneNode(ref), []),
2852
+ t.cloneNode(ref)
2853
+ );
2854
+ }
2855
+
2812
2856
  function collectControlFlowContent(children, state) {
2813
2857
  const parts = [];
2814
2858
  for (const child of children) {