what-compiler 0.6.0 → 0.6.2

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,5 +1,5 @@
1
- import Z from"path";import{transformSync as _e}from"@babel/core";var me=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),he=new Set(["once","capture","passive"]),ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ee=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),R=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),ie=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]);function G({types:e}){function f(n){let i=n.split("|"),r=i[0],t=i.slice(1).filter(a=>me.has(a));return{eventName:r,modifiers:t}}function E(n){return n.startsWith("bind:")}function k(n){return n.slice(5)}function x(n){return/^[A-Z]/.test(n)}function L(n){return ge.has(String(n).toLowerCase())}function b(n){return n?e.isJSXExpressionContainer(n)?n.expression:e.isStringLiteral(n)?n:e.stringLiteral(n.value||""):e.booleanLiteral(!0)}function v(n){return n==="className"?"class":n==="htmlFor"?"for":n}function y(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 _(n,i){if(i.length===0)return n;let r=n;for(let t of i)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 p(n,i){return i.has(n)}function u(n){let i=new Set;function r(a){let s=a.init;if(!s||!e.isCallExpression(s))return;let o=s.callee,l="";if(e.isIdentifier(o)?l=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(l=o.property.name),ie.has(l)){let c=a.id;if(e.isIdentifier(c))i.add(c.name);else if(e.isArrayPattern(c))for(let d of c.elements)e.isIdentifier(d)&&i.add(d.name);else if(e.isObjectPattern(c))for(let d of c.properties)e.isObjectProperty(d)&&e.isIdentifier(d.value)&&i.add(d.value.name)}}let t=n.scope;for(;t;){for(let[a,s]of Object.entries(t.bindings))if(s.path.isVariableDeclarator()&&r(s.path.node),s.path.isIdentifier()||s.kind==="param"){let o=s.scope.path;if(o&&o.node&&o.node.params){for(let l of o.node.params)if(e.isObjectPattern(l))for(let c of l.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?i.add(c.value.name):e.isRestElement(c)&&e.isIdentifier(c.argument)&&i.add(c.argument.name)}}t=t.parent}return i}function g(n){return u(n)}function h(n){if(!e.isCallExpression(n))return!1;let i=n.callee;return e.isMemberExpression(i)&&e.isIdentifier(i.object)?R.has(i.object.name):e.isIdentifier(i)?R.has(i.name):!1}function P(n,i,r){if(!i)return!1;if(e.isCallExpression(n)){if(e.isIdentifier(n.callee)&&p(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&p(n.callee.object.name,i)||h(n))return!1;if(n.arguments.some(t=>w(t,i,r)))return!0}return!1}function w(n,i,r){return i||(i=new Set),e.isCallExpression(n)?e.isIdentifier(n.callee)&&p(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&p(n.callee.object.name,i)?!0:h(n)?n.arguments.some(t=>w(t,i,r)):e.isIdentifier(n.callee)?n.arguments.some(t=>w(t,i,r)):w(n.callee,i,r)||n.arguments.some(t=>w(t,i,r)):e.isIdentifier(n)?p(n.name,i):e.isMemberExpression(n)?w(n.object,i,r):e.isConditionalExpression(n)?w(n.test,i,r)||w(n.consequent,i,r)||w(n.alternate,i,r):e.isBinaryExpression(n)||e.isLogicalExpression(n)?w(n.left,i,r)||w(n.right,i,r):e.isUnaryExpression(n)?w(n.argument,i,r):e.isTemplateLiteral(n)?n.expressions.some(t=>w(t,i,r)):e.isObjectExpression(n)?n.properties.some(t=>e.isObjectProperty(t)&&w(t.value,i,r)):e.isArrayExpression(n)?n.elements.some(t=>t&&w(t,i,r)):(e.isArrowFunctionExpression(n)||e.isFunctionExpression(n),!1)}function J(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(x(r))return!1;for(let t of i.attributes){if(e.isJSXSpreadAttribute(t))return!1;let a=t.value;if(e.isJSXExpressionContainer(a))return!1}return n.children.every(J)}return!1}function D(n){return e.isJSXSpreadAttribute(n)?!0:n.value?e.isJSXExpressionContainer(n.value):!1}function z(n){if(e.isJSXText(n)){let s=n.value.replace(/\n\s+/g," ").trim();return s?Y(s):""}if(e.isJSXExpressionContainer(n))return e.isJSXEmptyExpression(n.expression)?"":"<!--$-->";if(!e.isJSXElement(n))return"";let i=n.openingElement,r=i.name.name;if(x(r))return"";let t=`<${r}`;for(let s of i.attributes){if(e.isJSXSpreadAttribute(s))continue;let o=y(s);if(o.startsWith("on")||o.startsWith("bind:")||o.includes("|"))continue;let l=o;if(o==="className"&&(l="class"),o==="htmlFor"&&(l="for"),!s.value)t+=` ${l}`;else if(e.isStringLiteral(s.value))t+=` ${l}="${ce(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let a=n.openingElement.selfClosing;if(a&&L(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of n.children)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&(t+=Y(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)&&(x(s.openingElement.name.name)?t+="<!--$-->":t+=z(s));return t+=`</${r}>`,t}function Y(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ce(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name;if(x(a))return ee(n,i);if(a==="For")return fe(n,i);if(a==="Show")return pe(n,i);let s=t.attributes,o=r.children,l=o.every(J),c=s.every($=>!D($)),d=s.every($=>{if(e.isJSXSpreadAttribute($))return!1;let m=y($);return!m?.startsWith("on")&&!m?.startsWith("bind:")});if(l&&c&&d){let $=z(r);if($){let m=ne(i,$);return i.needsTemplate=!0,e.callExpression(e.identifier(m),[])}}let C=z(r);if(!C){let $=r.loc,m=i.filename||i.file?.opts?.filename||"<unknown>",S=$?`:${$.start.line}:${$.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${a}> at ${m}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),i.needsH=!0,V(n,i)}let O=ne(i,C);i.needsTemplate=!0;let T=i.nextVarId(),M=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(T),e.callExpression(e.identifier(O),[]))])];return Q(M,T,s,i),K(M,T,o,r,i),i._pendingSetup||(i._pendingSetup=[]),i._pendingSetup.push(...M),e.identifier(T)}function V(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,l=[];for(let C of s){if(e.isJSXSpreadAttribute(C))continue;let O=y(C),T=b(C.value),M=v(O);l.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(M)?e.identifier(M):e.stringLiteral(M),T))}let c=[];for(let C of o)if(e.isJSXText(C)){let O=C.value.replace(/\n\s+/g," ").trim();O&&c.push(e.stringLiteral(O))}else e.isJSXExpressionContainer(C)?e.isJSXEmptyExpression(C.expression)||c.push(C.expression):e.isJSXElement(C)?c.push(X({node:C},i)):e.isJSXFragment(C)&&c.push(H({node:C},i));let d=l.length>0?e.objectExpression(l):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(a),d,...c])}function Q(n,i,r,t){function a(s,o){return t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(i),e.stringLiteral(s),o])}for(let s of r){if(e.isJSXSpreadAttribute(s)){t.needsSpread=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(i),s.argument])));continue}let o=y(s);if(o.startsWith("on")&&!o.includes("|")){let l=o.slice(2).toLowerCase(),c=b(s.value);Ee.has(l)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(l),n.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier(`__${l}`)),c)))):n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral(l),c])));continue}if(o.startsWith("on")&&o.includes("|")){let{eventName:l,modifiers:c}=f(o),d=b(s.value),C=_(d,c),O=l.slice(2).toLowerCase(),T=c.filter($=>he.has($)),M=[e.stringLiteral(O),C];if(T.length>0){let $=T.map(m=>e.objectProperty(e.identifier(m),e.booleanLiteral(!0)));M.push(e.objectExpression($))}n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),M)));continue}if(E(o)){let l=k(o),c=s.value.expression;t.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(c),[])))]))),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(c),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):l==="checked"&&(t.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(c),[])))]))),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(c),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(s.value)){let l=s.value.expression,c=v(o);if(w(l,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let d=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(c,l))]);P(l,t.signalNames,t.importedIdentifiers)&&e.addComment(d,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(d))}else n.push(e.expressionStatement(a(c,l)))}}}function K(n,i,r,t,a){let s=0;for(let o of r){if(e.isJSXText(o)){o.value.replace(/\n\s+/g," ").trim()&&s++;continue}if(e.isJSXExpressionContainer(o)){if(e.isJSXEmptyExpression(o.expression))continue;let l=o.expression,c=U(i,s);if(a.needsInsert=!0,w(l,a.signalNames,a.importedIdentifiers)){let d=e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],l),c]);P(l,a.signalNames,a.importedIdentifiers)&&e.addComment(d,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(d))}else n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),l,c])));s++;continue}if(e.isJSXElement(o)){let l=o.openingElement.name.name;if(x(l)||l==="For"||l==="Show"){let c=X({node:o},a),d=U(i,s);a.needsInsert=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),c,d]))),s++}else{if(o.openingElement.attributes.some(D)||o.openingElement.attributes.some(d=>!e.isJSXSpreadAttribute(d)&&y(d)?.startsWith("on"))||!o.children.every(J)){let d=a.nextVarId();n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),U(i,s))])),Q(n,d,o.openingElement.attributes,a),K(n,d,o.children,o,a)}s++}continue}if(e.isJSXFragment(o)){for(let l of o.children)if(e.isJSXExpressionContainer(l)&&!e.isJSXEmptyExpression(l.expression)){a.needsInsert=!0;let c=l.expression;w(c,a.signalNames,a.importedIdentifiers)?n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],c)]))):n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),c])))}}}}function U(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 t=0;t<i;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function ee(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,l=null,c=[];for(let m of s){if(e.isJSXAttribute(m)){let S;if(e.isJSXNamespacedName(m.name)?S=`${m.name.namespace.name}:${m.name.name.name}`:S=m.name.name,S&&typeof S=="string"&&S.startsWith("client:")){let A=S.slice(7);m.value?l={type:A,value:m.value.value}:l={type:A};continue}}c.push(m)}if(l){i.needsCreateComponent=!0,i.needsIsland=!0;let m=[e.objectProperty(e.identifier("component"),e.identifier(a)),e.objectProperty(e.identifier("mode"),e.stringLiteral(l.type))];l.value&&m.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(l.value)));for(let S of c){if(e.isJSXSpreadAttribute(S))continue;let A=y(S),I=b(S.value);m.push(e.objectProperty(e.identifier(A),I))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(m),e.arrayExpression([])])}i.needsCreateComponent=!0;let d=[],C=!1,O=null;for(let m of c){if(e.isJSXSpreadAttribute(m)){C=!0,O=m.argument;continue}let S=y(m);if(E(S)){let I=k(S),N=m.value.expression;I==="value"?(d.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(N),[]))),d.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):I==="checked"&&(d.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(N),[]))),d.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(S.startsWith("on")&&S.includes("|")){let{eventName:I,modifiers:N}=f(S),ue=b(m.value),de=_(ue,N);d.push(e.objectProperty(e.identifier(I),de));continue}let A=b(m.value);d.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(S)?e.identifier(S):e.stringLiteral(S),A))}let T=[];for(let m of o)if(e.isJSXText(m)){let S=m.value.replace(/\n\s+/g," ").trim();S&&T.push(e.stringLiteral(S))}else e.isJSXExpressionContainer(m)?e.isJSXEmptyExpression(m.expression)||T.push(m.expression):e.isJSXElement(m)?T.push(X({node:m},i)):e.isJSXFragment(m)&&T.push(H({node:m},i));let M;C?d.length>0?M=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),O,e.objectExpression(d)]):M=O:d.length>0?M=e.objectExpression(d):M=e.nullLiteral();let $=T.length>0?e.arrayExpression(T):e.arrayExpression([]);return e.callExpression(e.identifier("_$createComponent"),[e.identifier(a),M,$])}function fe(n,i){let{node:r}=n,t=r.openingElement.attributes,a=r.children,s=null;for(let l of t)e.isJSXAttribute(l)&&y(l)==="each"&&(s=b(l.value));if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),i.needsH=!0,V(n,i);let o=null;for(let l of a)if(e.isJSXExpressionContainer(l)&&!e.isJSXEmptyExpression(l.expression)){o=l.expression;break}return o?(i.needsMapArray=!0,e.callExpression(e.identifier("_$mapArray"),[s,o])):(console.warn("[what-compiler] <For> element missing render function child."),i.needsH=!0,V(n,i))}function pe(n,i){return i.needsCreateComponent=!0,ee(n,i)}function H(n,i){let{node:r}=n,t=r.children,a=[];for(let s of t)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&a.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||a.push(s.expression):e.isJSXElement(s)?a.push(X({node:s},i)):e.isJSXFragment(s)&&a.push(H({node:s},i));return a.length===1?a[0]:e.arrayExpression(a)}function ne(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 t=r.source.value,a=t==="what-framework"||t.startsWith("what-framework/")||t==="what-core"||t.startsWith("what-core/")||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let o=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(o=s.local.name),o&&(a||/^(use|create)[A-Z]/.test(o))&&i.importedIdentifiers.add(o)}}n.traverse({VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let a=t.callee,s="";if(e.isIdentifier(a)?s=a.name:e.isMemberExpression(a)&&e.isIdentifier(a.property)&&(s=a.property.name),ie.has(s)){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 t=[];if(i.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),i.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),i.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let a=null;for(let s of n.node.body)if(e.isImportDeclaration(s)&&(s.source.value==="what-framework/render"||s.source.value==="what-core/render")){a=s;break}if(a){let s=new Set(a.specifiers.filter(o=>e.isImportSpecifier(o)).map(o=>o.imported.name));for(let o of r)s.has(o.imported.name)||a.specifiers.push(o)}else n.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&xe(n,e,t),i.needsDelegation&&i.delegatedEvents&&i.delegatedEvents.size>0){let a=e.arrayExpression([...i.delegatedEvents].map(s=>e.stringLiteral(s)));n.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[a])))}}},JSXElement(n,i){i.signalNames=u(n),i._pendingSetup=[];let r=X(n,i),t=i._pendingSetup;if(i._pendingSetup=[],t.length>0){let a=n;for(;a&&!a.isStatement();)a=a.parentPath;if(a&&a.isStatement()){for(let s of t)a.insertBefore(s);n.replaceWith(r)}else t.push(e.returnStatement(r)),n.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(t)),[]))}else n.replaceWith(r)},JSXFragment(n,i){let r=H(n,i);n.replaceWith(r)}}}}function xe(e,f,E){let k=null;for(let x of e.node.body)if(f.isImportDeclaration(x)&&(x.source.value==="what-core"||x.source.value==="what-framework")){k=x;break}if(k){let x=new Set(k.specifiers.filter(L=>f.isImportSpecifier(L)).map(L=>L.imported.name));for(let L of E)x.has(L.imported.name)||k.specifiers.push(L)}else{let x=f.importDeclaration(E,f.stringLiteral("what-framework"));e.unshiftContainer("body",x)}}import j from"fs";import F from"path";var re=new Set([".jsx",".tsx",".js",".ts"]),be=new Set(["_layout","_error","_loading","_404"]);function Se(e){let f=[],E=[],k=[];function x(b,v=""){if(!j.existsSync(b))return;let y=j.readdirSync(b,{withFileTypes:!0});for(let _ of y){let p=F.join(b,_.name);if(_.isDirectory()){if(_.name.match(/^\((.+)\)$/)){x(p,v);continue}if(_.name==="api"&&v===""){L(p,"/api");continue}x(p,v+"/"+W(_.name));continue}let u=F.extname(_.name);if(!re.has(u))continue;let g=F.basename(_.name,u);if(g==="_layout"){E.push({filePath:p,urlPrefix:v||"/"});continue}if(be.has(g))continue;let h=W(g),P=g==="index"?v||"/":v+"/"+h;f.push({filePath:p,routePath:te(P),isDynamic:P.includes(":")||P.includes("*")})}}function L(b,v){if(!j.existsSync(b))return;let y=j.readdirSync(b,{withFileTypes:!0});for(let _ of y){let p=F.join(b,_.name);if(_.isDirectory()){L(p,v+"/"+W(_.name));continue}let u=F.extname(_.name);if(!re.has(u))continue;let g=F.basename(_.name,u),h=W(g),P=g==="index"?v:v+"/"+h;k.push({filePath:p,routePath:te(P)})}}return x(e),f.sort((b,v)=>{let y=se(b.routePath),_=se(v.routePath);return y-_}),{pages:f,layouts:E,apiRoutes:k}}function W(e){let f=e.match(/^\[\.\.\.(\w+)\]$/);if(f)return"*"+f[1];let E=e.match(/^\[(\w+)\]$/);return E?":"+E[1]:e.toLowerCase()}function te(e){let f=e.replace(/\/+/g,"/");return f.length>1&&f.endsWith("/")&&(f=f.slice(0,-1)),f||"/"}function se(e){return e.includes("*")?100:e.includes(":")?10:0}function ve(e){let f=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!f)return{mode:"client"};try{let E=f[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(E)}}catch{return{mode:"client"}}}function oe(e,f){let{pages:E,layouts:k,apiRoutes:x}=Se(e),L=[],b=[],v=new Map;k.forEach((p,u)=>{let g=`_layout${u}`,h=q(p.filePath,f);L.push(`import ${g} from '${h}';`),v.set(p.urlPrefix,g)}),E.forEach((p,u)=>{let g=`_page${u}`,h=q(p.filePath,f);L.push(`import ${g} from '${h}';`);let P={mode:"client"};try{let D=j.readFileSync(p.filePath,"utf-8");P=ve(D)}catch{}let w=ye(p.routePath,v),J={path:p.routePath,component:g,mode:P.mode||"client",layout:w||null};b.push(J)});let y=[];return x.forEach((p,u)=>{let g=`_api${u}`,h=q(p.filePath,f);L.push(`import * as ${g} from '${h}';`),y.push({path:p.routePath,handlers:g})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...L,"","export const routes = [",...b.map(p=>` { path: '${p.path}', component: ${p.component}, mode: '${p.mode}'${p.layout?`, layout: ${p.layout}`:""} },`),"];","","export const apiRoutes = [",...y.map(p=>` { path: '${p.path}', handlers: ${p.handlers} },`),"];","","export const pageModes = {",...b.map(p=>` '${p.path}': '${p.mode}',`),"};"].join(`
2
- `)}function q(e,f){return"/"+F.relative(f,e).split(F.sep).join("/")}function ye(e,f){let E=e.split("/").filter(Boolean);for(;E.length>0;){let k="/"+E.join("/");if(f.has(k))return f.get(k);E.pop()}return f.has("/")?f.get("/"):null}var we=`
1
+ import Z from"path";import{transformSync as _e}from"@babel/core";var me=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),he=new Set(["once","capture","passive"]),ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),xe=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),R=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),ie=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]);function G({types:e}){function f(n){let i=n.split("|"),r=i[0],t=i.slice(1).filter(a=>me.has(a));return{eventName:r,modifiers:t}}function b(n){return n.startsWith("bind:")}function I(n){return n.slice(5)}function _(n){return/^[A-Z]/.test(n)}function T(n){return ge.has(String(n).toLowerCase())}function v(n){return n?e.isJSXExpressionContainer(n)?n.expression:e.isStringLiteral(n)?n:e.stringLiteral(n.value||""):e.booleanLiteral(!0)}function C(n){return n==="className"?"class":n==="htmlFor"?"for":n}function k(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 $(n,i){if(i.length===0)return n;let r=n;for(let t of i)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 d(n,i){return i.has(n)}function m(n){let i=new Set;function r(a){let s=a.init;if(!s||!e.isCallExpression(s))return;let o=s.callee,c="";if(e.isIdentifier(o)?c=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(c=o.property.name),ie.has(c)){let u=a.id;if(e.isIdentifier(u))i.add(u.name);else if(e.isArrayPattern(u))for(let S of u.elements)e.isIdentifier(S)&&i.add(S.name);else if(e.isObjectPattern(u))for(let S of u.properties)e.isObjectProperty(S)&&e.isIdentifier(S.value)&&i.add(S.value.name)}}let t=n.scope;for(;t;){for(let[a,s]of Object.entries(t.bindings))if(s.path.isVariableDeclarator()&&r(s.path.node),s.path.isIdentifier()||s.kind==="param"){let o=s.scope.path;if(o&&o.node&&o.node.params){for(let c of o.node.params)if(e.isObjectPattern(c))for(let u of c.properties)e.isObjectProperty(u)&&e.isIdentifier(u.value)?i.add(u.value.name):e.isRestElement(u)&&e.isIdentifier(u.argument)&&i.add(u.argument.name)}}t=t.parent}return i}function x(n){return m(n)}function g(n){if(!e.isCallExpression(n))return!1;let i=n.callee;return e.isMemberExpression(i)&&e.isIdentifier(i.object)?R.has(i.object.name):e.isIdentifier(i)?R.has(i.name):!1}function P(n,i,r){if(!i)return!1;if(e.isCallExpression(n)){if(e.isIdentifier(n.callee)&&d(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&d(n.callee.object.name,i)||g(n))return!1;if(n.arguments.some(t=>L(t,i,r)))return!0}return!1}function L(n,i,r){return i||(i=new Set),e.isCallExpression(n)?e.isIdentifier(n.callee)&&d(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&d(n.callee.object.name,i)?!0:g(n)?n.arguments.some(t=>L(t,i,r)):e.isIdentifier(n.callee)?n.arguments.some(t=>L(t,i,r)):L(n.callee,i,r)||n.arguments.some(t=>L(t,i,r)):e.isIdentifier(n)?d(n.name,i):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(t=>L(t,i,r)):e.isObjectExpression(n)?n.properties.some(t=>e.isObjectProperty(t)&&L(t.value,i,r)):e.isArrayExpression(n)?n.elements.some(t=>t&&L(t,i,r)):(e.isArrowFunctionExpression(n)||e.isFunctionExpression(n),!1)}function J(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(_(r))return!1;for(let t of i.attributes){if(e.isJSXSpreadAttribute(t))return!1;let a=t.value;if(e.isJSXExpressionContainer(a))return!1}return n.children.every(J)}return!1}function j(n){return e.isJSXSpreadAttribute(n)?!0:n.value?e.isJSXExpressionContainer(n.value):!1}function B(n){if(e.isJSXText(n)){let s=n.value.replace(/\n\s+/g," ").trim();return s?Y(s):""}if(e.isJSXExpressionContainer(n))return e.isJSXEmptyExpression(n.expression)?"":"<!--$-->";if(!e.isJSXElement(n))return"";let i=n.openingElement,r=i.name.name;if(_(r))return"";let t=`<${r}`;for(let s of i.attributes){if(e.isJSXSpreadAttribute(s))continue;let o=k(s);if(o==="key"||o.startsWith("on")||o.startsWith("bind:")||o.includes("|"))continue;let c=o;if(o==="className"&&(c="class"),o==="htmlFor"&&(c="for"),!s.value)t+=` ${c}`;else if(e.isStringLiteral(s.value))t+=` ${c}="${ce(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let a=n.openingElement.selfClosing;if(a&&T(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of n.children)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&(t+=Y(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)&&(_(s.openingElement.name.name)?t+="<!--$-->":t+=B(s));return t+=`</${r}>`,t}function Y(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ce(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function X(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name;if(_(a))return ee(n,i);if(a==="For")return fe(n,i);if(a==="Show")return pe(n,i);let s=t.attributes,o=r.children,c=o.every(J),u=s.every(E=>!j(E)),S=s.every(E=>{if(e.isJSXSpreadAttribute(E))return!1;let p=k(E);return!p?.startsWith("on")&&!p?.startsWith("bind:")});if(c&&u&&S){let E=B(r);if(E){let p=ne(i,E);return i.needsTemplate=!0,e.callExpression(e.identifier(p),[])}}let y=B(r);if(!y){let E=r.loc,p=i.filename||i.file?.opts?.filename||"<unknown>",w=E?`:${E.start.line}:${E.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${a}> at ${p}${w}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),i.needsH=!0,z(n,i)}let M=ne(i,y);i.needsTemplate=!0;let l=i.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier(M),[]))])];return Q(h,l,s,i),K(h,l,o,r,i),i._pendingSetup||(i._pendingSetup=[]),i._pendingSetup.push(...h),e.identifier(l)}function z(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,c=[];for(let y of s){if(e.isJSXSpreadAttribute(y))continue;let M=k(y),l=v(y.value),h=C(M);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),l))}let u=[];for(let y of o)if(e.isJSXText(y)){let M=y.value.replace(/\n\s+/g," ").trim();M&&u.push(e.stringLiteral(M))}else e.isJSXExpressionContainer(y)?e.isJSXEmptyExpression(y.expression)||u.push(y.expression):e.isJSXElement(y)?u.push(X({node:y},i)):e.isJSXFragment(y)&&u.push(H({node:y},i));let S=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(a),S,...u])}function Q(n,i,r,t){function a(s,o){return t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(i),e.stringLiteral(s),o])}for(let s of r){if(e.isJSXSpreadAttribute(s)){t.needsSpread=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(i),s.argument])));continue}let o=k(s);if(o!=="key"){if(o==="ref"){let c=v(s.value);n.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",c),e.stringLiteral("function")),e.callExpression(e.cloneNode(c),[e.identifier(i)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(c),e.identifier("current")),e.identifier(i)))));continue}if(o.startsWith("on")&&!o.includes("|")){let c=o.slice(2).toLowerCase(),u=v(s.value);xe.has(c)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(c),n.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier(`__${c}`)),u)))):n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral(c),u])));continue}if(o.startsWith("on")&&o.includes("|")){let{eventName:c,modifiers:u}=f(o),S=v(s.value),y=$(S,u),M=c.slice(2).toLowerCase(),l=u.filter(E=>he.has(E)),h=[e.stringLiteral(M),y];if(l.length>0){let E=l.map(p=>e.objectProperty(e.identifier(p),e.booleanLiteral(!0)));h.push(e.objectExpression(E))}n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),h)));continue}if(b(o)){let c=I(o),u=s.value.expression;t.needsEffect=!0,c==="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(u),[])))]))),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(u),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):c==="checked"&&(t.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(u),[])))]))),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(u),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(s.value)){let c=s.value.expression,u=C(o);if(L(c,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(u,c))]);P(c,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),n.push(e.expressionStatement(S))}else n.push(e.expressionStatement(a(u,c)))}}}}function K(n,i,r,t,a){let s=[],o=0;for(let l of r){if(e.isJSXText(l)){l.value.replace(/\n\s+/g," ").trim()&&o++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s.push({type:"expression",child:l,childIndex:o}),o++;continue}if(e.isJSXElement(l)){let h=l.openingElement.name.name;if(_(h)||h==="For"||h==="Show")s.push({type:"component",child:l,childIndex:o}),o++;else{let E=l.openingElement.attributes.some(j)||l.openingElement.attributes.some(p=>!e.isJSXSpreadAttribute(p)&&k(p)?.startsWith("on"))||!l.children.every(J);s.push({type:"static",child:l,childIndex:o,hasAnythingDynamic:E}),o++}continue}e.isJSXFragment(l)&&s.push({type:"fragment",child:l})}let c=s.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),u=s.some(l=>l.type==="expression"||l.type==="component"),S=c.length>=2&&u,y=new Map;if(S)for(let l of c){let h=`_m$${l.childIndex}`,E=a.nextVarId();y.set(l.childIndex,E),n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),U(i,l.childIndex))]))}function M(l){return y.has(l)?e.identifier(y.get(l)):U(i,l)}for(let l of s){if(l.type==="expression"){let h=l.child.expression,E=M(l.childIndex);if(a.needsInsert=!0,L(h,a.signalNames,a.importedIdentifiers)){let p=e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],h),E]);P(h,a.signalNames,a.importedIdentifiers)&&e.addComment(p,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(p))}else n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),h,E])));continue}if(l.type==="component"){let h=X({node:l.child},a),E=M(l.childIndex);a.needsInsert=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),h,E])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let h;y.has(l.childIndex)?h=y.get(l.childIndex):(h=a.nextVarId(),n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),U(i,l.childIndex))]))),Q(n,h,l.child.openingElement.attributes,a),K(n,h,l.child.children,l.child,a);continue}if(l.type==="fragment"){for(let h of l.child.children)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){a.needsInsert=!0;let E=h.expression;L(E,a.signalNames,a.importedIdentifiers)?n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],E)]))):n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),E])))}}}}function U(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 t=0;t<i;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function ee(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,c=null,u=[];for(let p of s){if(e.isJSXAttribute(p)){let w;if(e.isJSXNamespacedName(p.name)?w=`${p.name.namespace.name}:${p.name.name.name}`:w=p.name.name,w&&typeof w=="string"&&w.startsWith("client:")){let A=w.slice(7);p.value?c={type:A,value:p.value.value}:c={type:A};continue}}u.push(p)}if(c){i.needsCreateComponent=!0,i.needsIsland=!0;let p=[e.objectProperty(e.identifier("component"),e.identifier(a)),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&p.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));for(let w of u){if(e.isJSXSpreadAttribute(w))continue;let A=k(w),F=v(w.value);p.push(e.objectProperty(e.identifier(A),F))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(p),e.arrayExpression([])])}i.needsCreateComponent=!0;let S=[],y=!1,M=null;for(let p of u){if(e.isJSXSpreadAttribute(p)){y=!0,M=p.argument;continue}let w=k(p);if(w==="key")continue;if(b(w)){let F=I(w),N=p.value.expression;F==="value"?(S.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(N),[]))),S.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):F==="checked"&&(S.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(N),[]))),S.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(w.startsWith("on")&&w.includes("|")){let{eventName:F,modifiers:N}=f(w),ue=v(p.value),de=$(ue,N);S.push(e.objectProperty(e.identifier(F),de));continue}let A=v(p.value);S.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(w)?e.identifier(w):e.stringLiteral(w),A))}let l=[];for(let p of o)if(e.isJSXText(p)){let w=p.value.replace(/\n\s+/g," ").trim();w&&l.push(e.stringLiteral(w))}else e.isJSXExpressionContainer(p)?e.isJSXEmptyExpression(p.expression)||l.push(p.expression):e.isJSXElement(p)?l.push(X({node:p},i)):e.isJSXFragment(p)&&l.push(H({node:p},i));let h;y?S.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),M,e.objectExpression(S)]):h=M:S.length>0?h=e.objectExpression(S):h=e.nullLiteral();let E=l.length>0?e.arrayExpression(l):e.arrayExpression([]);return e.callExpression(e.identifier("_$createComponent"),[e.identifier(a),h,E])}function fe(n,i){let{node:r}=n,t=r.openingElement.attributes,a=r.children,s=null;for(let c of t)e.isJSXAttribute(c)&&k(c)==="each"&&(s=v(c.value));if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),i.needsH=!0,z(n,i);let o=null;for(let c of a)if(e.isJSXExpressionContainer(c)&&!e.isJSXEmptyExpression(c.expression)){o=c.expression;break}return o?(i.needsMapArray=!0,e.callExpression(e.identifier("_$mapArray"),[s,o])):(console.warn("[what-compiler] <For> element missing render function child."),i.needsH=!0,z(n,i))}function pe(n,i){return i.needsCreateComponent=!0,ee(n,i)}function H(n,i){let{node:r}=n,t=r.children,a=[];for(let s of t)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&a.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||a.push(s.expression):e.isJSXElement(s)?a.push(X({node:s},i)):e.isJSXFragment(s)&&a.push(H({node:s},i));return a.length===1?a[0]:e.arrayExpression(a)}function ne(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 t=r.source.value,a=t==="what-framework"||t.startsWith("what-framework/")||t==="what-core"||t.startsWith("what-core/")||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let o=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(o=s.local.name),o&&(a||/^(use|create)[A-Z]/.test(o))&&i.importedIdentifiers.add(o)}}n.traverse({VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let a=t.callee,s="";if(e.isIdentifier(a)?s=a.name:e.isMemberExpression(a)&&e.isIdentifier(a.property)&&(s=a.property.name),ie.has(s)){let o=r.node.id;if(e.isIdentifier(o))i.signalNames.add(o.name);else if(e.isArrayPattern(o))for(let c of o.elements)e.isIdentifier(c)&&i.signalNames.add(c.name);else if(e.isObjectPattern(o))for(let c of o.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&i.signalNames.add(c.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 t=[];if(i.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),i.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),i.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let a=null;for(let s of n.node.body)if(e.isImportDeclaration(s)&&(s.source.value==="what-framework/render"||s.source.value==="what-core/render")){a=s;break}if(a){let s=new Set(a.specifiers.filter(o=>e.isImportSpecifier(o)).map(o=>o.imported.name));for(let o of r)s.has(o.imported.name)||a.specifiers.push(o)}else n.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&Ee(n,e,t),i.needsDelegation&&i.delegatedEvents&&i.delegatedEvents.size>0){let a=e.arrayExpression([...i.delegatedEvents].map(s=>e.stringLiteral(s)));n.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[a])))}}},JSXElement(n,i){i.signalNames=m(n),i._pendingSetup=[];let r=X(n,i),t=i._pendingSetup;if(i._pendingSetup=[],t.length>0){let a=n;for(;a&&!a.isStatement();)a=a.parentPath;if(a&&a.isStatement()){for(let s of t)a.insertBefore(s);n.replaceWith(r)}else t.push(e.returnStatement(r)),n.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(t)),[]))}else n.replaceWith(r)},JSXFragment(n,i){let r=H(n,i);n.replaceWith(r)}}}}function Ee(e,f,b){let I=null;for(let _ of e.node.body)if(f.isImportDeclaration(_)&&(_.source.value==="what-core"||_.source.value==="what-framework")){I=_;break}if(I){let _=new Set(I.specifiers.filter(T=>f.isImportSpecifier(T)).map(T=>T.imported.name));for(let T of b)_.has(T.imported.name)||I.specifiers.push(T)}else{let _=f.importDeclaration(b,f.stringLiteral("what-framework"));e.unshiftContainer("body",_)}}import D from"fs";import O from"path";var re=new Set([".jsx",".tsx",".js",".ts"]),be=new Set(["_layout","_error","_loading","_404"]);function Se(e){let f=[],b=[],I=[];function _(v,C=""){if(!D.existsSync(v))return;let k=D.readdirSync(v,{withFileTypes:!0});for(let $ of k){let d=O.join(v,$.name);if($.isDirectory()){if($.name.match(/^\((.+)\)$/)){_(d,C);continue}if($.name==="api"&&C===""){T(d,"/api");continue}_(d,C+"/"+W($.name));continue}let m=O.extname($.name);if(!re.has(m))continue;let x=O.basename($.name,m);if(x==="_layout"){b.push({filePath:d,urlPrefix:C||"/"});continue}if(be.has(x))continue;let g=W(x),P=x==="index"?C||"/":C+"/"+g;f.push({filePath:d,routePath:te(P),isDynamic:P.includes(":")||P.includes("*")})}}function T(v,C){if(!D.existsSync(v))return;let k=D.readdirSync(v,{withFileTypes:!0});for(let $ of k){let d=O.join(v,$.name);if($.isDirectory()){T(d,C+"/"+W($.name));continue}let m=O.extname($.name);if(!re.has(m))continue;let x=O.basename($.name,m),g=W(x),P=x==="index"?C:C+"/"+g;I.push({filePath:d,routePath:te(P)})}}return _(e),f.sort((v,C)=>{let k=se(v.routePath),$=se(C.routePath);return k-$}),{pages:f,layouts:b,apiRoutes:I}}function W(e){let f=e.match(/^\[\.\.\.(\w+)\]$/);if(f)return"*"+f[1];let b=e.match(/^\[(\w+)\]$/);return b?":"+b[1]:e.toLowerCase()}function te(e){let f=e.replace(/\/+/g,"/");return f.length>1&&f.endsWith("/")&&(f=f.slice(0,-1)),f||"/"}function se(e){return e.includes("*")?100:e.includes(":")?10:0}function ye(e){let f=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!f)return{mode:"client"};try{let b=f[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(b)}}catch{return{mode:"client"}}}function oe(e,f){let{pages:b,layouts:I,apiRoutes:_}=Se(e),T=[],v=[],C=new Map;I.forEach((d,m)=>{let x=`_layout${m}`,g=q(d.filePath,f);T.push(`import ${x} from '${g}';`),C.set(d.urlPrefix,x)}),b.forEach((d,m)=>{let x=`_page${m}`,g=q(d.filePath,f);T.push(`import ${x} from '${g}';`);let P={mode:"client"};try{let j=D.readFileSync(d.filePath,"utf-8");P=ye(j)}catch{}let L=ve(d.routePath,C),J={path:d.routePath,component:x,mode:P.mode||"client",layout:L||null};v.push(J)});let k=[];return _.forEach((d,m)=>{let x=`_api${m}`,g=q(d.filePath,f);T.push(`import * as ${x} from '${g}';`),k.push({path:d.routePath,handlers:x})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...T,"","export const routes = [",...v.map(d=>` { path: '${d.path}', component: ${d.component}, mode: '${d.mode}'${d.layout?`, layout: ${d.layout}`:""} },`),"];","","export const apiRoutes = [",...k.map(d=>` { path: '${d.path}', handlers: ${d.handlers} },`),"];","","export const pageModes = {",...v.map(d=>` '${d.path}': '${d.mode}',`),"};"].join(`
2
+ `)}function q(e,f){return"/"+O.relative(f,e).split(O.sep).join("/")}function ve(e,f){let b=e.split("/").filter(Boolean);for(;b.length>0;){let I="/"+b.join("/");if(f.has(I))return f.get(I);b.pop()}return f.has("/")?f.get("/"):null}var we=`
3
3
  :host {
4
4
  position: fixed;
5
5
  inset: 0;
@@ -185,7 +185,7 @@ import Z from"path";import{transformSync as _e}from"@babel/core";var me=new Set(
185
185
  white-space: pre-wrap;
186
186
  line-height: 1.5;
187
187
  }
188
- `,Ie=`
188
+ `,Fe=`
189
189
  class WhatErrorOverlay extends HTMLElement {
190
190
  constructor(err) {
191
191
  super();
@@ -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 ae(e){let f=e.ws.send.bind(e.ws);e.ws.send=function(E){return E?.type==="error"&&E.err?.plugin==="vite-plugin-what"&&(E.err._isCompilerError=!0),f(E)}}var le="virtual:what-routes",B="\0"+le,Ce=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,Le=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function ke(e={}){let{include:f=/\.[jt]sx$/,exclude:E=/node_modules/,sourceMaps:k=!0,production:x=!0,pages:L="src/pages",hot:b=!x}=e,v="",y="",_=null,p=!1;return{name:"vite-plugin-what",configResolved(u){v=u.root,y=Z.resolve(v,L),p=u.command==="serve"},configureServer(u){_=u,ae(u),u.watcher.on("add",g=>{if(g.startsWith(y)){let h=u.moduleGraph.getModuleById(B);h&&(u.moduleGraph.invalidateModule(h),u.ws.send({type:"full-reload"}))}}),u.watcher.on("unlink",g=>{if(g.startsWith(y)){let h=u.moduleGraph.getModuleById(B);h&&(u.moduleGraph.invalidateModule(h),u.ws.send({type:"full-reload"}))}})},resolveId(u){if(u===le)return B},load(u){if(u===B)return oe(y,v)},transform(u,g){if(!f.test(g)||E&&E.test(g))return null;try{let h=_e(u,{filename:g,sourceMaps:k,plugins:[[G,{production:x}]],parserOpts:{plugins:["jsx","typescript"]}});if(!h||!h.code)return null;let P=h.code;return b&&p&&!x&&$e(u,g)&&(P+=Me(g)),{code:P,map:h.map}}catch(h){throw h.plugin="vite-plugin-what",h.id||(h.id=g),h.loc===void 0&&h._loc&&(h.loc={file:g,line:h._loc.line,column:h._loc.column}),console.error(`[what] Error transforming ${g}:`,h.message),h}},handleHotUpdate({file:u,server:g,modules:h}){if(b&&f.test(u)&&!(E&&E.test(u))&&Te(u))return g.ws.send({type:"full-reload"}),[]},config(u,{mode:g}){return{esbuild:{jsx:"preserve"},optimizeDeps:{include:["what-framework"]}}}}}function $e(e,f){return!!(Ce.test(e)||f.includes("/pages/")||f.includes("\\pages\\"))}function Te(e){let f=Z.basename(e,Z.extname(e));return Le.test(f)}function Me(e){return`
383
+ `;function ae(e){let f=e.ws.send.bind(e.ws);e.ws.send=function(b){return b?.type==="error"&&b.err?.plugin==="vite-plugin-what"&&(b.err._isCompilerError=!0),f(b)}}var le="virtual:what-routes",V="\0"+le,Ce=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,ke=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function Le(e={}){let{include:f=/\.[jt]sx$/,exclude:b=/node_modules/,sourceMaps:I=!0,production:_=!0,pages:T="src/pages",hot:v=!_}=e,C="",k="",$=null,d=!1;return{name:"vite-plugin-what",configResolved(m){C=m.root,k=Z.resolve(C,T),d=m.command==="serve"},configureServer(m){$=m,ae(m),m.watcher.on("add",x=>{if(x.startsWith(k)){let g=m.moduleGraph.getModuleById(V);g&&(m.moduleGraph.invalidateModule(g),m.ws.send({type:"full-reload"}))}}),m.watcher.on("unlink",x=>{if(x.startsWith(k)){let g=m.moduleGraph.getModuleById(V);g&&(m.moduleGraph.invalidateModule(g),m.ws.send({type:"full-reload"}))}})},resolveId(m){if(m===le)return V},load(m){if(m===V)return oe(k,C)},transform(m,x){if(!f.test(x)||b&&b.test(x))return null;try{let g=_e(m,{filename:x,sourceMaps:I,plugins:[[G,{production:_}]],parserOpts:{plugins:["jsx","typescript"]}});if(!g||!g.code)return null;let P=g.code;return v&&d&&!_&&$e(m,x)&&(P+=Ie(x)),{code:P,map:g.map}}catch(g){throw g.plugin="vite-plugin-what",g.id||(g.id=x),g.loc===void 0&&g._loc&&(g.loc={file:x,line:g._loc.line,column:g._loc.column}),console.error(`[what] Error transforming ${x}:`,g.message),g}},handleHotUpdate({file:m,server:x,modules:g}){if(v&&f.test(m)&&!(b&&b.test(m))&&Te(m))return x.ws.send({type:"full-reload"}),[]},config(m,{mode:x}){return{esbuild:{jsx:"preserve"},optimizeDeps:{include:["what-framework"]}}}}}function $e(e,f){return!!(Ce.test(e)||f.includes("/pages/")||f.includes("\\pages\\"))}function Te(e){let f=Z.basename(e,Z.extname(e));return ke.test(f)}function Ie(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
- `}export{ke as default,ke as what};
396
+ `}export{Le as default,Le as what};
397
397
  //# sourceMappingURL=vite-plugin.min.js.map