what-compiler 0.10.0 → 0.11.0

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