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