what-compiler 0.11.6 → 0.11.8
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/index.min.js +6 -6
- package/dist/vite-plugin.min.js +6 -6
- package/package.json +2 -2
- package/src/babel-plugin.js +532 -58
- package/src/vite-plugin.js +60 -4
package/dist/vite-plugin.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
1
|
+
import Y from"path";import{transformSync as tn}from"@babel/core";var Ve=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Be=new Set(["once","capture","passive"]),Ue=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ze=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),ne=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),_e=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),Ge=new Set(["For","Show","Switch","Match"]),qe=new Set(["what-framework/server","what-server","what-server/actions"]);function Ze(e){let m=0xcbf29ce484222325n;for(let x=0;x<e.length;x++)m^=BigInt(e.charCodeAt(x)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function Ke(e,m){let x=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),C=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return C&&x.startsWith(`${C}/`)?x.slice(C.length+1):x.replace(/^\.\//,"")}function W(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),x=-1;for(let _=0;_<m.length;_++)/[^ \t]/.test(m[_])&&(x=_);if(x===-1)return"";let C="";for(let _=0;_<m.length;_++){let $=m[_].replace(/\t/g," "),F=_===0,P=_===m.length-1;F||($=$.replace(/^ +/,"")),P||($=$.replace(/ +$/,"")),$&&(_!==x&&($+=" "),C+=$)}return C}function fe({types:e}){let m=new Set,x=new Set;function C(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(t=>t!=="").length===0)}function _(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],t=r.slice(1).filter(a=>Ve.has(a));return{eventName:o,modifiers:t}}function $(i){return i.startsWith("bind:")}function F(i){return i.slice(5)}function P(i){return/^[A-Z]/.test(i)}function L(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&P(n.name)}function k(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function S(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function T(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function A(i){return e.isJSXMemberExpression(i)?e.memberExpression(A(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function X(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let c=0;c<r.properties.length;c++){let p=r.properties[c];if(e.isRestElement(p))return;if(e.isObjectProperty(p)&&!p.computed&&e.isIdentifier(p.key,{name:"children"})){if(o!==-1||!e.isIdentifier(p.value))return;o=c}}if(o===-1)return;let t=i.scope.getBinding(r.properties[o].value.name);if(!t||t.constantViolations.length>0||t.referencePaths.length===0||!t.referencePaths.every(c=>{let p=c.parentPath;if(!p||!p.isJSXExpressionContainer())return!1;let d=p.parentPath;if(!d||!d.isJSXElement()||!L(d.node))return!1;let l=d.node.openingElement.name;return!(e.isJSXIdentifier(l)&&Ge.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let u=r.properties.filter((c,p)=>p!==o);if(u.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let c=e.objectPattern(u);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(c,e.cloneNode(s))])),i.node._whatMovedProps=c}for(let c of t.referencePaths)c.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function j(i){return Ue.has(String(i).toLowerCase())}function N(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}function b(i){return i==="className"?"class":i==="htmlFor"?"for":i}function y(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 J(i){return!!i&&i.length>2&&/^on/i.test(i)}function U(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 D(i,n){return n.has(i)}function Q(i){let n=new Set;function r(a){let s=a.init;if(!s||!e.isCallExpression(s))return;let u=s.callee,c="";if(e.isIdentifier(u)?c=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(c=u.property.name),_e.has(c)){let p=a.id;if(e.isIdentifier(p))n.add(p.name);else if(e.isArrayPattern(p))for(let d of p.elements)e.isIdentifier(d)&&n.add(d.name);else if(e.isObjectPattern(p))for(let d of p.properties)e.isObjectProperty(d)&&e.isIdentifier(d.value)&&n.add(d.value.name)}}function o(a){if(e.isObjectPattern(a))for(let s of a.properties)e.isObjectProperty(s)&&e.isIdentifier(s.value)?n.add(s.value.name):e.isRestElement(s)&&e.isIdentifier(s.argument)&&n.add(s.argument.name)}let t=i.scope;for(;t;){for(let s of Object.values(t.bindings))s.path.isVariableDeclarator()&&r(s.path.node);let a=t.path&&t.path.node;if(a){if(a.params)for(let s of a.params)o(s);a._whatMovedProps&&o(a._whatMovedProps)}t=t.parent}return n}function O(i){return Q(i)}function q(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?ne.has(n.object.name):e.isIdentifier(n)?ne.has(n.name):!1}function oe(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&D(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&D(i.callee.object.name,n)||q(i))return!1;if(i.arguments.some(o=>M(o,n,r)))return!0}return!1}function M(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&D(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!ne.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&D(i.callee.object.name,n)?!0:q(i)?i.arguments.some(o=>M(o,n,r)):e.isIdentifier(i.callee)?i.arguments.some(o=>M(o,n,r)):M(i.callee,n,r)||i.arguments.some(o=>M(o,n,r)):e.isIdentifier(i)?D(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?M(i.object,n,r):e.isConditionalExpression(i)?M(i.test,n,r)||M(i.consequent,n,r)||M(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?M(i.left,n,r)||M(i.right,n,r):e.isUnaryExpression(i)?M(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>M(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&M(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&M(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function me(i,n){let r=i,o=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,o=!0),e.isConditionalExpression(r)){let a=ee(r.consequent,n),s=ee(r.alternate,n);if(a||s){let u=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return o?e.arrowFunctionExpression([],u):u}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=ee(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return o?e.arrowFunctionExpression([],s):s}return null}return ee(r,n)}function ee(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 l=r.body.body.find(g=>e.isReturnStatement(g));l&&(o=l.argument)}}else if(e.isFunctionExpression(r)){let l=r.body.body.find(g=>e.isReturnStatement(g));l&&(o=l.argument)}if(!o||!e.isJSXElement(o))return null;let t=o.openingElement.attributes,a=null;for(let l of t)if(e.isJSXAttribute(l)&&y(l)==="key"){a=l;break}if(!a)return null;let s=N(a.value);if(!s)return null;o.openingElement.attributes=t.filter(l=>l!==a);let u=i.callee.object,c=e.arrowFunctionExpression([],u),p=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),d=e.arrowFunctionExpression([p],e.cloneNode(s,!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 se(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(L(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(se)}return!1}function he(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function te(i){if(e.isJSXText(i)){let a=W(i.value);return a?ge(a):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(L(i))return"";let o=`<${r}`;for(let a of n.attributes){if(e.isJSXSpreadAttribute(a))continue;let s=y(a);if(s==="key"||J(s)||s.startsWith("bind:")||s.includes("|"))continue;let u=s;if(s==="className"&&(u="class"),s==="htmlFor"&&(u="for"),!a.value)o+=` ${u}`;else if(e.isStringLiteral(a.value))o+=` ${u}="${Me(a.value.value)}"`;else if(e.isJSXExpressionContainer(a.value))continue}let t=i.openingElement.selfClosing;if(t&&j(r))return o+=">",o;if(t)return o+=`></${r}>`,o;o+=">";for(let a of i.children)if(e.isJSXText(a)){let s=W(a.value);s&&(o+=ge(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||(o+="<!--$-->"):e.isJSXElement(a)&&(L(a)?o+="<!--$-->":o+=te(a));return o+=`</${r}>`,o}function ge(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Me(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function V(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name;if(!k(t,n)){if(t==="For")return Pe(i,n);if(t==="Show")return Ne(i,n)}if(t==="Switch"&&(!k(t,n)||T(r)))return Te(i,n);if(L(r))return be(i,n);let a=o.attributes,s=r.children,u=s.every(se),c=a.every(f=>!he(f)),p=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let w=y(f);return!w?.startsWith("on")&&!w?.startsWith("bind:")});if(u&&c&&p){let f=te(r);if(f){let w=Se(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(w),[])}}let d=te(r);if(!d){let f=r.loc,w=n.filename||n.file?.opts?.filename||"<unknown>",I=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${t}> at ${w}${I}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,ae(i,n)}let l=Se(n,d);n.needsTemplate=!0;let g=n.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier(l),[]))])];return Ee(h,g,a,n,t),xe(h,g,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...h),e.identifier(g)}function ae(i,n){let{node:r}=i,o=r.openingElement,t=o.name.name,a=o.attributes,s=r.children,u=[];for(let d of a){if(e.isJSXSpreadAttribute(d))continue;let l=y(d),g=N(d.value),h=b(l);u.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),g))}let c=[];for(let d of s)if(e.isJSXText(d)){let l=W(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(V({node:d},n)):e.isJSXFragment(d)&&c.push(Z({node:d},n));let p=u.length>0?e.objectExpression(u):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(t),p,...c])}let Fe=new Set(["input","textarea","select","option"]);function Ee(i,n,r,o,t){function a(c,p){return c==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),p])):c==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),p])):c==="value"&&t&&Fe.has(t)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),p])):c==="checked"&&t==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),p])):c.startsWith("data-")||c.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(c),p])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(c),p]))}let s=!1;function u(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}for(let c of r){if(e.isJSXSpreadAttribute(c)){o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),c.argument])));continue}let p=y(c);if(p!=="key"){if(p==="ref"){let d=N(c.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",d),e.stringLiteral("function")),e.callExpression(e.cloneNode(d),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(d),e.identifier("current")),e.identifier(n)))));continue}if(p.startsWith("on")&&!p.includes("|")&&!C(p,o)){let d=p.slice(2).toLowerCase(),l=N(c.value);ze.has(d)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(d),u(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${d}`)),l)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(d),l])));continue}if(p.startsWith("on")&&(p.includes("|")||C(p,o))){let{eventName:d,modifiers:l}=_(p),g=N(c.value),h=U(g,l),f=d.slice(2).toLowerCase(),w=l.filter(E=>Be.has(E)),I=[e.stringLiteral(f),h];if(w.length>0){let E=w.map(v=>e.objectProperty(e.identifier(v),e.booleanLiteral(!0)));I.push(e.objectExpression(E))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),I)));continue}if($(p)){let d=F(p),l=c.value.expression;o.needsEffect=!0,d==="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"))]))])))):d==="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(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(c.value)){let d=c.value.expression,l=b(p);if(M(d,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let g=e.isIdentifier(d)&&(D(d.name,o.signalNames)||o.importedIdentifiers&&o.importedIdentifiers.has(d.name))?e.callExpression(d,[]):d,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(l,g))]);oe(d,o.signalNames,o.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(h))}else i.push(e.expressionStatement(a(l,d)))}}}}function le(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(le);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"&&le(r))return!0}return!1}function B(i,n,r){let o=null,t=!1;if(e.isConditionalExpression(i))o=i.test,t=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!M(o,r.signalNames,r.importedIdentifiers)||!(t?[i.consequent,i.alternate]:[i.right]).some(le))return i;let s=r.nextMemoId();r.needsMemo=!0;let u=t?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],u)]))]));let c=e.callExpression(e.identifier(s),[]);return t?e.conditionalExpression(c,i.consequent,i.alternate):e.logicalExpression(i.operator,c,i.right)}function xe(i,n,r,o,t){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){W(l.value)&&s++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:s}),s++;continue}if(e.isJSXElement(l)){let g=l.openingElement.name.name;if(L(l)||g==="For"||g==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let h=l.openingElement.attributes.some(he)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&y(f)?.startsWith("on"))||!l.children.every(se);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:h}),s++}continue}e.isJSXFragment(l)&&a.push({type:"fragment",child:l})}let u=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),c=u.length>=2,p=new Map;if(c){let l=null,g=0;for(let h of u){let f=h.childIndex,w=t.nextVarId();p.set(f,w);let I;if(l===null)I=ce(n,f);else{I=e.identifier(l);for(let E=g;E<f;E++)I=e.memberExpression(I,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(w),I)])),l=w,g=f}}function d(l){return p.has(l)?e.identifier(p.get(l)):ce(n,l)}for(let l of a){if(l.type==="expression"){let g=l.child.expression,h=d(l.childIndex);t.needsInsert=!0;let f=me(g,t);if(f){t.needsMapArray=!0;let I=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),E=e.isArrowFunctionExpression(f);E&&e.isExpression(f.body)?f.body=B(f.body,i,t):!I&&!E&&(f=B(f,i,t));let v=I||E?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),v,h])));continue}if(e.isCallExpression(g)&&e.isIdentifier(g.callee)&&(g.callee.name==="mapArray"||g.callee.name==="_$mapArray")){t.needsMapArray=!0,g.callee.name==="mapArray"&&(g.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(M(g,t.signalNames,t.importedIdentifiers)){g=B(g,i,t);let I=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],g),h]);oe(g,t.signalNames,t.importedIdentifiers)&&e.addComment(I,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(I))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(l.type==="component"){let g=V({node:l.child},t),h=d(l.childIndex);t.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),g,h])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let g;p.has(l.childIndex)?g=p.get(l.childIndex):(g=t.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),ce(n,l.childIndex))]))),Ee(i,g,l.child.openingElement.attributes,t,l.child.openingElement.name.name),xe(i,g,l.child.children,l.child,t);continue}if(l.type==="fragment"){for(let g of l.child.children)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){t.needsInsert=!0;let h=g.expression;M(h,t.signalNames,t.importedIdentifiers)?(h=B(h,i,t),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],h)])))):i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),h])))}}}}function ce(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 be(i,n){let{node:r}=i,o=r.openingElement,t=A(o.name),a=o.attributes,s=r.children,u=null,c=[];for(let E of a){if(e.isJSXAttribute(E)){let v;if(e.isJSXNamespacedName(E.name)?v=`${E.name.namespace.name}:${E.name.name.name}`:v=E.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let R=v.slice(7);E.value?u={type:R,value:E.value.value}:u={type:R};continue}}c.push(E)}if(u){n.needsCreateComponent=!0,n.needsIsland=!0;let E=[e.objectProperty(e.identifier("component"),t),e.objectProperty(e.identifier("mode"),e.stringLiteral(u.type))];u.value&&E.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(u.value)));for(let v of c){if(e.isJSXSpreadAttribute(v))continue;let R=y(v),z=N(v.value);E.push(e.objectProperty(e.identifier(R),z))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(E),e.arrayExpression([])])}n.needsCreateComponent=!0;let p=[],d=!1,l=null;for(let E of c){if(e.isJSXSpreadAttribute(E)){d=!0,l=E.argument;continue}let v=y(E);if(v==="key")continue;if($(v)){let z=F(v),G=E.value.expression;z==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(G),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(G),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):z==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(G),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(G),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||C(v,n))){let{eventName:z,modifiers:G}=_(v),We=N(E.value),He=U(We,G);p.push(e.objectProperty(e.identifier(z),He));continue}let R=N(E.value);p.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(v)?e.identifier(v):e.stringLiteral(v),R))}let g=n._pendingSetup?n._pendingSetup.length:0,h=[],f=!1;for(let E of s)if(e.isJSXText(E)){let v=W(E.value);v&&h.push(e.stringLiteral(v))}else if(e.isJSXExpressionContainer(E))e.isJSXEmptyExpression(E.expression)||(f=!0,h.push(E.expression));else if(e.isJSXElement(E)){let v=E.openingElement.name.name;v!=="For"&&v!=="Show"&&v!=="Switch"&&(f=!0),h.push(V({node:E},n))}else e.isJSXFragment(E)&&(f=!0,h.push(Z({node:E},n)));let w;d?p.length>0?w=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),l,e.objectExpression(p)]):w=l:p.length>0?w=e.objectExpression(p):w=e.nullLiteral();let I=e.arrayExpression(h);if(f){let E=n._pendingSetup?n._pendingSetup.splice(g):[];I=e.arrowFunctionExpression([],E.length>0?e.blockStatement([...E,e.returnStatement(I)]):I)}return e.callExpression(e.identifier("_$createComponent"),[t,w,I])}function Pe(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,a=null,s=null;for(let p of o)if(e.isJSXAttribute(p)){let d=y(p);d==="each"?a=N(p.value):d==="key"&&(s=N(p.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,ae(i,n);let u=null;for(let p of t)if(e.isJSXExpressionContainer(p)&&!e.isJSXEmptyExpression(p.expression)){u=p.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,ae(i,n);n.needsMapArray=!0;let c=[a,u];return s&&c.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),c)}function Ne(i,n){let{node:r}=i,o=r.openingElement.attributes,t=r.children,a=null,s=null;for(let h of o)if(e.isJSXAttribute(h)){let f=y(h);f==="when"?a=N(h.value):f==="fallback"&&(s=N(h.value))}if(!a)throw i.buildCodeFrameError('<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let u=null;for(let h of t)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){u=h.expression;break}if(!u){let h=[];for(let f of t)if(e.isJSXText(f)){let w=W(f.value);w&&h.push(e.stringLiteral(w))}else e.isJSXElement(f)&&h.push(V({node:f},n));h.length===1?u=h[0]:h.length>1?u=e.arrayExpression(h):u=e.nullLiteral()}let c=ye(a,n),p=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),d=e.isFunction(u),l=d?e.callExpression(u,[e.cloneNode(p)]):u,g=s||e.nullLiteral();if(M(c,n.signalNames,n.importedIdentifiers)){let h=n.nextMemoId();n.needsMemo=!0;let f=d?c:e.unaryExpression("!",e.unaryExpression("!",c));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),c=e.callExpression(e.identifier(h),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(p,c)]),e.returnStatement(e.conditionalExpression(e.cloneNode(p),l,g))]))}function ye(i,n){return e.isCallExpression(i)?i:e.isArrowFunctionExpression(i)&&e.isExpression(i.body)?i.body:e.isIdentifier(i)&&(n.signalNames&&D(i.name,n.signalNames)||n.importedIdentifiers&&n.importedIdentifiers.has(i.name))?e.callExpression(i,[]):i}function Je(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let t=W(o.value);t&&r.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(V({node:o},n)):e.isJSXFragment(o)&&r.push(Z({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Te(i,n){let{node:r}=i,o=k(r.openingElement.name.name,n),t=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(o||!k("Match",n));if(!r.children.some(t)&&!S(r.openingElement.name.name,n))return be(i,n);let a=f=>{let w=`<Switch> ${f}. The compiler needs to read its arms statically. Write them out: <Switch fallback={...}><Match when={a}>\u2026</Match><Match when={b}>\u2026</Match></Switch>`;throw i.buildCodeFrameError?i.buildCodeFrameError(w):new Error(`[what-compiler] ${w}`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),y(f)==="fallback"&&(s=N(f.value));let u=[];for(let f of r.children){if(e.isJSXText(f)){W(f.value)&&a("cannot mix text with its <Match> arms");continue}if(e.isJSXExpressionContainer(f)){if(e.isJSXEmptyExpression(f.expression))continue;a("cannot read its arms from an expression child")}t(f)||a("cannot mix other elements with its <Match> arms"),u.push(f)}u.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let c=[];for(let f of u){let w=null;for(let R of f.openingElement.attributes)e.isJSXAttribute(R)&&y(R)==="when"&&(w=N(R.value));w||a('has a <Match> with no "when" prop');let I=n._pendingSetup.length,E=Je(f.children,n),v=n._pendingSetup.splice(I);v.length>0&&(E=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...v,e.returnStatement(E)])),[])),c.push([ye(w,n),E])}let p=c.some(([f])=>M(f,n.signalNames,n.importedIdentifiers)),d=s||e.nullLiteral();if(!p){let f=d;for(let w=c.length-1;w>=0;w--)f=e.conditionalExpression(c[w][0],c[w][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=c.length-1;f>=0;f--)l=e.conditionalExpression(c[f][0],e.numericLiteral(f),l);let g=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let h=d;for(let f=c.length-1;f>=0;f--)h=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(g),[]),e.numericLiteral(f)),c[f][1],h);return e.arrowFunctionExpression([],h)}function Oe(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=me(i,n);if(o){n.needsMapArray=!0;let a=e.isCallExpression(o)&&e.isIdentifier(o.callee)&&(o.callee.name==="_$mapArray"||o.callee.name==="mapArray");if(e.isArrowFunctionExpression(o)&&e.isExpression(o.body))return o.body=B(o.body,r,n),o;if(a)return o;let u=B(o,r,n);return e.arrowFunctionExpression([],u)}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):M(i,n.signalNames,n.importedIdentifiers)?(i=B(i,r,n),e.arrowFunctionExpression([],i)):i}function Z(i,n){let{node:r}=i,o=r.children,t=[];for(let a of o)if(e.isJSXText(a)){let s=W(a.value);s&&t.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||t.push(Oe(a.expression,n)):e.isJSXElement(a)?t.push(V({node:a},n)):e.isJSXFragment(a)&&t.push(Z({node:a},n));return t.length===1?t[0]:e.arrayExpression(t)}function Se(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 we(i,n,r){let o=i.scope,t=n._signalNamesCache;t||(t=n._signalNamesCache=new WeakMap);let a=t.get(o);a||(a=Q(i),t.set(o,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),u=n._pendingSetup;if(n._pendingSetup=[],u.length>0){let c=i,p=!1;for(;c&&!c.isStatement();)(c.isArrowFunctionExpression()||c.isFunctionExpression())&&(p=!0),c=c.parentPath;c&&c.isStatement()&&(c.listKey==="body"||c.listKey==="consequent")&&Array.isArray(c.container)&&!p?(c.insertBefore(u),i.replaceWith(s)):(u.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(u)),[])))}else i.replaceWith(s)}function Xe(i){let n=i.parentPath;if(n?.isVariableDeclarator()&&e.isIdentifier(n.node.id))return n.node.id.name;if(n?.isAssignmentExpression()&&e.isIdentifier(n.node.left))return n.node.left.name;if(n?.isExportDefaultDeclaration())return"default";if(n?.isObjectProperty()&&!n.node.computed){if(e.isIdentifier(n.node.key))return n.node.key.name;if(e.isStringLiteral(n.node.key))return n.node.key.value}return null}function je(i,n){let r=i.node.callee;return e.isIdentifier(r)?n.serverActionBindings.has(r.name):e.isMemberExpression(r)&&!r.computed&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"action"})&&n.serverActionNamespaces.has(r.object.name)}function De(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 ve(i,n,r,o,t){let a=i.node.loc?.start||{line:0,column:0},s=`${t}:${a.line}:${a.column+1}`,u=`${t}#${o}`,c=n.serverActionIds.get(r);if(c)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${c.bindingName}" at ${c.source}; conflicts with "${o}" at ${s}.`);let p={id:r,key:u,bindingName:o,filename:t,source:s,loc:a};if(n.serverActionIds.set(r,p),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(p)}catch(d){throw i.buildCodeFrameError(d instanceof Error?d.message:String(d))}}function Re(i,n){if(!je(i,n))return;let r=Xe(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],t=De(o);if(t.property){t.value!==null&&ve(i,n,t.value,r,n.serverActionFilename);return}let a=`wa1_${Ze(`${n.serverActionFilename}#${r}`)}`;ve(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));o?e.isObjectExpression(o)?o.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([s]))}return{name:"what-jsx-transform",visitor:{Program:{enter(i,n){n.needsTemplate=!1,n.needsInsert=!1,n.needsEffect=!1,n.needsMapArray=!1,n.needsSpread=!1,n.needsSetProp=!1,n.needsMemo=!1,n.needsSetClass=!1,n.needsSetStyle=!1,n.needsSetAttr=!1,n.needsSetValue=!1,n.needsSetChecked=!1,n.needsH=!1,n.needsCreateComponent=!1,n.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=Ke(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,t=o==="what-framework"||o.startsWith("what-framework/")||o==="what-core"||o.startsWith("what-core/"),a=t||o.startsWith("./")||o.startsWith("../");for(let s of r.specifiers){let u=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(u=s.local.name),u&&((a||/^(use|create)[A-Z]/.test(u))&&n.importedIdentifiers.add(u),t?n.whatImports.add(u):o.startsWith(".")||n.foreignImports.add(u)),qe.has(o)&&(e.isImportSpecifier(s)&&e.isIdentifier(s.imported,{name:"action"})&&e.isIdentifier(s.local)?n.serverActionBindings.add(s.local.name):e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local)&&n.serverActionNamespaces.add(s.local.name))}}i.traverse({Function(r){X(r)},CallExpression(r){Re(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let t=o.callee,a="";if(e.isIdentifier(t)?a=t.name:e.isMemberExpression(t)&&e.isIdentifier(t.property)&&(a=t.property.name),_e.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let u of s.elements)e.isIdentifier(u)&&n.signalNames.add(u.name);else if(e.isObjectPattern(s))for(let u of s.properties)e.isObjectProperty(u)&&e.isIdentifier(u.value)&&n.signalNames.add(u.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 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 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(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||t.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&Ye(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let t=e.arrayExpression([...n.delegatedEvents].map(s=>e.stringLiteral(s))),a=e.functionDeclaration(e.identifier("_$delegate$"),[],e.blockStatement([e.ifStatement(e.identifier("_$delegated$"),e.returnStatement()),e.expressionStatement(e.assignmentExpression("=",e.identifier("_$delegated$"),e.booleanLiteral(!0))),e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[t]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){we(i,n,V)},JSXFragment(i,n){we(i,n,Z)}}}}function Ye(e,m,x){let C=null;for(let _ of e.node.body)if(m.isImportDeclaration(_)&&(_.source.value==="what-core"||_.source.value==="what-framework")){C=_;break}if(C){let _=new Set(C.specifiers.filter($=>m.isImportSpecifier($)).map($=>$.imported.name));for(let $ of x)_.has($.imported.name)||C.specifiers.push($)}else{let _=m.importDeclaration(x,m.stringLiteral("what-framework"));e.unshiftContainer("body",_)}}import K from"fs";import H from"path";var $e=new Set([".jsx",".tsx",".js",".ts"]),Qe=new Set(["_layout","_error","_loading","_404"]);function en(e){let m=[],x=[],C=[];function _(F,P=""){if(!K.existsSync(F))return;let L=K.readdirSync(F,{withFileTypes:!0});for(let k of L){let S=H.join(F,k.name);if(k.isDirectory()){if(k.name.match(/^\((.+)\)$/)){_(S,P);continue}if(k.name==="api"&&P===""){$(S,"/api");continue}_(S,P+"/"+ie(k.name));continue}let T=H.extname(k.name);if(!$e.has(T))continue;let A=H.basename(k.name,T);if(A==="_layout"){x.push({filePath:S,urlPrefix:P||"/"});continue}if(Qe.has(A))continue;let X=ie(A),j=A==="index"?P||"/":P+"/"+X;m.push({filePath:S,routePath:Ce(j),isDynamic:j.includes(":")||j.includes("*")})}}function $(F,P){if(!K.existsSync(F))return;let L=K.readdirSync(F,{withFileTypes:!0});for(let k of L){let S=H.join(F,k.name);if(k.isDirectory()){$(S,P+"/"+ie(k.name));continue}let T=H.extname(k.name);if(!$e.has(T))continue;let A=H.basename(k.name,T),X=ie(A),j=A==="index"?P:P+"/"+X;C.push({filePath:S,routePath:Ce(j)})}}return _(e),m.sort((F,P)=>{let L=ke(F.routePath),k=ke(P.routePath);return L-k}),{pages:m,layouts:x,apiRoutes:C}}function ie(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let x=e.match(/^\[(\w+)\]$/);return x?":"+x[1]:e.toLowerCase()}function Ce(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function ke(e){return e.includes("*")?100:e.includes(":")?10:0}function nn(e){let m=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!m)return{mode:"client"};try{let x=m[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(x)}}catch{return{mode:"client"}}}function rn(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 Ae(e,m){let{pages:x,layouts:C,apiRoutes:_}=en(e),$=[],F=[],P=new Map;C.forEach((S,T)=>{let A=`_layout${T}`,X=pe(S.filePath,m);$.push(`import ${A} from '${X}';`),P.set(S.urlPrefix,A)}),x.forEach((S,T)=>{let A=`_page${T}`,X=pe(S.filePath,m);$.push(`import ${A} from '${X}';`);let j={mode:"client"},N={hasLoader:!1,hasGetStaticPaths:!1,hasPageConfig:!1};try{let J=K.readFileSync(S.filePath,"utf-8");j=nn(J),N=rn(J)}catch{}let b=on(S.routePath,P),y={path:S.routePath,component:A,mode:j.mode||"client",layout:b||null,hasLoader:N.hasLoader};F.push(y)});let L=[];return _.forEach((S,T)=>{let A=`_api${T}`,X=pe(S.filePath,m);$.push(`import * as ${A} from '${X}';`),L.push({path:S.routePath,handlers:A})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...$,"","export const routes = [",...F.map(S=>` { path: '${S.path}', component: ${S.component}, mode: '${S.mode}'${S.layout?`, layout: ${S.layout}`:""}${S.hasLoader?", hasLoader: true":""} },`),"];","","export const apiRoutes = [",...L.map(S=>` { path: '${S.path}', handlers: ${S.handlers} },`),"];","","export const pageModes = {",...F.map(S=>` '${S.path}': '${S.mode}',`),"};"].join(`
|
|
2
|
+
`)}function pe(e,m){return"/"+H.relative(m,e).split(H.sep).join("/")}function on(e,m){let x=e.split("/").filter(Boolean);for(;x.length>0;){let C="/"+x.join("/");if(m.has(C))return m.get(C);x.pop()}return m.has("/")?m.get("/"):null}var sn=`
|
|
3
3
|
:host {
|
|
4
4
|
position: fixed;
|
|
5
5
|
inset: 0;
|
|
@@ -185,12 +185,12 @@ import re from"path";import{transformSync as Je}from"@babel/core";var Ce=new Set
|
|
|
185
185
|
white-space: pre-wrap;
|
|
186
186
|
line-height: 1.5;
|
|
187
187
|
}
|
|
188
|
-
`,
|
|
188
|
+
`,Sn=`
|
|
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>${sn}</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 Ie(e){let m=e.ws.send.bind(e.ws);e.ws.send=function(x){return x?.type==="error"&&x.err?.plugin==="vite-plugin-what"&&(x.err._isCompilerError=!0),m(x)}}var Le="virtual:what-routes",re="\0"+Le,an=/(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/,ln=/\.[cm]?[jt]sx?$/;function de(e,m){return e?Array.isArray(e)?e.some(x=>de(x,m)):e instanceof RegExp?(e.lastIndex=0,e.test(m)):typeof e=="function"?e(m):!1:!1}function cn({rolldownVersion:e,viteVersion:m}={}){let x=parseInt(String(m??""),10);return!!e||Number.isFinite(x)&&x>=8?{oxc:{jsx:"preserve"}}:{esbuild:{jsx:"preserve"}}}var ue=null;function fn(){return ue||(ue=import("vite").then(e=>e.version||"").catch(()=>"")),ue}var pn=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,un=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function dn(e={}){let{include:m=/\.[jt]sx$/,exclude:x=/node_modules/,sourceMaps:C=!0,production:_=!0,pages:$="src/pages",hot:F=!_,prodBundles:P=!0}=e,L="",k="",S=null,T=!1,A=new Map;function X(b){let y=A.get(b.id);if(y&&y.key!==b.key)throw new Error(`Duplicate server action ID "${b.id}". First declared by "${y.bindingName}" at ${y.source}; conflicts with "${b.bindingName}" at ${b.source}.`);A.set(b.id,b)}function j(b){for(let[y,J]of A)J.filename===b&&A.delete(y)}function N(b){let y=b.replace(/[?#].*$/,"");return L?Y.relative(L,y).split(Y.sep).join("/"):y}return{name:"vite-plugin-what",configResolved(b){L=b.root,k=Y.resolve(L,$),T=b.command==="serve"},configureServer(b){S=b,Ie(b),b.watcher.on("add",y=>{if(y.startsWith(k)){let J=b.moduleGraph.getModuleById(re);J&&(b.moduleGraph.invalidateModule(J),b.ws.send({type:"full-reload"}))}}),b.watcher.on("unlink",y=>{if(j(N(y)),y.startsWith(k)){let J=b.moduleGraph.getModuleById(re);J&&(b.moduleGraph.invalidateModule(J),b.ws.send({type:"full-reload"}))}})},resolveId(b){if(b===Le)return re},load(b){if(b===re)return Ae(k,L)},transform(b,y){let J=y.replace(/[?#].*$/,""),U=de(m,J),D=ln.test(J),Q=D&&an.test(b);if(x&&de(x,J)||(D&&j(N(J)),!U&&!Q))return null;try{let O=tn(b,{filename:y,sourceMaps:C,configFile:!1,babelrc:!1,plugins:[[fe,{production:_,projectRoot:L||process.cwd(),onActionId:X}]],parserOpts:{plugins:["jsx","typescript"]}});if(!O||!O.code)return null;let q=O.code;return F&&T&&!_&&mn(b,y)&&(q+=gn(y)),{code:q,map:O.map}}catch(O){throw O.plugin="vite-plugin-what",O.id||(O.id=y),O.loc===void 0&&O._loc&&(O.loc={file:y,line:O._loc.line,column:O._loc.column}),console.error(`[what] Error transforming ${y}:`,O.message),O}},handleHotUpdate({file:b,server:y,modules:J}){if(F&&m.test(b)&&!(x&&x.test(b))&&hn(b))return y.ws.send({type:"full-reload"}),[]},async config(b,{mode:y,command:J}){let U=J==="build"&&y==="production"&&P,D=cn({rolldownVersion:this?.meta?.rolldownVersion,viteVersion:await fn()});return{...U?{resolve:{conditions:["production"]}}:{},...D,optimizeDeps:{exclude:["what-framework","what-core","what-compiler","what-router"]}}}}}function mn(e,m){return!!(pn.test(e)||m.includes("/pages/")||m.includes("\\pages\\"))}function hn(e){let m=Y.basename(e,Y.extname(e));return un.test(m)}function gn(e){return`
|
|
384
384
|
|
|
385
385
|
// --- What Framework HMR Boundary ---
|
|
386
386
|
if (import.meta.hot) {
|
|
@@ -393,4 +393,4 @@ if (import.meta.hot) {
|
|
|
393
393
|
}
|
|
394
394
|
});
|
|
395
395
|
}
|
|
396
|
-
`}export{
|
|
396
|
+
`}export{dn as default,cn as jsxPreserveConfig,dn as what};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-compiler",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.8",
|
|
4
4
|
"description": "JSX compiler for What Framework - transforms JSX to optimized DOM operations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@babel/core": "^7.0.0",
|
|
52
|
-
"what-core": "^0.11.
|
|
52
|
+
"what-core": "^0.11.8"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"src",
|