what-compiler 0.12.3 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel-plugin.min.js +1 -1
- package/dist/file-router.min.js +13 -3
- package/dist/index.min.js +16 -6
- package/dist/vite-plugin.min.js +16 -6
- package/package.json +2 -2
- package/src/babel-plugin.js +475 -24
- package/src/file-router.js +252 -19
- package/src/vite-plugin.js +14 -9
package/dist/babel-plugin.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ce=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),$e=new Set(["once","capture","passive"]),Ie=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ke=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),T=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),le=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),Fe=new Set(["For","Show","Switch","Match"]),Je=new Set(["what-framework/server","what-server","what-server/actions"]);function Xe(e){let v=0xcbf29ce484222325n;for(let _=0;_<e.length;_++)v^=BigInt(e.charCodeAt(_)),v=BigInt.asUintN(64,v*0x100000001b3n);return v.toString(36)}function Me(e,v){let _=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(v||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&_.startsWith(`${C}/`)?_.slice(C.length+1):_.replace(/^\.\//,"")}function F(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let v=e.split(/\r\n|\n|\r/),_=-1;for(let b=0;b<v.length;b++)/[^ \t]/.test(v[b])&&(_=b);if(_===-1)return"";let C="";for(let b=0;b<v.length;b++){let A=v[b].replace(/\t/g," "),D=b===0,O=b===v.length-1;D||(A=A.replace(/^ +/,"")),O||(A=A.replace(/ +$/,"")),A&&(b!==_&&(A+=" "),C+=A)}return C}function Ne({types:e}){let v=new Set,_=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function b(i){let n=i.includes("|")?"|":"__",r=i.split(n),s=r[0],t=r.slice(1).filter(a=>Ce.has(a));return{eventName:s,modifiers:t}}function A(i){return i.startsWith("bind:")}function D(i){return i.slice(5)}function O(i){return/^[A-Z]/.test(i)}function N(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&O(n.name)}function j(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function ce(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function fe(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function U(i){return e.isJSXMemberExpression(i)?e.memberExpression(U(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function pe(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],s=-1;for(let f=0;f<r.properties.length;f++){let d=r.properties[f];if(e.isRestElement(d))return;if(e.isObjectProperty(d)&&!d.computed&&e.isIdentifier(d.key,{name:"children"})){if(s!==-1||!e.isIdentifier(d.value))return;s=f}}if(s===-1)return;let t=i.scope.getBinding(r.properties[s].value.name);if(!t||t.constantViolations.length>0||t.referencePaths.length===0||!t.referencePaths.every(f=>{let d=f.parentPath;if(!d||!d.isJSXExpressionContainer())return!1;let u=d.parentPath;if(!u||!u.isJSXElement()||!N(u.node))return!1;let l=u.node.openingElement.name;return!(e.isJSXIdentifier(l)&&Fe.has(l.name))}))return;let o=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(o.typeAnnotation=r.typeAnnotation),n[0]=o;let c=r.properties.filter((f,d)=>d!==s);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let f=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(f,e.cloneNode(o))])),i.node._whatMovedProps=f}for(let f of t.referencePaths)f.replaceWith(e.memberExpression(e.cloneNode(o),e.identifier("children")));i.scope.crawl()}function ue(i){return Ie.has(String(i).toLowerCase())}function $(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function G(i){return i==="className"?"class":i==="htmlFor"?"for":i}function I(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function de(i){return!!i&&i.length>2&&/^on/i.test(i)}function z(i,n){if(n.length===0)return i;let r=i;for(let s of n)switch(s){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function J(i,n){return n.has(i)}function q(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function s(o){let c=o.init;if(!c||!e.isCallExpression(c))return;let f=c.callee,d="";if(e.isIdentifier(f)?d=f.name:e.isMemberExpression(f)&&e.isIdentifier(f.property)&&(d=f.property.name),le.has(d)){let u=o.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let l of u.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(u))for(let l of u.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function t(o){if(e.isObjectPattern(o))for(let c of o.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&s(c.path.node);let o=a.path&&a.path.node;if(o){if(o.params)for(let c of o.params)t(c);o._whatMovedProps&&t(o._whatMovedProps)}a=a.parent}return n}function De(i){return q(i)}function Z(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?T.has(n.object.name):e.isIdentifier(n)?T.has(n.name):!1}function K(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)||Z(i))return!1;if(i.arguments.some(s=>y(s,n,r)))return!0}return!1}function y(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)?!0:Z(i)?i.arguments.some(s=>y(s,n,r)):e.isIdentifier(i.callee)?i.arguments.some(s=>y(s,n,r)):y(i.callee,n,r)||i.arguments.some(s=>y(s,n,r)):e.isIdentifier(i)?J(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?y(i.object,n,r):e.isConditionalExpression(i)?y(i.test,n,r)||y(i.consequent,n,r)||y(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?y(i.left,n,r)||y(i.right,n,r):e.isUnaryExpression(i)?y(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(s=>y(s,n,r)):e.isObjectExpression(i)?i.properties.some(s=>e.isObjectProperty(s)&&y(s.value,n,r)):e.isArrayExpression(i)?i.elements.some(s=>s&&y(s,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function Q(i,n){let r=i,s=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,s=!0),e.isConditionalExpression(r)){let a=P(r.consequent,n),o=P(r.alternate,n);if(a||o){let c=e.conditionalExpression(r.test,a||r.consequent,o||r.alternate);return s?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=P(r.right,n);if(a){let o=e.logicalExpression(r.operator,r.left,a);return s?e.arrowFunctionExpression([],o):o}return null}return P(r,n)}function P(i,n){if(!e.isCallExpression(i)||!e.isMemberExpression(i.callee)||!e.isIdentifier(i.callee.property,{name:"map"})||i.arguments.length<1)return null;let r=i.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let s=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))s=r.body;else if(e.isBlockStatement(r.body)){let l=r.body.body.find(m=>e.isReturnStatement(m));l&&(s=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(m=>e.isReturnStatement(m));l&&(s=l.argument)}if(!s||!e.isJSXElement(s))return null;let t=s.openingElement.attributes,a=null;for(let l of t)if(e.isJSXAttribute(l)&&I(l)==="key"){a=l;break}if(!a)return null;let o=$(a.value);if(!o)return null;s.openingElement.attributes=t.filter(l=>l!==a);let c=i.callee.object,f=e.arrowFunctionExpression([],c),d=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),u=e.arrowFunctionExpression([d],e.cloneNode(o,!0));return e.callExpression(e.identifier("_$mapArray"),[f,r,e.objectExpression([e.objectProperty(e.identifier("key"),u),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function R(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(N(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let s=r.value;if(e.isJSXExpressionContainer(s))return!1}return i.children.every(R)}return!1}function Y(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function W(i){if(e.isJSXText(i)){let a=F(i.value);return a?ee(a):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(N(i))return"";let s=`<${r}`;for(let a of n.attributes){if(e.isJSXSpreadAttribute(a))continue;let o=I(a);if(o==="key"||de(o)||o.startsWith("bind:")||o.includes("|"))continue;let c=o;if(o==="className"&&(c="class"),o==="htmlFor"&&(c="for"),!a.value)s+=` ${c}`;else if(e.isStringLiteral(a.value))s+=` ${c}="${me(a.value.value)}"`;else if(e.isJSXExpressionContainer(a.value))continue}let t=i.openingElement.selfClosing;if(t&&ue(r))return s+=">",s;if(t)return s+=`></${r}>`,s;s+=">";for(let a of i.children)if(e.isJSXText(a)){let o=F(a.value);o&&(s+=ee(o))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||(s+="<!--$-->"):e.isJSXElement(a)&&(N(a)?s+="<!--$-->":s+=W(a));return s+=`</${r}>`,s}function ee(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function me(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function X(i,n){let{node:r}=i,s=r.openingElement,t=s.name.name;if(!j(t,n)){if(t==="For")return he(i,n);if(t==="Show")return ge(i,n)}if(t==="Switch"&&(!j(t,n)||fe(r)))return xe(i,n);if(N(r))return re(i,n);let a=s.attributes,o=r.children,c=o.every(R),f=a.every(p=>!Y(p)),d=a.every(p=>{if(e.isJSXSpreadAttribute(p))return!1;let h=I(p);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(c&&f&&d){let p=W(r);if(p){let h=oe(n,p);return n.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let u=W(r);if(!u){let p=r.loc,h=n.filename||n.file?.opts?.filename||"<unknown>",g=p?`:${p.start.line}:${p.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${h}${g}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,V(i,n)}let l=oe(n,u);n.needsTemplate=!0;let m=n.nextVarId(),E=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier(l),[]))])];return ne(E,m,a,n,t),ie(E,m,o,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...E),e.identifier(m)}function V(i,n){let{node:r}=i,s=r.openingElement,t=s.name.name,a=s.attributes,o=r.children,c=[];for(let u of a){if(e.isJSXSpreadAttribute(u))continue;let l=I(u),m=$(u.value),E=G(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(E)?e.identifier(E):e.stringLiteral(E),m))}let f=[];for(let u of o)if(e.isJSXText(u)){let l=F(u.value);l&&f.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||f.push(u.expression):e.isJSXElement(u)?f.push(X({node:u},n)):e.isJSXFragment(u)&&f.push(L({node:u},n));let d=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),d,...f])}let Ee=new Set(["input","textarea","select","option"]);function ne(i,n,r,s,t){function a(f,d){return f==="class"?(s.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):f==="style"?(s.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):f==="value"&&t&&Ee.has(t)?(s.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):f==="checked"&&t==="input"?(s.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):f.startsWith("data-")||f.startsWith("aria-")?(s.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(f),d])):(s.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(f),d]))}let o=!1;function c(){o||(o=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let f of r){if(e.isJSXSpreadAttribute(f)){s.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),f.argument])));continue}let d=I(f);if(d!=="key"){if(d==="ref"){let u=$(f.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(d.startsWith("on")&&!d.includes("|")&&!C(d,s)){let u=d.slice(2).toLowerCase(),l=$(f.value);ke.has(u)?(s.needsDelegation=!0,s.delegatedEvents||(s.delegatedEvents=new Set),s.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),l)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),l])));continue}if(d.startsWith("on")&&(d.includes("|")||C(d,s))){let{eventName:u,modifiers:l}=b(d),m=$(f.value),E=z(m,l),p=u.slice(2).toLowerCase(),h=l.filter(x=>$e.has(x)),g=[e.stringLiteral(p),E];if(h.length>0){let x=h.map(w=>e.objectProperty(e.identifier(w),e.booleanLiteral(!0)));g.push(e.objectExpression(x))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),g)));continue}if(A(d)){let u=D(d),l=f.value.expression;s.needsEffect=!0,u==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(s.needsEffect=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("checked")),e.callExpression(e.cloneNode(l),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(l),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(f.value)){let u=f.value.expression,l=G(d);if(y(u,s.signalNames,s.importedIdentifiers)){s.needsEffect=!0;let m=s.signalNames&&s.signalNames.fromDestructuredProps,E=e.isIdentifier(u)&&!(m&&m.has(u.name))&&(J(u.name,s.signalNames)||s.importedIdentifiers&&s.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,p=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(l,E))]);K(u,s.signalNames,s.importedIdentifiers)&&e.addComment(p,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(p))}else i.push(e.expressionStatement(a(l,u)))}}}}function B(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(B);if(i.type==="JSXElement"||i.type==="JSXFragment"||i.type==="CallExpression"&&i.callee&&i.callee.type==="Identifier"&&(i.callee.name==="_$mapArray"||i.callee.name==="mapArray"))return!0;for(let n of Object.keys(i)){if(n==="loc"||n==="start"||n==="end"||n==="leadingComments"||n==="trailingComments"||n==="innerComments")continue;let r=i[n];if(r&&typeof r=="object"&&B(r))return!0}return!1}function M(i,n,r){let s=null,t=!1;if(e.isConditionalExpression(i))s=i.test,t=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))s=i.left;else return i;if(!y(s,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(B))return i;let o=r.nextMemoId();r.needsMemo=!0;let c=t?e.unaryExpression("!",e.unaryExpression("!",s)):s;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let f=e.callExpression(e.identifier(o),[]);return t?e.conditionalExpression(f,i.consequent,i.alternate):e.logicalExpression(i.operator,f,i.right)}function ie(i,n,r,s,t){let a=[],o=0;for(let l of r){if(e.isJSXText(l)){F(l.value)&&o++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:o}),o++;continue}if(e.isJSXElement(l)){let m=l.openingElement.name.name;if(N(l)||m==="For"||m==="Show")a.push({type:"component",child:l,childIndex:o}),o++;else{let E=l.openingElement.attributes.some(Y)||l.openingElement.attributes.some(p=>!e.isJSXSpreadAttribute(p)&&I(p)?.startsWith("on"))||!l.children.every(R);a.push({type:"static",child:l,childIndex:o,hasAnythingDynamic:E}),o++}continue}e.isJSXFragment(l)&&a.push({type:"fragment",child:l})}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),f=c.length>=2,d=new Map;if(f){let l=null,m=0;for(let E of c){let p=E.childIndex,h=t.nextVarId();d.set(p,h);let g;if(l===null)g=H(n,p);else{g=e.identifier(l);for(let x=m;x<p;x++)g=e.memberExpression(g,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),g)])),l=h,m=p}}function u(l){return d.has(l)?e.identifier(d.get(l)):H(n,l)}for(let l of a){if(l.type==="expression"){let m=l.child.expression,E=u(l.childIndex);t.needsInsert=!0;let p=Q(m,t);if(p){t.needsMapArray=!0;let g=e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="_$mapArray"||p.callee.name==="mapArray"),x=e.isArrowFunctionExpression(p);x&&e.isExpression(p.body)?p.body=M(p.body,i,t):!g&&!x&&(p=M(p,i,t));let w=g||x?p:e.arrowFunctionExpression([],p);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),w,E])));continue}if(e.isCallExpression(m)&&e.isIdentifier(m.callee)&&(m.callee.name==="mapArray"||m.callee.name==="_$mapArray")){t.needsMapArray=!0,m.callee.name==="mapArray"&&(m.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,E])));continue}if(y(m,t.signalNames,t.importedIdentifiers)){m=M(m,i,t);let g=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],m),E]);K(m,t.signalNames,t.importedIdentifiers)&&e.addComment(g,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(g))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,E])));continue}if(l.type==="component"){let m=X({node:l.child},t),E=u(l.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),m,E])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let m;d.has(l.childIndex)?m=d.get(l.childIndex):(m=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),H(n,l.childIndex))]))),ne(i,m,l.child.openingElement.attributes,t,l.child.openingElement.name.name),ie(i,m,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let m of l.child.children)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){t.needsInsert=!0;let E=m.expression;y(E,t.signalNames,t.importedIdentifiers)?(E=M(E,i,t),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],E)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E])))}}}}function H(i,n){if(n===0)return e.memberExpression(e.identifier(i),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(i),e.identifier("firstChild"));for(let s=0;s<n;s++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function re(i,n){let{node:r}=i,s=r.openingElement,t=U(s.name),a=s.attributes,o=r.children,c=null,f=[];for(let h of a){if(e.isJSXAttribute(h)){let g;if(e.isJSXNamespacedName(h.name)?g=`${h.name.namespace.name}:${h.name.name.name}`:g=h.name.name,g&&typeof g=="string"&&g.startsWith("client:")){let x=g.slice(7);h.value?c={type:x,value:h.value.value}:c={type:x};continue}}f.push(h)}function d(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],x=!1;for(let S of o)if(e.isJSXText(S)){let k=F(S.value);k&&g.push(e.stringLiteral(k))}else if(e.isJSXExpressionContainer(S))e.isJSXEmptyExpression(S.expression)||(x=!0,g.push(S.expression));else if(e.isJSXElement(S)){let k=S.openingElement.name.name;k!=="For"&&k!=="Show"&&k!=="Switch"&&(x=!0),g.push(X({node:S},n))}else e.isJSXFragment(S)&&(x=!0,g.push(L({node:S},n)));let w=e.arrayExpression(g);if(x){let S=n._pendingSetup?n._pendingSetup.splice(h):[];w=e.arrowFunctionExpression([],S.length>0?e.blockStatement([...S,e.returnStatement(w)]):w)}return w}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let g=null;for(let w of f){if(e.isJSXSpreadAttribute(w)){g=w.argument;continue}let S=I(w);if(S==="key")continue;let k=$(w.value);h.push(e.objectProperty(e.identifier(S),k))}let x=g?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),g,e.objectExpression(h)]):e.objectExpression(h);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),x,d()])}n.needsCreateComponent=!0;let u=[],l=!1,m=null;for(let h of f){if(e.isJSXSpreadAttribute(h)){l=!0,m=h.argument;continue}let g=I(h);if(g==="key")continue;if(A(g)){let w=D(g),S=h.value.expression;w==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(S),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):w==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(S),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(g.startsWith("on")&&(g.includes("|")||C(g,n))){let{eventName:w,modifiers:S}=b(g),k=$(h.value),_e=z(k,S);u.push(e.objectProperty(e.identifier(w),_e));continue}let x=$(h.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),x))}let E;l?u.length>0?E=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),m,e.objectExpression(u)]):E=m:u.length>0?E=e.objectExpression(u):E=e.nullLiteral();let p=d();return e.callExpression(e.identifier("_$createComponent"),[t,E,p])}function he(i,n){let{node:r}=i,s=r.openingElement.attributes,t=r.children,a=null,o=null;for(let d of s)if(e.isJSXAttribute(d)){let u=I(d);u==="each"?a=$(d.value):u==="key"&&(o=$(d.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,V(i,n);let c=null;for(let d of t)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){c=d.expression;break}if(!c)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,V(i,n);n.needsMapArray=!0;let f=[a,c];return o&&f.push(e.objectExpression([e.objectProperty(e.identifier("key"),o)])),e.callExpression(e.identifier("_$mapArray"),f)}function ge(i,n){let{node:r}=i,s=r.openingElement.attributes,t=r.children,a=null,o=null;for(let E of s)if(e.isJSXAttribute(E)){let p=I(E);p==="when"?a=$(E.value):p==="fallback"&&(o=$(E.value))}if(!a)throw i.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let E of t)if(e.isJSXExpressionContainer(E)&&!e.isJSXEmptyExpression(E.expression)){c=E.expression;break}if(!c){let E=[];for(let p of t)if(e.isJSXText(p)){let h=F(p.value);h&&E.push(e.stringLiteral(h))}else e.isJSXElement(p)&&E.push(X({node:p},n));E.length===1?c=E[0]:E.length>1?c=e.arrayExpression(E):c=e.nullLiteral()}let f=se(a,n),d=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),l=u?e.callExpression(c,[e.cloneNode(d)]):c,m=o||e.nullLiteral();if(y(f,n.signalNames,n.importedIdentifiers)){let E=n.nextMemoId();n.needsMemo=!0;let p=u?f:e.unaryExpression("!",e.unaryExpression("!",f));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],p)]))])),f=e.callExpression(e.identifier(E),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(d,f)]),e.returnStatement(e.conditionalExpression(e.cloneNode(d),l,m))]))}function se(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&J(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Se(i,n){let r=[];for(let s of i)if(e.isJSXText(s)){let t=F(s.value);t&&r.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||r.push(s.expression):e.isJSXElement(s)?r.push(X({node:s},n)):e.isJSXFragment(s)&&r.push(L({node:s},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function xe(i,n){let{node:r}=i,s=j(r.openingElement.name.name,n),t=p=>e.isJSXElement(p)&&e.isJSXIdentifier(p.openingElement.name,{name:"Match"})&&(s||!j("Match",n));if(!r.children.some(t)&&!ce(r.openingElement.name.name,n))return re(i,n);let a=p=>{let h=`<Switch> ${p}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`;throw i.buildCodeFrameError?i.buildCodeFrameError(h):new Error(`[what-compiler] ${h}`)},o=null;for(let p of r.openingElement.attributes)e.isJSXSpreadAttribute(p)&&a("cannot take a spread attribute"),I(p)==="fallback"&&(o=$(p.value));let c=[];for(let p of r.children){if(e.isJSXText(p)){F(p.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(p)){if(e.isJSXEmptyExpression(p.expression))continue;a("cannot read its arms from an expression child")}t(p)||a("cannot mix other elements with its <Match> arms"),c.push(p)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let f=[];for(let p of c){let h=null;for(let S of p.openingElement.attributes)e.isJSXAttribute(S)&&I(S)==="when"&&(h=$(S.value));h||a('has a <Match> with no "when" prop');let g=n._pendingSetup.length,x=Se(p.children,n),w=n._pendingSetup.splice(g);w.length>0&&(x=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...w,e.returnStatement(x)])),[])),f.push([se(h,n),x])}let d=f.some(([p])=>y(p,n.signalNames,n.importedIdentifiers)),u=o||e.nullLiteral();if(!d){let p=u;for(let h=f.length-1;h>=0;h--)p=e.conditionalExpression(f[h][0],f[h][1],p);return e.arrowFunctionExpression([],p)}let l=e.numericLiteral(-1);for(let p=f.length-1;p>=0;p--)l=e.conditionalExpression(f[p][0],e.numericLiteral(p),l);let m=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let E=u;for(let p=f.length-1;p>=0;p--)E=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(m),[]),e.numericLiteral(p)),f[p][1],E);return e.arrowFunctionExpression([],E)}function be(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,s=Q(i,n);if(s){n.needsMapArray=!0;let a=e.isCallExpression(s)&&e.isIdentifier(s.callee)&&(s.callee.name==="_$mapArray"||s.callee.name==="mapArray");if(e.isArrowFunctionExpression(s)&&e.isExpression(s.body))return s.body=M(s.body,r,n),s;if(a)return s;let c=M(s,r,n);return e.arrowFunctionExpression([],c)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):y(i,n.signalNames,n.importedIdentifiers)?(i=M(i,r,n),e.arrowFunctionExpression([],i)):i}function L(i,n){let{node:r}=i,s=r.children,t=[];for(let a of s)if(e.isJSXText(a)){let o=F(a.value);o&&t.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||t.push(be(a.expression,n)):e.isJSXElement(a)?t.push(X({node:a},n)):e.isJSXFragment(a)&&t.push(L({node:a},n));return t.length===1?t[0]:e.arrayExpression(t)}function oe(i,n){if(i.templateMap.has(n))return i.templateMap.get(n);let r=`_tmpl$${i.templateCount++}`;return i.templateMap.set(n,r),i.templates.push({id:r,html:n}),r}function te(i,n,r){let s=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let a=t.get(s);a||(a=q(i),t.set(s,a)),n.signalNames=a,n._pendingSetup=[];let o=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let f=i,d=!1;for(;f&&!f.isStatement();)(f.isArrowFunctionExpression()||f.isFunctionExpression())&&(d=!0),f=f.parentPath;f&&f.isStatement()&&(f.listKey==="body"||f.listKey==="consequent")&&Array.isArray(f.container)&&!d?(f.insertBefore(c),i.replaceWith(o)):(c.push(e.returnStatement(o)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(o)}function ye(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function we(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function ve(i){if(!e.isObjectExpression(i))return{property:null,value:null};for(let n of i.properties)if(!(!e.isObjectProperty(n)||(e.isIdentifier(n.key)&&!n.computed?n.key.name:e.isStringLiteral(n.key)?n.key.value:null)!=="id"))return e.isStringLiteral(n.value)?{property:n,value:n.value.value}:e.isTemplateLiteral(n.value)&&n.value.expressions.length===0?{property:n,value:n.value.quasis[0]?.value.cooked||""}:{property:n,value:null};return{property:null,value:null}}function ae(i,n,r,s,t){let a=i.node.loc?.start||{line:0,column:0},o=`${t}:${a.line}:${a.column+1}`,c=`${t}#${s}`,f=n.serverActionIds.get(r);if(f)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${f.bindingName}" at ${f.source}; conflicts with "${s}" at ${o}.`);let d={id:r,key:c,bindingName:s,filename:t,source:o,loc:a};if(n.serverActionIds.set(r,d),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(d)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Ae(i,n){if(!we(i,n))return;let r=ye(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let s=i.node.arguments[1],t=ve(s);if(t.property){t.value!==null&&ae(i,n,t.value,r,n.serverActionFilename);return}let a=`wa1_${Xe(`${n.serverActionFilename}#${r}`)}`;ae(i,n,a,r,n.serverActionFilename);let o=e.objectProperty(e.identifier("id"),e.stringLiteral(a));s?e.isObjectExpression(s)?s.properties.unshift(o):i.node.arguments[1]=e.objectExpression([o,e.spreadElement(s)]):i.node.arguments.push(e.objectExpression([o]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Me(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set,n.whatImports=new Set,n.foreignImports=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let s=r.source.value,t=s==="what-framework"||s.startsWith("what-framework/")||s==="what-core"||s.startsWith("what-core/"),a=t||s.startsWith("./")||s.startsWith("../");for(let o of r.specifiers){let c=null;(e.isImportSpecifier(o)&&e.isIdentifier(o.local)||e.isImportDefaultSpecifier(o)&&e.isIdentifier(o.local)||e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local))&&(c=o.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),t?n.whatImports.add(c):s.startsWith(".")||n.foreignImports.add(c)),Je.has(s)&&(e.isImportSpecifier(o)&&e.isIdentifier(o.imported,{name:"action"})&&e.isIdentifier(o.local)?n.serverActionBindings.add(o.local.name):e.isImportNamespaceSpecifier(o)&&e.isIdentifier(o.local)&&n.serverActionNamespaces.add(o.local.name))}}i.traverse({Function(r){pe(r)},CallExpression(r){Ae(r,n)},VariableDeclarator(r){let s=r.node.init;if(!s||!e.isCallExpression(s))return;let t=s.callee,a="";if(e.isIdentifier(t)?a=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(a=t.property.name),le.has(a)){let o=r.node.id;if(e.isIdentifier(o))n.signalNames.add(o.name);else if(e.isArrayPattern(o))for(let c of o.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(o))for(let c of o.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let t of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(t.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t.id),a)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let s=[];if(n.needsH&&s.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&s.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&s.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let t=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){t=a;break}if(t){let a=new Set(t.specifiers.filter(o=>e.isImportSpecifier(o)).map(o=>o.imported.name));for(let o of r)a.has(o.imported.name)||t.specifiers.push(o)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(s.length>0&&Le(i,e,s),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let t=e.arrayExpression([...n.delegatedEvents].map(o=>e.stringLiteral(o))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){te(i,n,X)},JSXFragment(i,n){te(i,n,L)}}}}function Le(e,v,_){let C=null;for(let b of e.node.body)if(v.isImportDeclaration(b)&&(b.source.value==="what-core"||b.source.value==="what-framework")){C=b;break}if(C){let b=new Set(C.specifiers.filter(A=>v.isImportSpecifier(A)).map(A=>A.imported.name));for(let A of _)b.has(A.imported.name)||C.specifiers.push(A)}else{let b=v.importDeclaration(_,v.stringLiteral("what-framework"));e.unshiftContainer("body",b)}}export{Ne as default};
|
|
1
|
+
var Je=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Me=new Set(["once","capture","passive"]),Ne=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Xe=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),T=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),fe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),De=new Set(["For","Show","Switch","Match"]),je=new Set(["what-framework/server","what-server","what-server/actions"]);function Le(e){let _=0xcbf29ce484222325n;for(let I=0;I<e.length;I++)_^=BigInt(e.charCodeAt(I)),_=BigInt.asUintN(64,_*0x100000001b3n);return _.toString(36)}function Pe(e,_){let I=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(_||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&I.startsWith(`${C}/`)?I.slice(C.length+1):I.replace(/^\.\//,"")}function J(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let _=e.split(/\r\n|\n|\r/),I=-1;for(let y=0;y<_.length;y++)/[^ \t]/.test(_[y])&&(I=y);if(I===-1)return"";let C="";for(let y=0;y<_.length;y++){let A=_[y].replace(/\t/g," "),P=y===0,W=y===_.length-1;P||(A=A.replace(/^ +/,"")),W||(A=A.replace(/ +$/,"")),A&&(y!==I&&(A+=" "),C+=A)}return C}function Oe({types:e}){let _=new Set,I=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(s=>s!=="").length===0)}function y(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],s=r.slice(1).filter(t=>Je.has(t));return{eventName:o,modifiers:s}}function A(i){return i.startsWith("bind:")}function P(i){return i.slice(5)}function W(i){return/^[A-Z]/.test(i)}function z(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let s=o?.loc?.start,t=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${t}:${s.line}:${s.column+1}`:t})`)}function j(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&W(n.name)}function O(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function pe(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function ue(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function q(i){return e.isJSXMemberExpression(i)?e.memberExpression(q(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function de(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let p=0;p<r.properties.length;p++){let m=r.properties[p];if(e.isRestElement(m))return;if(e.isObjectProperty(m)&&!m.computed&&e.isIdentifier(m.key,{name:"children"})){if(o!==-1||!e.isIdentifier(m.value))return;o=p}}if(o===-1)return;let s=i.scope.getBinding(r.properties[o].value.name);if(!s||s.constantViolations.length>0||s.referencePaths.length===0||!s.referencePaths.every(p=>{let m=p.parentPath;if(!m||!m.isJSXExpressionContainer())return!1;let u=m.parentPath;if(!u||!u.isJSXElement()||!j(u.node))return!1;let f=u.node.openingElement.name;return!(e.isJSXIdentifier(f)&&De.has(f.name))}))return;let a=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(a.typeAnnotation=r.typeAnnotation),n[0]=a;let c=r.properties.filter((p,m)=>m!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(a))])),i.node._whatMovedProps=p}for(let p of s.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(a),e.identifier("children")));i.scope.crawl()}function me(i){return Ne.has(String(i).toLowerCase())}function k(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function K(i){return i==="className"?"class":i==="htmlFor"?"for":i}function $(i){return e.isJSXNamespacedName(i.name)?`${i.name.namespace.name}:${i.name.name.name}`:typeof i.name.name=="string"?i.name.name:String(i.name.name)}function Ee(i){return!!i&&i.length>2&&/^on/i.test(i)}function Z(i,n){if(n.length===0)return i;let r=i;for(let o of n)switch(o){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function N(i,n){return n.has(i)}function he(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(a){let c=a.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,m="";if(e.isIdentifier(p)?m=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(m=p.property.name),fe.has(m)){let u=a.id;if(e.isIdentifier(u))n.add(u.name);else if(e.isArrayPattern(u))for(let f of u.elements)e.isIdentifier(f)&&n.add(f.name);else if(e.isObjectPattern(u))for(let f of u.properties)e.isObjectProperty(f)&&e.isIdentifier(f.value)&&n.add(f.value.name)}}function s(a){if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let t=i.scope;for(;t;){for(let c of Object.values(t.bindings))c.path.isVariableDeclarator()&&o(c.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let c of a.params)s(c);a._whatMovedProps&&s(a._whatMovedProps)}t=t.parent}return n}function Q(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?T.has(n.object.name):e.isIdentifier(n)?T.has(n.name):!1}function Y(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&N(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&N(i.callee.object.name,n)||Q(i))return!1;if(i.arguments.some(o=>w(o,n,r)))return!0}return!1}function w(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&N(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!T.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&N(i.callee.object.name,n)?!0:Q(i)?i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>w(o,n,r)):w(i.callee,n,r)||i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i)?N(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?w(i.object,n,r):e.isConditionalExpression(i)?w(i.test,n,r)||w(i.consequent,n,r)||w(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?w(i.left,n,r)||w(i.right,n,r):e.isUnaryExpression(i)?w(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>w(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&w(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&w(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function M(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":M(i.left,n);break;case"RestElement":M(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)M(r,n);break;case"ObjectPattern":for(let r of i.properties)M(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function ge(i){let n=new Set;for(let o=1;o<i.params.length;o++)M(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let s of o.declarations)M(s.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":M(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let s of Object.keys(o)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments")continue;let t=o[s];t&&typeof t=="object"&&r(t)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of M(i.params[0],new Set))n.delete(o);return n}function xe(i,n){if(n.size===0)return null;let r=null,o=s=>{if(!(r||!s||typeof s!="object")){if(Array.isArray(s)){s.forEach(o);return}if(s.type==="Identifier"){n.has(s.name)&&(r=s.name);return}for(let t of Object.keys(s)){if(t==="loc"||t==="start"||t==="end"||t==="type"||t==="leadingComments"||t==="trailingComments"||t==="innerComments"||s.type==="MemberExpression"&&t==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&t==="key"&&!s.computed)continue;let a=s[t];a&&typeof a=="object"&&o(a)}}};return o(i),r}function ee(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let t=R(r.consequent,n),a=R(r.alternate,n);if(t||a){let c=e.conditionalExpression(r.test,t||r.consequent,a||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let t=R(r.right,n);if(t){let a=e.logicalExpression(r.operator,r.left,t);return o?e.arrowFunctionExpression([],a):a}return null}return R(r,n)}function R(i,n){if(!e.isCallExpression(i)||!e.isMemberExpression(i.callee)||!e.isIdentifier(i.callee.property,{name:"map"})||i.arguments.length<1)return null;let r=i.arguments[0];if(!e.isArrowFunctionExpression(r)&&!e.isFunctionExpression(r))return null;let o=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))o=r.body;else if(e.isBlockStatement(r.body)){let d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}}else if(e.isFunctionExpression(r)){let d=r.body.body.find(l=>e.isReturnStatement(l));d&&(o=d.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,t=null;for(let d of s)if(e.isJSXAttribute(d)&&$(d)==="key"){t=d;break}if(!t)return null;let a=k(t.value);if(!a)return null;let c=ge(r);if(xe(a,c)){let d=e.isIdentifier(a)&&r.params[1]&&e.isIdentifier(r.params[1],{name:a.name});return null}o.openingElement.attributes=s.filter(d=>d!==t);let m=i.callee.object,u=e.arrowFunctionExpression([],m),f=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),E=e.arrowFunctionExpression([f],e.cloneNode(a,!0));return e.callExpression(e.identifier("_$mapArray"),[u,r,e.objectExpression([e.objectProperty(e.identifier("key"),E),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function V(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(j(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let o=r.value;if(e.isJSXExpressionContainer(o))return!1}return i.children.every(V)}return!1}function ne(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function B(i){if(e.isJSXText(i)){let t=J(i.value);return t?ie(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(j(i))return"";let o=`<${r}`;for(let t of n.attributes){if(e.isJSXSpreadAttribute(t))continue;let a=$(t);if(a==="key"||Ee(a)||a.startsWith("bind:")||a.includes("|"))continue;let c=a;if(a==="className"&&(c="class"),a==="htmlFor"&&(c="for"),!t.value)o+=` ${c}`;else if(e.isStringLiteral(t.value))o+=` ${c}="${be(t.value.value)}"`;else if(e.isJSXExpressionContainer(t.value))continue}let s=i.openingElement.selfClosing;if(s&&me(r))return o+=">",o;if(s)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let a=J(t.value);a&&(o+=ie(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)&&(j(t)?o+="<!--$-->":o+=B(t));return o+=`</${r}>`,o}function ie(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function be(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function X(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name;if(!O(s,n)){if(s==="For")return ve(i,n);if(s==="Show")return we(i,n)}if(s==="Switch"&&(!O(s,n)||ue(r)))return Ae(i,n);if(j(r))return se(i,n);let t=o.attributes,a=r.children,c=a.every(V),p=t.every(l=>!ne(l)),m=t.every(l=>{if(e.isJSXSpreadAttribute(l))return!1;let h=$(l);return!h?.startsWith("on")&&!h?.startsWith("bind:")});if(c&&p&&m){let l=B(r);if(l){let h=ae(n,l);return n.needsTemplate=!0,e.callExpression(e.identifier(h),[])}}let u=B(r);if(!u){let l=r.loc,h=n.filename||n.file?.opts?.filename||"<unknown>",g=l?`:${l.start.line}:${l.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${h}${g}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,G(i,n)}let f=ae(n,u);n.needsTemplate=!0;let E=n.nextVarId(),d=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier(f),[]))])];return re(d,E,t,n,s),oe(d,E,a,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...d),e.identifier(E)}function G(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,t=o.attributes,a=r.children,c=[];for(let u of t){if(e.isJSXSpreadAttribute(u))continue;let f=$(u),E=k(u.value),d=K(f);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(d)?e.identifier(d):e.stringLiteral(d),E))}let p=[];for(let u of a)if(e.isJSXText(u)){let f=J(u.value);f&&p.push(e.stringLiteral(f))}else e.isJSXExpressionContainer(u)?e.isJSXEmptyExpression(u.expression)||p.push(u.expression):e.isJSXElement(u)?p.push(X({node:u},n)):e.isJSXFragment(u)&&p.push(L({node:u},n));let m=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),m,...p])}let Se=new Set(["input","textarea","select","option"]);function re(i,n,r,o,s){function t(p,m){return p==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),m])):p==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),m])):p==="value"&&s&&Se.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),m])):p==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),m])):p.startsWith("data-")||p.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(p),m])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(p),m]))}let a=!1;function c(){a||(a=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let p of r){if(e.isJSXSpreadAttribute(p)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),p.argument])));continue}let m=$(p);if(m!=="key"){if(m==="ref"){let u=k(p.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(m.startsWith("on")&&!m.includes("|")&&!C(m,o)){let u=m.slice(2).toLowerCase(),f=k(p.value);Xe.has(u)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),f)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),f])));continue}if(m.startsWith("on")&&(m.includes("|")||C(m,o))){let{eventName:u,modifiers:f}=y(m),E=k(p.value),d=Z(E,f),l=u.slice(2).toLowerCase(),h=f.filter(x=>Me.has(x)),g=[e.stringLiteral(l),d];if(h.length>0){let x=h.map(S=>e.objectProperty(e.identifier(S),e.booleanLiteral(!0)));g.push(e.objectExpression(x))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),g)));continue}if(A(m)){let u=P(m),f=p.value.expression;o.needsEffect=!0,u==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(f),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(o.needsEffect=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("checked")),e.callExpression(e.cloneNode(f),[])))]))),i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(f),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(p.value)){let u=p.value.expression,f=K(m);if(w(u,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let E=o.signalNames&&o.signalNames.fromDestructuredProps,d=e.isIdentifier(u)&&!(E&&E.has(u.name))&&(N(u.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(u.name))?e.callExpression(u,[]):u,l=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],t(f,d))]);Y(u,o.signalNames,o.importedIdentifiers)&&e.addComment(l,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(l))}else i.push(e.expressionStatement(t(f,u)))}}}}function H(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(H);if(i.type==="JSXElement"||i.type==="JSXFragment"||i.type==="CallExpression"&&i.callee&&i.callee.type==="Identifier"&&(i.callee.name==="_$mapArray"||i.callee.name==="mapArray"))return!0;for(let n of Object.keys(i)){if(n==="loc"||n==="start"||n==="end"||n==="leadingComments"||n==="trailingComments"||n==="innerComments")continue;let r=i[n];if(r&&typeof r=="object"&&H(r))return!0}return!1}function ye(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function D(i,n,r){let o=null,s=!1;if(e.isConditionalExpression(i))o=i.test,s=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!w(o,r.signalNames,r.importedIdentifiers)||!(s?[i.consequent,i.alternate]:[i.right]).some(H))return i;let a=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(a),[]);return s?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function oe(i,n,r,o,s){let t=[],a=0;for(let f of r){if(e.isJSXText(f)){J(f.value)&&a++;continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;t.push({type:"expression",child:f,childIndex:a}),a++;continue}if(e.isJSXElement(f)){let E=f.openingElement.name.name;if(j(f)||E==="For"||E==="Show")t.push({type:"component",child:f,childIndex:a}),a++;else{let d=f.openingElement.attributes.some(ne)||f.openingElement.attributes.some(l=>!e.isJSXSpreadAttribute(l)&&$(l)?.startsWith("on"))||!f.children.every(V);t.push({type:"static",child:f,childIndex:a,hasAnythingDynamic:d}),a++}continue}e.isJSXFragment(f)&&t.push({type:"fragment",child:f})}let c=t.filter(f=>f.type==="expression"||f.type==="component"||f.type==="static"&&f.hasAnythingDynamic),p=c.length>=2,m=new Map;if(p){let f=null,E=0;for(let d of c){let l=d.childIndex,h=s.nextVarId();m.set(l,h);let g;if(f===null)g=U(n,l);else{g=e.identifier(f);for(let x=E;x<l;x++)g=e.memberExpression(g,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),g)])),f=h,E=l}}function u(f){return m.has(f)?e.identifier(m.get(f)):U(n,f)}for(let f of t){if(f.type==="expression"){let E=f.child.expression,d=u(f.childIndex);s.needsInsert=!0;let l=ee(E,s);if(l){s.needsMapArray=!0;let g=e.isCallExpression(l)&&e.isIdentifier(l.callee)&&(l.callee.name==="_$mapArray"||l.callee.name==="mapArray"),x=e.isArrowFunctionExpression(l);x&&e.isExpression(l.body)?l.body=D(l.body,i,s):!g&&!x&&(l=D(l,i,s));let S=g||x?l:e.arrowFunctionExpression([],l);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),S,d])));continue}if(e.isCallExpression(E)&&e.isIdentifier(E.callee)&&(E.callee.name==="mapArray"||E.callee.name==="_$mapArray")){s.needsMapArray=!0,E.callee.name==="mapArray"&&(E.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(w(E,s.signalNames,s.importedIdentifiers)){E=D(E,i,s);let g=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],E),d]);Y(E,s.signalNames,s.importedIdentifiers)&&e.addComment(g,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(g))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(f.type==="component"){let E=X({node:f.child},s),d=u(f.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),E,d])));continue}if(f.type==="static"&&f.hasAnythingDynamic){let E;m.has(f.childIndex)?E=m.get(f.childIndex):(E=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),U(n,f.childIndex))]))),re(i,E,f.child.openingElement.attributes,s,f.child.openingElement.name.name),oe(i,E,f.child.children,f.child,s);continue}if(f.type==="fragment"){for(let E of f.child.children)if(e.isJSXExpressionContainer(E)&&!e.isJSXEmptyExpression(E.expression)){s.needsInsert=!0;let d=E.expression;w(d,s.signalNames,s.importedIdentifiers)?(d=D(d,i,s),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],d)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),d])))}}}}function U(i,n){if(n===0)return e.memberExpression(e.identifier(i),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(i),e.identifier("firstChild"));for(let o=0;o<n;o++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function se(i,n){let{node:r}=i,o=r.openingElement,s=q(o.name),t=o.attributes,a=r.children,c=null,p=[];for(let h of t){if(e.isJSXAttribute(h)){let g;if(e.isJSXNamespacedName(h.name)?g=`${h.name.namespace.name}:${h.name.name.name}`:g=h.name.name,g&&typeof g=="string"&&g.startsWith("client:")){let x=g.slice(7);h.value?c={type:x,value:h.value.value}:c={type:x};continue}}p.push(h)}function m(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],x=!1;for(let b of a)if(e.isJSXText(b)){let v=J(b.value);v&&g.push(e.stringLiteral(v))}else if(e.isJSXExpressionContainer(b))e.isJSXEmptyExpression(b.expression)||(x=!0,g.push(b.expression));else if(e.isJSXElement(b)){let v=b.openingElement.name.name;v!=="For"&&v!=="Show"&&v!=="Switch"&&(x=!0),g.push(X({node:b},n))}else e.isJSXFragment(b)&&(x=!0,g.push(L({node:b},n)));let S=e.arrayExpression(g);if(x){let b=n._pendingSetup?n._pendingSetup.splice(h):[];S=e.arrowFunctionExpression([],b.length>0?e.blockStatement([...b,e.returnStatement(S)]):S)}return S}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),s),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let g=null;for(let S of p){if(e.isJSXSpreadAttribute(S)){g=S.argument;continue}let b=$(S);if(b==="key")continue;let v=k(S.value);h.push(e.objectProperty(e.identifier(b),v))}let x=g?e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),g,e.objectExpression(h)]):e.objectExpression(h);return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),x,m()])}n.needsCreateComponent=!0;let u=[],f=!1,E=null;for(let h of p){if(e.isJSXSpreadAttribute(h)){f=!0,E=h.argument;continue}let g=$(h);if(g==="key")continue;if(A(g)){let S=P(g),b=h.value.expression;S==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):S==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(b),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(b),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(g.startsWith("on")&&(g.includes("|")||C(g,n))){let{eventName:S,modifiers:b}=y(g),v=k(h.value),F=Z(v,b);u.push(e.objectProperty(e.identifier(S),F));continue}let x=k(h.value);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),x))}let d;f?u.length>0?d=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),E,e.objectExpression(u)]):d=E:u.length>0?d=e.objectExpression(u):d=e.nullLiteral();let l=m();return e.callExpression(e.identifier("_$createComponent"),[s,d,l])}function ve(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null,c=null;for(let v of o)if(e.isJSXAttribute(v)){let F=$(v);F==="each"?t=k(v.value):F==="key"?a=k(v.value):F==="fallback"&&(c=k(v.value))}if(!t)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,G(i,n);let p=null;for(let v of s)if(e.isJSXExpressionContainer(v)&&!e.isJSXEmptyExpression(v.expression)){p=v.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,G(i,n);n.needsMapArray=!0;let m=v=>{let F=[v,p];return a&&F.push(e.objectExpression([e.objectProperty(e.identifier("key"),a)])),e.callExpression(e.identifier("_$mapArray"),F)};if(!c)return m(t);n._pendingSetup||(n._pendingSetup=[]);let u=n.nextForIndex(),f=`_each$${u}`,E=`_for$${u}`,d=`_fb$${u}`,l=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let h=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),g=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(f)),e.stringLiteral("function")),e.callExpression(e.identifier(f),[]),e.identifier(f));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),t)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(h,g)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(h),e.memberExpression(e.cloneNode(h),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),m(e.identifier(f)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(l),[]),e.nullLiteral(),c)))]));let x=e.identifier("_parent"),S=e.identifier("_marker"),b=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([x,S],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(b,e.callExpression(e.identifier(E),[e.cloneNode(x),e.cloneNode(S)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(x),e.arrayExpression([e.identifier(d)]),e.cloneNode(S)])),e.returnStatement(e.cloneNode(b))])),e.identifier(E)])}function we(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,t=null,a=null;for(let d of o)if(e.isJSXAttribute(d)){let l=$(d);l==="when"?t=k(d.value):l==="fallback"&&(a=k(d.value))}if(!t)throw z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let d of s)if(e.isJSXExpressionContainer(d)&&!e.isJSXEmptyExpression(d.expression)){c=d.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let d=n._pendingSetup.length,l=[];for(let g of s)if(e.isJSXText(g)){let x=J(g.value);x&&l.push(e.stringLiteral(x))}else e.isJSXElement(g)&&l.push(X({node:g},n));l.length===1?c=l[0]:l.length>1?c=e.arrayExpression(l):c=e.nullLiteral();let h=n._pendingSetup.splice(d);h.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...h,e.returnStatement(c)])),[]))}let p=te(t,n),m=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),u=e.isFunction(c),f=u?e.callExpression(c,[e.cloneNode(m)]):c,E=a||e.nullLiteral();if(w(p,n.signalNames,n.importedIdentifiers)){let d=n.nextMemoId();n.needsMemo=!0;let l=u?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(d),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))])),p=e.callExpression(e.identifier(d),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(m,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(m),f,E))]))}function te(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&N(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function _e(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let s=J(o.value);s&&r.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(X({node:o},n)):e.isJSXFragment(o)&&r.push(L({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Ae(i,n){let{node:r}=i,o=O(r.openingElement.name.name,n),s=l=>e.isJSXElement(l)&&e.isJSXIdentifier(l.openingElement.name,{name:"Match"})&&(o||!O("Match",n));if(!r.children.some(s)&&!pe(r.openingElement.name.name,n))return se(i,n);let t=l=>{throw z(i,n,`<Switch> ${l}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`)},a=null;for(let l of r.openingElement.attributes)e.isJSXSpreadAttribute(l)&&t("cannot take a spread attribute"),$(l)==="fallback"&&(a=k(l.value));let c=[];for(let l of r.children){if(e.isJSXText(l)){J(l.value)&&t("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;t("cannot read its arms from an expression child")}s(l)||t("cannot mix other elements with its <Match> arms"),c.push(l)}c.length===0&&t("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let l of c){let h=null;for(let b of l.openingElement.attributes)e.isJSXAttribute(b)&&$(b)==="when"&&(h=k(b.value));h||t('has a <Match> with no "when" prop');let g=n._pendingSetup.length,x=_e(l.children,n),S=n._pendingSetup.splice(g);S.length>0&&(x=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...S,e.returnStatement(x)])),[])),p.push([te(h,n),x])}let m=p.some(([l])=>w(l,n.signalNames,n.importedIdentifiers)),u=a||e.nullLiteral();if(!m){let l=u;for(let h=p.length-1;h>=0;h--)l=e.conditionalExpression(p[h][0],p[h][1],l);return e.arrowFunctionExpression([],l)}let f=e.numericLiteral(-1);for(let l=p.length-1;l>=0;l--)f=e.conditionalExpression(p[l][0],e.numericLiteral(l),f);let E=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))]));let d=u;for(let l=p.length-1;l>=0;l--)d=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(E),[]),e.numericLiteral(l)),p[l][1],d);return e.arrowFunctionExpression([],d)}function Ie(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=ee(i,n);if(o){n.needsMapArray=!0;let t=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=D(o.body,r,n),o;if(t)return o;let c=D(o,r,n);return e.arrowFunctionExpression([],c)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):w(i,n.signalNames,n.importedIdentifiers)?(i=D(i,r,n),e.arrowFunctionExpression([],i)):i}function L(i,n){let{node:r}=i,o=r.children,s=[];for(let t of o)if(e.isJSXText(t)){let a=J(t.value);a&&s.push(e.stringLiteral(a))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||s.push(Ie(t.expression,n)):e.isJSXElement(t)?s.push(X({node:t},n)):e.isJSXFragment(t)&&s.push(L({node:t},n));return s.length===1?s[0]:e.arrayExpression(s)}function ae(i,n){if(i.templateMap.has(n))return i.templateMap.get(n);let r=`_tmpl$${i.templateCount++}`;return i.templateMap.set(n,r),i.templates.push({id:r,html:n}),r}function le(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let t=s.get(o);t||(t=he(i),s.set(o,t)),n.signalNames=t,n._pendingSetup=[];let a=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,m=!1,u=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(m=!0),ye(p)&&(u=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!m&&!u?(p.insertBefore(c),i.replaceWith(a)):(c.push(e.returnStatement(a)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(a)}function Ce(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function ke(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function $e(i){if(!e.isObjectExpression(i))return{property:null,value:null};for(let n of i.properties)if(!(!e.isObjectProperty(n)||(e.isIdentifier(n.key)&&!n.computed?n.key.name:e.isStringLiteral(n.key)?n.key.value:null)!=="id"))return e.isStringLiteral(n.value)?{property:n,value:n.value.value}:e.isTemplateLiteral(n.value)&&n.value.expressions.length===0?{property:n,value:n.value.quasis[0]?.value.cooked||""}:{property:n,value:null};return{property:null,value:null}}function ce(i,n,r,o,s){let t=i.node.loc?.start||{line:0,column:0},a=`${s}:${t.line}:${t.column+1}`,c=`${s}#${o}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${o}" at ${a}.`);let m={id:r,key:c,bindingName:o,filename:s,source:a,loc:t};if(n.serverActionIds.set(r,m),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(m)}catch(u){throw i.buildCodeFrameError(u instanceof Error?u.message:String(u))}}function Fe(i,n){if(!ke(i,n))return;let r=Ce(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let o=i.node.arguments[1],s=$e(o);if(s.property){s.value!==null&&ce(i,n,s.value,r,n.serverActionFilename);return}let t=`wa1_${Le(`${n.serverActionFilename}#${r}`)}`;ce(i,n,t,r,n.serverActionFilename);let a=e.objectProperty(e.identifier("id"),e.stringLiteral(t));o?e.isObjectExpression(o)?o.properties.unshift(a):i.node.arguments[1]=e.objectExpression([a,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([a]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=Pe(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set,n.whatImports=new Set,n.foreignImports=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let o=r.source.value,s=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/"),t=s||o.startsWith("./")||o.startsWith("../");for(let a of r.specifiers){let c=null;(e.isImportSpecifier(a)&&e.isIdentifier(a.local)||e.isImportDefaultSpecifier(a)&&e.isIdentifier(a.local)||e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local))&&(c=a.local.name),c&&((t||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),je.has(o)&&(e.isImportSpecifier(a)&&e.isIdentifier(a.imported,{name:"action"})&&e.isIdentifier(a.local)?n.serverActionBindings.add(a.local.name):e.isImportNamespaceSpecifier(a)&&e.isIdentifier(a.local)&&n.serverActionNamespaces.add(a.local.name))}}i.traverse({Function(r){de(r)},CallExpression(r){Fe(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,t="";if(e.isIdentifier(s)?t=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(t=s.property.name),fe.has(t)){let a=r.node.id;if(e.isIdentifier(a))n.signalNames.add(a.name);else if(e.isArrayPattern(a))for(let c of a.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(a))for(let c of a.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let s of n.templates.reverse()){let t=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(t,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.id),t)]))}let r=[];n.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("_$template"))),n.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),n.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),n.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),n.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),n.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),n.needsMemo&&r.push(e.importSpecifier(e.identifier("_$memo"),e.identifier("memo"))),n.needsSetClass&&r.push(e.importSpecifier(e.identifier("_$setClass"),e.identifier("setClass"))),n.needsSetStyle&&r.push(e.importSpecifier(e.identifier("_$setStyle"),e.identifier("setStyle"))),n.needsSetAttr&&r.push(e.importSpecifier(e.identifier("_$setAttr"),e.identifier("setAttr"))),n.needsSetValue&&r.push(e.importSpecifier(e.identifier("_$setValue"),e.identifier("setValue"))),n.needsSetChecked&&r.push(e.importSpecifier(e.identifier("_$setChecked"),e.identifier("setChecked"))),n.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let o=[];if(n.needsH&&o.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&o.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&o.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let s=null;for(let t of i.node.body)if(e.isImportDeclaration(t)&&(t.source.value==="what-framework/render"||t.source.value==="what-core/render")){s=t;break}if(s){let t=new Set(s.specifiers.filter(a=>e.isImportSpecifier(a)).map(a=>a.imported.name));for(let a of r)t.has(a.imported.name)||s.specifiers.push(a)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Re(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(a=>e.stringLiteral(a))),t=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),t])}}},JSXElement(i,n){le(i,n,X)},JSXFragment(i,n){le(i,n,L)}}}}function Re(e,_,I){let C=null;for(let y of e.node.body)if(_.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){C=y;break}if(C){let y=new Set(C.specifiers.filter(A=>_.isImportSpecifier(A)).map(A=>A.imported.name));for(let A of I)y.has(A.imported.name)||C.specifiers.push(A)}else{let y=_.importDeclaration(I,_.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Oe as default};
|
package/dist/file-router.min.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import $ from"fs";import d from"path";var E=new Set([".jsx",".tsx",".js",".ts"]),I=new Set(["_layout","_error","_loading","_404"]);function C(t){let a=[],e=[],c=[];function s(n,r=""){if(!$.existsSync(n))return;let p=$.readdirSync(n,{withFileTypes:!0});for(let u of p){let l=d.join(n,u.name);if(u.isDirectory()){if(u.name.match(/^\((.+)\)$/)){s(l,r);continue}if(u.name==="api"&&r===""){i(l,"/api");continue}s(l,r+"/"+x(u.name));continue}let o=d.extname(u.name);if(!E.has(o))continue;let h=d.basename(u.name,o);if(h==="_layout"){e.push({filePath:l,urlPrefix:r||"/"});continue}if(I.has(h))continue;let f=x(h),m=h==="index"?r||"/":r+"/"+f;a.push({filePath:l,routePath:_(m),isDynamic:m.includes(":")||m.includes("*")})}}function i(n,r){if(!$.existsSync(n))return;let p=$.readdirSync(n,{withFileTypes:!0});for(let u of p){let l=d.join(n,u.name);if(u.isDirectory()){i(l,r+"/"+x(u.name));continue}let o=d.extname(u.name);if(!E.has(o))continue;let h=d.basename(u.name,o),f=x(h),m=h==="index"?r:r+"/"+f;c.push({filePath:l,routePath:_(m)})}}return s(t),a.sort((n,r)=>{let p=v(n.routePath),u=v(r.routePath);return p-u}),{pages:a,layouts:e,apiRoutes:c}}function x(t){let a=t.match(/^\[\.\.\.(\w+)\]$/);if(a)return"*"+a[1];let e=t.match(/^\[(\w+)\]$/);return e?":"+e[1]:t.toLowerCase()}function _(t){let a=t.replace(/\/+/g,"/");return a.length>1&&a.endsWith("/")&&(a=a.slice(0,-1)),a||"/"}function v(t){return t.includes("*")?100:t.includes(":")?10:0}var R=/export\s+const\s+page\s*=\s*\{/;function j(t,a={}){let e=R.exec(t);if(!e)return{mode:"client"};let c=e.index+e[0].length-1;try{return{mode:"client",...JSON.parse(T(t,c))}}catch(s){return k(s,a.filePath),{mode:"client"}}}function k(t,a){let e=a?` in ${a}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${e}: ${t.message}
|
|
2
|
+
This page falls back to mode 'client', so static generation will skip it.
|
|
3
|
+
\`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`)}var A=t=>/[A-Za-z_$]/.test(t),G=t=>/[A-Za-z0-9_$]/.test(t);function T(t,a){let e=[],c=-1,s=0,i=a;for(;i<t.length;){let n=t[i];if(n==="/"&&t[i+1]==="/"){let r=t.indexOf(`
|
|
4
|
+
`,i);i=r===-1?t.length:r,e.push(" ");continue}if(n==="/"&&t[i+1]==="*"){let r=t.indexOf("*/",i+2);if(r===-1)throw new SyntaxError("unterminated block comment");i=r+2,e.push(" ");continue}if(n==='"'||n==="'"||n==="`"){let r=M(t,i);e.push(JSON.stringify(r.value)),c=-1,i=r.end;continue}if(A(n)){let r=i+1;for(;r<t.length&&G(t[r]);)r++;let p=t.slice(i,r);e.push(F(t,r)?JSON.stringify(p):p),c=-1,i=r;continue}if(n===" "||n===" "||n===`
|
|
5
|
+
`||n==="\r"){e.push(n),i++;continue}if(n===","){e.push(","),c=e.length-1,i++;continue}if(n==="}"||n==="]"){if(c!==-1&&(e[c]=""),c=-1,e.push(n),i++,n==="}"&&--s===0)return e.join("");continue}n==="{"&&s++,e.push(n),c=-1,i++}throw new SyntaxError("unterminated object literal")}function F(t,a){let e=a;for(;e<t.length;){let c=t[e];if(c===" "||c===" "||c===`
|
|
6
|
+
`||c==="\r"){e++;continue}if(c==="/"&&t[e+1]==="/"){let s=t.indexOf(`
|
|
7
|
+
`,e);if(s===-1)return!1;e=s+1;continue}if(c==="/"&&t[e+1]==="*"){let s=t.indexOf("*/",e+2);if(s===-1)return!1;e=s+2;continue}return c===":"}return!1}var N={n:`
|
|
8
|
+
`,t:" ",r:"\r",b:"\b",f:"\f",v:"\v",0:"\0","\\":"\\","'":"'",'"':'"',"`":"`","/":"/"};function M(t,a){let e=t[a],c="",s=a+1;for(;s<t.length;){let i=t[s];if(i==="\\"){let n=t[s+1];if(n===void 0)break;if(n===`
|
|
9
|
+
`){s+=2;continue}if(n==="\r"){s+=t[s+2]===`
|
|
10
|
+
`?3:2;continue}if(n==="u"){if(t[s+2]==="{"){let r=t.indexOf("}",s+3);if(r===-1)throw new SyntaxError("invalid unicode escape");c+=String.fromCodePoint(parseInt(t.slice(s+3,r),16)),s=r+1;continue}c+=String.fromCharCode(parseInt(t.slice(s+2,s+6),16)),s+=6;continue}if(n==="x"){c+=String.fromCharCode(parseInt(t.slice(s+2,s+4),16)),s+=4;continue}c+=Object.prototype.hasOwnProperty.call(N,n)?N[n]:n,s+=2;continue}if(i===e)return{value:c,end:s+1};if(e==="`"&&i==="$"&&t[s+1]==="{")throw new SyntaxError("template literal interpolation cannot be resolved at build time");if(e!=="`"&&(i===`
|
|
11
|
+
`||i==="\r"))break;c+=i,s++}throw new SyntaxError("unterminated string literal")}function L(t){return{hasLoader:/export\s+(?:async\s+)?(?:const|let|var|function)\s+loader\b/.test(t),hasGetStaticPaths:/export\s+(?:async\s+)?(?:const|let|var|function)\s+getStaticPaths\b/.test(t),hasPageConfig:/export\s+const\s+page\b/.test(t)}}function z(t,a){let{pages:e,layouts:c,apiRoutes:s}=C(t),i=[],n=[],r=new Map;c.forEach((l,o)=>{let h=`_layout${o}`,f=y(l.filePath,a);i.push(`import ${h} from '${f}';`),r.set(l.urlPrefix,h)}),e.forEach((l,o)=>{let h=`_page${o}`,f=y(l.filePath,a);i.push(`import ${h} from '${f}';`);let m={mode:"client"},P={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let S=$.readFileSync(l.filePath,"utf-8");m=j(S,{filePath:l.filePath}),P=L(S)}catch{}let w=O(l.routePath,r),g={path:l.routePath,component:h,mode:m.mode||"client",layout:w||null,hasLoader:P.hasLoader};n.push(g)});let p=[];return s.forEach((l,o)=>{let h=`_api${o}`,f=y(l.filePath,a);i.push(`import * as ${h} from '${f}';`),p.push({path:l.routePath,handlers:h})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...i,"","export const routes = [",...n.map(l=>` { path: '${l.path}', component: ${l.component}, mode: '${l.mode}'${l.layout?`, layout: ${l.layout}`:""}${l.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...p.map(l=>` { path: '${l.path}', handlers: ${l.handlers} },`),"];","","export const pageModes = {",...n.map(l=>` '${l.path}': '${l.mode}',`),"};"].join(`
|
|
12
|
+
`)}function D(t,a){let{pages:e,layouts:c,apiRoutes:s}=C(t),i=[],n=[],r=new Map;c.forEach((o,h)=>{let f=`_layout${h}`;i.push(`import ${f} from '${y(o.filePath,a)}';`),r.set(o.urlPrefix,f)}),e.forEach((o,h)=>{let f=`_page${h}`,m=`_page${h}_ns`,P=y(o.filePath,a),w={mode:"client"},g={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let b=$.readFileSync(o.filePath,"utf-8");w=j(b,{filePath:o.filePath}),g=L(b)}catch{}g.hasLoader||g.hasGetStaticPaths||g.hasPageConfig?i.push(`import ${f}, * as ${m} from '${P}';`):i.push(`import ${f} from '${P}';`),n.push({path:o.routePath,component:f,ns:m,mode:w.mode||"client",layout:O(o.routePath,r)||null,...g})});let p=[];s.forEach((o,h)=>{let f=`_api${h}`;i.push(`import * as ${f} from '${y(o.filePath,a)}';`),p.push({path:o.routePath,handlers:f})});let u=o=>` { path: '${o.path}', component: ${o.component}, mode: '${o.mode}'${o.layout?`, layout: ${o.layout}`:""}${o.hasLoader?`, loader: ${o.ns}.loader`:""}${o.hasGetStaticPaths?`, getStaticPaths: ${o.ns}.getStaticPaths`:""}${o.hasPageConfig?`, page: ${o.ns}.page`:""} },`;return["// Auto-generated by What Framework file router (server)","// Do not edit \u2014 changes will be overwritten","",...i,"","export const routes = [",...n.map(u),"];","","export const apiRoutes = [",...p.map(o=>` { path: '${o.path}', handlers: ${o.handlers} },`),"];","","export const pageModes = {",...n.map(o=>` '${o.path}': '${o.mode}',`),"};"].join(`
|
|
13
|
+
`)}function y(t,a){return"/"+d.relative(a,t).split(d.sep).join("/")}function O(t,a){let e=t.split("/").filter(Boolean);for(;e.length>0;){let c="/"+e.join("/");if(a.has(c))return a.get(c);e.pop()}return a.has("/")?a.get("/"):null}export{L as detectPageExports,j as extractPageConfig,z as generateRoutesModule,D as generateServerRoutesModule,C as scanPages};
|