what-compiler 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/babel.d.ts +78 -2
- package/dist/babel/auto-selector.min.js +94 -0
- package/dist/babel/common.min.js +2053 -0
- package/dist/babel/dev-metadata.min.js +106 -0
- package/dist/babel/dom.min.js +1669 -0
- package/dist/babel/jsx-root.min.js +13 -0
- package/dist/babel/lists.min.js +492 -0
- package/dist/babel/nesting.min.js +328 -0
- package/dist/babel/reactivity.min.js +1218 -0
- package/dist/babel/server-actions.min.js +85 -0
- package/dist/babel/ssr.min.js +496 -0
- package/dist/babel/types.min.js +9 -0
- package/dist/babel-plugin.min.js +101 -1
- package/dist/file-router.min.js +368 -12
- package/dist/framework-files.min.js +62 -0
- package/dist/hot.min.js +315 -0
- package/dist/index.min.js +13 -414
- package/dist/release.min.js +78 -0
- package/dist/runtime.min.js +9 -1
- package/dist/tables/import-changes.min.js +272 -0
- package/dist/tables/markup-rules.min.js +213 -0
- package/dist/vite-plugin.min.js +432 -399
- package/file-router.d.ts +3 -1
- package/index.d.ts +1 -1
- package/package.json +11 -2
- package/runtime.d.ts +2 -1
- package/src/babel/auto-selector.js +248 -0
- package/src/babel/common.js +3800 -0
- package/src/babel/dev-metadata.js +167 -0
- package/src/babel/dom.js +3386 -0
- package/src/babel/jsx-root.js +27 -0
- package/src/babel/lists.js +704 -0
- package/src/babel/nesting.js +260 -0
- package/src/babel/reactivity.js +1998 -0
- package/src/babel/server-actions.js +144 -0
- package/src/babel/ssr.js +870 -0
- package/src/babel/types.js +10 -0
- package/src/babel-plugin.js +185 -3598
- package/src/file-router.js +58 -38
- package/src/framework-files.js +106 -0
- package/src/hot.js +523 -0
- package/src/release.js +127 -0
- package/src/runtime.js +7 -7
- package/src/tables/import-changes.js +157 -0
- package/src/tables/markup-rules.js +388 -0
- package/src/vite-plugin.js +460 -175
- package/vite.d.ts +47 -3
- package/src/error-overlay.js +0 -428
package/dist/vite-plugin.min.js
CHANGED
|
@@ -1,414 +1,447 @@
|
|
|
1
|
-
import Y from"path";import{createRequire as An}from"node:module";import{transformSync as Ln}from"@babel/core";var sn=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),an=new Set(["once","capture","passive"]),ln=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),cn=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),se=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),fn=new Set(["toString","toLocaleString","valueOf","toJSON","toUpperCase","toLowerCase","toLocaleUpperCase","toLocaleLowerCase","trim","trimStart","trimEnd","toFixed","toPrecision","toExponential","toISOString","toUTCString","toDateString","toTimeString","toLocaleDateString","toLocaleTimeString","slice","reverse","sort","flat","concat","join"]),Pe=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),un=new Set(["For","Show","Switch","Match"]),pn=new Set(["what-framework/server","what-server","what-server/actions"]);function Ne(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function dn(e){let m=0xcbf29ce484222325n;for(let d=0;d<e.length;d++)m^=BigInt(e.charCodeAt(d)),m=BigInt.asUintN(64,m*0x100000001b3n);return m.toString(36)}function mn(e,m){let d=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),y=String(m||"").replace(/\\/g,"/").replace(/\/+$/,"");return y&&d.startsWith(`${y}/`)?d.slice(y.length+1):d.replace(/^\.\//,"")}function H(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let m=e.split(/\r\n|\n|\r/),d=-1;for(let E=0;E<m.length;E++)/[^ \t]/.test(m[E])&&(d=E);if(d===-1)return"";let y="";for(let E=0;E<m.length;E++){let b=m[E].replace(/\t/g," "),w=E===0,C=E===m.length-1;w||(b=b.replace(/^ +/,"")),C||(b=b.replace(/ +$/,"")),b&&(E!==d&&(b+=" "),y+=b)}return y}function ge({types:e}){let m=new Set,d=new Set;function y(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(o=>o!=="").length===0)}function E(i){let n=i.includes("|")?"|":"__",r=i.split(n),t=r[0],o=r.slice(1).filter(a=>sn.has(a));return{eventName:t,modifiers:o}}function b(i){return i.startsWith("bind:")}function w(i){return i.slice(5)}function C(i){return/^[A-Z]/.test(i)}function D(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let t=i?.node;if(t&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(t,r);let o=t?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${o?`${a}:${o.line}:${o.column+1}`:a})`)}function A(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&C(n.name)}function _(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function J(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function P(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function W(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:V(n.node.callee,n.scope)}function V(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?B(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?B(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function B(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let t=i.path.node;if(!n(t))return!1;if(r!==null){let a=t.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let o=i.path.parent;return e.isImportDeclaration(o)&&Ne(o.source.value)}function k(i){return e.isJSXMemberExpression(i)?e.memberExpression(k(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function L(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],t=-1;for(let p=0;p<r.properties.length;p++){let x=r.properties[p];if(e.isRestElement(x))return;if(e.isObjectProperty(x)&&!x.computed&&e.isIdentifier(x.key,{name:"children"})){if(t!==-1||!e.isIdentifier(x.value))return;t=p}}if(t===-1)return;let o=i.scope.getBinding(r.properties[t].value.name);if(!o||o.constantViolations.length>0||o.referencePaths.length===0||!o.referencePaths.every(p=>{let x=p.parentPath;if(!x||!x.isJSXExpressionContainer())return!1;let h=x.parentPath;if(!h||!h.isJSXElement()||!A(h.node))return!1;let l=h.node.openingElement.name;return!(e.isJSXIdentifier(l)&&un.has(l.name))}))return;let s=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(s.typeAnnotation=r.typeAnnotation),n[0]=s;let c=r.properties.filter((p,x)=>x!==t);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let p=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(p,e.cloneNode(s))])),i.node._whatMovedProps=p}for(let p of o.referencePaths)p.replaceWith(e.memberExpression(e.cloneNode(s),e.identifier("children")));i.scope.crawl()}function R(i){return ln.has(String(i).toLowerCase())}function F(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}let Q=new Map([["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"],["acceptCharset","accept-charset"]]);function U(i){return Q.get(i)||i}function te(i,n){let r=U(X(i[n]));for(let t=n+1;t<i.length;t+=1){let o=i[t];if(!e.isJSXSpreadAttribute(o)&&U(X(o))===r)return!0}return!1}function X(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 O(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function ee(i){return!!i&&i.length>2&&/^on/i.test(i)}function ce(i,n){if(n.length===0)return i;let r=i;for(let t of n)switch(t){case"preventDefault":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("preventDefault")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"stopPropagation":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.expressionStatement(e.callExpression(e.memberExpression(e.identifier("e"),e.identifier("stopPropagation")),[])),e.expressionStatement(e.callExpression(r,[e.identifier("e")]))]));break;case"self":r=e.arrowFunctionExpression([e.identifier("e")],e.blockStatement([e.ifStatement(e.binaryExpression("===",e.memberExpression(e.identifier("e"),e.identifier("target")),e.memberExpression(e.identifier("e"),e.identifier("currentTarget"))),e.expressionStatement(e.callExpression(r,[e.identifier("e")])))]));break;case"once":case"capture":case"passive":break}return r}function q(i,n){return n.has(i)}function We(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function t(s){let c=s.init;if(!c||!e.isCallExpression(c))return;let p=c.callee,x="";if(e.isIdentifier(p)?x=p.name:e.isMemberExpression(p)&&e.isIdentifier(p.property)&&(x=p.property.name),Pe.has(x)){let h=s.id;if(e.isIdentifier(h))n.add(h.name);else if(e.isArrayPattern(h))for(let l of h.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(h))for(let l of h.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function o(s){if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)?(n.add(c.value.name),r.add(c.value.name)):e.isRestElement(c)&&e.isIdentifier(c.argument)&&(n.add(c.argument.name),r.add(c.argument.name))}let a=i.scope;for(;a;){for(let c of Object.values(a.bindings))c.path.isVariableDeclarator()&&t(c.path.node);let s=a.path&&a.path.node;if(s){if(s.params)for(let c of s.params)o(c);s._whatMovedProps&&o(s._whatMovedProps)}a=a.parent}return n}function Ve(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&fn.has(i.callee.property.name)}function be(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?se.has(n.object.name):e.isIdentifier(n)?se.has(n.name):!1}function ye(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)||be(i))return!1;if(i.arguments.some(t=>j(t,n,r)))return!0}return!1}function j(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&q(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!se.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&q(i.callee.object.name,n)?!0:be(i)?i.arguments.some(t=>j(t,n,r)):i.arguments.length===0&&!Ve(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(t=>j(t,n,r)):j(i.callee,n,r)||i.arguments.some(t=>j(t,n,r)):e.isIdentifier(i)?q(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?j(i.object,n,r):e.isConditionalExpression(i)?j(i.test,n,r)||j(i.consequent,n,r)||j(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?j(i.left,n,r)||j(i.right,n,r):e.isUnaryExpression(i)?j(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(t=>j(t,n,r)):e.isObjectExpression(i)?i.properties.some(t=>e.isObjectProperty(t)&&j(t.value,n,r)):e.isArrayExpression(i)?i.elements.some(t=>t&&j(t,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function G(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":G(i.left,n);break;case"RestElement":G(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)G(r,n);break;case"ObjectPattern":for(let r of i.properties)G(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function He(i){let n=new Set;for(let t=1;t<i.params.length;t++)G(i.params[t],n);let r=t=>{if(!(!t||typeof t!="object")){if(Array.isArray(t)){t.forEach(r);return}switch(t.type){case"VariableDeclaration":for(let o of t.declarations)G(o.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":t.id&&n.add(t.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":G(t.param,n),r(t.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(t.init),r(t.left),r(t.body);return;default:break}for(let o of Object.keys(t)){if(o==="loc"||o==="start"||o==="end"||o==="type"||o==="leadingComments"||o==="trailingComments"||o==="innerComments")continue;let a=t[o];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let t of G(i.params[0],new Set))n.delete(t);return n}function Be(i,n){if(n.size===0)return null;let r=null,t=o=>{if(!(r||!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(t);return}if(o.type==="Identifier"){n.has(o.name)&&(r=o.name);return}for(let a of Object.keys(o)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||o.type==="MemberExpression"&&a==="property"&&!o.computed||(o.type==="ObjectProperty"||o.type==="ObjectMethod")&&a==="key"&&!o.computed)continue;let s=o[a];s&&typeof s=="object"&&t(s)}}};return t(i),r}function Se(i,n){let r=i,t=!1;if(e.isArrowFunctionExpression(i)&&i.params.length===0&&(r=i.body,t=!0),e.isConditionalExpression(r)){let a=oe(r.consequent,n),s=oe(r.alternate,n);if(a||s){let c=e.conditionalExpression(r.test,a||r.consequent,s||r.alternate);return t?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=oe(r.right,n);if(a){let s=e.logicalExpression(r.operator,r.left,a);return t?e.arrowFunctionExpression([],s):s}return null}return oe(r,n)}function oe(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 t=null;if(e.isArrowFunctionExpression(r)){if(e.isExpression(r.body))t=r.body;else if(e.isBlockStatement(r.body)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}}else if(e.isFunctionExpression(r)){let g=r.body.body.find(f=>e.isReturnStatement(f));g&&(t=g.argument)}if(!t||!e.isJSXElement(t))return null;let o=t.openingElement.attributes,a=null;for(let g of o)if(e.isJSXAttribute(g)&&X(g)==="key"){a=g;break}if(!a)return null;let s=F(a.value);if(!s)return null;let c=He(r);if(Be(s,c)){let g=e.isIdentifier(s)&&r.params[1]&&e.isIdentifier(r.params[1],{name:s.name});return null}t.openingElement.attributes=o.filter(g=>g!==a);let x=i.callee.object,h=e.arrowFunctionExpression([],x),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),u=e.arrowFunctionExpression([l],e.cloneNode(s,!0));return e.callExpression(e.identifier("_$mapArray"),[h,r,e.objectExpression([e.objectProperty(e.identifier("key"),u),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function fe(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(A(i))return!1;for(let r of n.attributes){if(e.isJSXSpreadAttribute(r))return!1;let t=r.value;if(e.isJSXExpressionContainer(t))return!1}return i.children.every(fe)}return!1}function we(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function ue(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let t=H(r.value);t&&n.push({kind:"text",text:t});continue}if(e.isJSXFragment(r)){ue(r,n);continue}if(e.isJSXExpressionContainer(r)){e.isJSXEmptyExpression(r.expression)||n.push({kind:"expression",child:r});continue}e.isJSXElement(r)&&n.push({kind:"element",child:r})}return n}function pe(i){if(e.isJSXText(i)){let s=H(i.value);return s?ve(s):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(A(i))return"";let t=`<${r}`,o=n.attributes.findIndex(s=>e.isJSXSpreadAttribute(s));for(let[s,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||o!==-1&&s>o||te(n.attributes,s))continue;let p=X(c);if(p==="key"||ee(p)||p.startsWith("bind:")||p.includes("|"))continue;let x=U(p);if(!c.value)t+=` ${x}`;else if(e.isStringLiteral(c.value))t+=` ${x}="${Ue(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&R(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of i.children)if(e.isJSXText(s)){let c=H(s.value);c&&(t+=ve(c))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)?A(s)?t+="<!--$-->":t+=pe(s):e.isJSXFragment(s)&&(t+="<!--$-->".repeat(ue(s).length));return t+=`</${r}>`,t}function ve(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Ue(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function K(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name;if(!_(o,n)){if(o==="For")return qe(i,n);if(o==="Show")return Ke(i,n)}if(o==="Switch"&&(!_(o,n)||P(r)))return Qe(i,n);if(A(r))return Ce(i,n);let a=t.attributes,s=r.children,c=s.every(fe),p=a.every(f=>!we(f)),x=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let I=X(f);return!I?.startsWith("on")&&!I?.startsWith("bind:")});if(c&&p&&x){let f=pe(r);if(f){let I=Le(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(I),[])}}let h=pe(r);if(!h){let f=r.loc,I=n.filename||n.file?.opts?.filename||"<unknown>",S=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${o}> at ${I}${S}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,de(i,n)}let l=Le(n,h);n.needsTemplate=!0;let u=n.nextVarId(),g=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier(l),[]))])];return _e(g,u,a,n,o),ke(g,u,s,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...g),e.identifier(u)}function de(i,n){let{node:r}=i,t=r.openingElement,o=t.name.name,a=t.attributes,s=r.children,c=[];for(let h of a){if(e.isJSXSpreadAttribute(h))continue;let l=X(h),u=F(h.value),g=U(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(g)?e.identifier(g):e.stringLiteral(g),u))}let p=[];for(let h of s)if(e.isJSXText(h)){let l=H(h.value);l&&p.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(h)?e.isJSXEmptyExpression(h.expression)||p.push(h.expression):e.isJSXElement(h)?p.push(K({node:h},n)):e.isJSXFragment(h)&&p.push(ne({node:h},n));let x=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(o),x,...p])}let Ge=new Set(["input","textarea","select","option"]);function _e(i,n,r,t,o){function a(x,h){return x==="class"?(t.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),h])):x==="style"?(t.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),h])):x==="value"&&o&&Ge.has(o)?(t.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),h])):x==="checked"&&o==="input"?(t.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),h])):x.startsWith("data-")||x.startsWith("aria-")?(t.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(x),h])):(t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(x),h]))}let s=!1;function c(){s||(s=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let p=!1;for(let[x,h]of r.entries()){if(e.isJSXSpreadAttribute(h)){p=!0,t.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),h.argument])));continue}if(te(r,x))continue;let l=X(h);if(l!=="key"){if(l==="ref"){let u=F(h.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",u),e.stringLiteral("function")),e.callExpression(e.cloneNode(u),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(u),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!y(l,t)){let u=l.slice(2).toLowerCase(),g=F(h.value);cn.has(u)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(u),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${u}`)),g)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(u),g])));continue}if(l.startsWith("on")&&(l.includes("|")||y(l,t))){let{eventName:u,modifiers:g}=E(l),f=F(h.value),I=ce(f,g),S=u.slice(2).toLowerCase(),v=g.filter(N=>an.has(N)),M=[e.stringLiteral(S),I];if(v.length>0){let N=v.map($=>e.objectProperty(e.identifier($),e.booleanLiteral(!0)));M.push(e.objectExpression(N))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),M)));continue}if(b(l)){let u=w(l),g=h.value.expression;t.needsEffect=!0,u==="value"?(i.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier("value")),e.callExpression(e.cloneNode(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):u==="checked"&&(t.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(g),[])))]))),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(g),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(h.value)){let u=h.value.expression,g=U(l);if(j(u,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let f=t.signalNames&&t.signalNames.fromDestructuredProps,I=e.isIdentifier(u)&&!(f&&f.has(u.name))&&q(u.name,t.signalNames)?e.callExpression(u,[]):u,S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(g,I))]);ye(u,t.signalNames,t.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: effect wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(S))}else i.push(e.expressionStatement(a(g,u)));continue}p&&i.push(e.expressionStatement(a(U(l),F(h.value))))}}}function me(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(me);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"&&me(r))return!0}return!1}function ze(i){let n=i.parent;return n?e.isLogicalExpression(n)?i.key==="right":e.isConditionalExpression(n)?i.key==="consequent"||i.key==="alternate":e.isOptionalCallExpression(n)||e.isOptionalMemberExpression(n)?i.key!=="callee"&&i.key!=="object":!1:!1}function Z(i,n,r){let t=null,o=!1;if(e.isConditionalExpression(i))t=i.test,o=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))t=i.left;else return i;if(!j(t,r.signalNames,r.importedIdentifiers)||!(o?[i.consequent,i.alternate]:[i.right]).some(me))return i;let s=r.nextMemoId();r.needsMemo=!0;let c=o?e.unaryExpression("!",e.unaryExpression("!",t)):t;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let p=e.callExpression(e.identifier(s),[]);return o?e.conditionalExpression(p,i.consequent,i.alternate):e.logicalExpression(i.operator,p,i.right)}function ke(i,n,r,t,o){let a=[],s=0;for(let l of r){if(e.isJSXText(l)){H(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 u=l.openingElement.name.name;if(A(l)||u==="For"||u==="Show")a.push({type:"component",child:l,childIndex:s}),s++;else{let g=l.openingElement.attributes.some(we)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&X(f)?.startsWith("on"))||!l.children.every(fe);a.push({type:"static",child:l,childIndex:s,hasAnythingDynamic:g}),s++}continue}if(e.isJSXFragment(l))for(let u of ue(l))u.kind==="text"?a.push({type:"fragmentText",text:u.text,childIndex:s}):u.kind==="expression"?a.push({type:"expression",child:u.child,childIndex:s}):a.push({type:"component",child:u.child,childIndex:s}),s++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),p=c.length>=2,x=new Map;if(p){let l=null,u=0;for(let g of c){let f=g.childIndex,I=o.nextVarId();x.set(f,I);let S;if(l===null)S=he(n,f);else{S=e.identifier(l);for(let v=u;v<f;v++)S=e.memberExpression(S,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(I),S)])),l=I,u=f}}function h(l){return x.has(l)?e.identifier(x.get(l)):he(n,l)}for(let l of a){if(l.type==="expression"){let u=l.child.expression,g=h(l.childIndex);o.needsInsert=!0;let f=Se(u,o);if(f){o.needsMapArray=!0;let S=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),v=e.isArrowFunctionExpression(f);v&&e.isExpression(f.body)?f.body=Z(f.body,i,o):!S&&!v&&(f=Z(f,i,o));let M=S||v?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),M,g])));continue}if(e.isCallExpression(u)&&e.isIdentifier(u.callee)&&(u.callee.name==="mapArray"||u.callee.name==="_$mapArray")){o.needsMapArray=!0,u.callee.name==="mapArray"&&(u.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(j(u,o.signalNames,o.importedIdentifiers)){u=Z(u,i,o);let S=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],u),g]);ye(u,o.signalNames,o.importedIdentifiers)&&e.addComment(S,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),i.push(e.expressionStatement(S))}else i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(l.type==="component"){let u=K({node:l.child},o),g=h(l.childIndex);o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),u,g])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let u;x.has(l.childIndex)?u=x.get(l.childIndex):(u=o.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),he(n,l.childIndex))]))),_e(i,u,l.child.openingElement.attributes,o,l.child.openingElement.name.name),ke(i,u,l.child.children,l.child,o);continue}if(l.type==="fragmentText"){o.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),h(l.childIndex)])));continue}}}function he(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 t=0;t<n;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function Ce(i,n){let{node:r}=i,t=r.openingElement,o=k(t.name),a=t.attributes,s=r.children,c=null,p=[];for(let S of a){if(e.isJSXAttribute(S)){let v;if(e.isJSXNamespacedName(S.name)?v=`${S.name.namespace.name}:${S.name.name.name}`:v=S.name.name,v&&typeof v=="string"&&v.startsWith("client:")){let M=v.slice(7);S.value?c={type:M,value:S.value.value}:c={type:M};continue}}p.push(S)}function x(){let S=n._pendingSetup?n._pendingSetup.length:0,v=[],M=!1;for(let $ of s)if(e.isJSXText($)){let T=H($.value);T&&v.push(e.stringLiteral(T))}else if(e.isJSXExpressionContainer($))e.isJSXEmptyExpression($.expression)||(M=!0,v.push(Ae($.expression,n)));else if(e.isJSXElement($)){let T=$.openingElement.name.name;T!=="For"&&T!=="Show"&&T!=="Switch"&&(M=!0),v.push(K({node:$},n))}else e.isJSXFragment($)&&(M=!0,v.push(ne({node:$},n)));let N=e.arrayExpression(v);if(M){let $=n._pendingSetup?n._pendingSetup.splice(S):[];N=e.arrowFunctionExpression([],$.length>0?e.blockStatement([...$,e.returnStatement(N)]):N)}return N}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let S=[e.objectProperty(e.identifier("component"),o),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&S.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let v=[],M=[],N=()=>{M.length>0&&(v.push(e.objectExpression(M)),M=[])};for(let T of p){if(e.isJSXSpreadAttribute(T)){N(),v.push(T.argument);continue}let ie=X(T);if(ie==="key")continue;let on=F(T.value);M.push(e.objectProperty(O(ie),on))}let $;return v.length===0?$=e.objectExpression([...M,...S]):(N(),$=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...v,e.objectExpression(S)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),$,x()])}let h=W(i);h?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],u=[],g=()=>{u.length>0&&(l.push(e.objectExpression(u)),u=[])};for(let S of p){if(e.isJSXSpreadAttribute(S)){g(),l.push(S.argument);continue}let v=X(S);if(v==="key")continue;if(b(v)){let N=w(v),$=S.value.expression;N==="value"?(u.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):N==="checked"&&(u.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode($),[]))),u.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode($),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(v.startsWith("on")&&(v.includes("|")||y(v,n))){let{eventName:N,modifiers:$}=E(v),T=F(S.value),ie=ce(T,$);u.push(e.objectProperty(e.identifier(N),ie));continue}let M=F(S.value);u.push(e.objectProperty(O(v),M))}g();let f;l.length===0?f=e.nullLiteral():l.length===1&&e.isObjectExpression(l[0])?f=l[0]:f=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...l]);let I=x();return e.callExpression(e.identifier(h?"_$componentVNode":"_$createComponent"),[o,f,I])}function qe(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null,c=null;for(let $ of t)if(e.isJSXAttribute($)){let T=X($);T==="each"?a=F($.value):T==="key"?s=F($.value):T==="fallback"&&(c=F($.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,de(i,n);let p=null;for(let $ of o)if(e.isJSXExpressionContainer($)&&!e.isJSXEmptyExpression($.expression)){p=$.expression;break}if(!p)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,de(i,n);n.needsMapArray=!0;let x=$=>{let T=[$,p];return s&&T.push(e.objectExpression([e.objectProperty(e.identifier("key"),s)])),e.callExpression(e.identifier("_$mapArray"),T)};if(!c)return x(a);n._pendingSetup||(n._pendingSetup=[]);let h=n.nextForIndex(),l=`_each$${h}`,u=`_for$${h}`,g=`_fb$${h}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let I=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),S=e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",e.identifier(l)),e.stringLiteral("function")),e.callExpression(e.identifier(l),[]),e.identifier(l));n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),a)]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(f),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(I,S)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(I),e.memberExpression(e.cloneNode(I),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),x(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let v=e.identifier("_parent"),M=e.identifier("_marker"),N=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([v,M],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(N,e.callExpression(e.identifier(u),[e.cloneNode(v),e.cloneNode(M)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(v),e.arrayExpression([e.identifier(g)]),e.cloneNode(M)])),e.returnStatement(e.cloneNode(N))])),e.identifier(u)])}function Ke(i,n){let{node:r}=i,t=r.openingElement.attributes,o=r.children,a=null,s=null;for(let g of t)if(e.isJSXAttribute(g)){let f=X(g);f==="when"?a=F(g.value):f==="fallback"&&(s=F(g.value))}if(!a)throw D(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let g of o)if(e.isJSXExpressionContainer(g)&&!e.isJSXEmptyExpression(g.expression)){c=g.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let g=n._pendingSetup.length,f=[];for(let S of o)if(e.isJSXText(S)){let v=H(S.value);v&&f.push(e.stringLiteral(v))}else e.isJSXElement(S)&&f.push(K({node:S},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let I=n._pendingSetup.splice(g);I.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...I,e.returnStatement(c)])),[]))}let p=$e(a,n),x=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),h=e.isFunction(c),l=h?e.callExpression(c,[e.cloneNode(x)]):c,u=s||e.nullLiteral();if(j(p,n.signalNames,n.importedIdentifiers)){let g=n.nextMemoId();n.needsMemo=!0;let f=h?p:e.unaryExpression("!",e.unaryExpression("!",p));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),p=e.callExpression(e.identifier(g),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(x,p)]),e.returnStatement(e.conditionalExpression(e.cloneNode(x),l,u))]))}function $e(i,n){if(e.isCallExpression(i))return i;if(e.isArrowFunctionExpression(i)&&e.isExpression(i.body))return i.body;let r=n.signalNames&&n.signalNames.fromDestructuredProps,t=a=>r&&r.has(a)||n.importedIdentifiers&&n.importedIdentifiers.has(a);if(e.isIdentifier(i))return t(i.name)?Ie(i):n.signalNames&&q(i.name,n.signalNames)?e.callExpression(i,[]):i;let o=Ze(i);return o&&t(o.name)?Ie(i):i}function Ze(i){if(!e.isMemberExpression(i))return null;let n=i;for(;e.isMemberExpression(n);){if(n.computed||!e.isIdentifier(n.property))return null;n=n.object}return e.isIdentifier(n)?n:null}function Ie(i){return e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",i),e.stringLiteral("function")),e.callExpression(e.cloneNode(i),[]),e.cloneNode(i))}function Ye(i,n){let r=[];for(let t of i)if(e.isJSXText(t)){let o=H(t.value);o&&r.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||r.push(t.expression):e.isJSXElement(t)?r.push(K({node:t},n)):e.isJSXFragment(t)&&r.push(ne({node:t},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Qe(i,n){let{node:r}=i,t=_(r.openingElement.name.name,n),o=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(t||!_("Match",n));if(!r.children.some(o)&&!J(r.openingElement.name.name,n))return Ce(i,n);let a=f=>{throw D(i,n,`<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>`)},s=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),X(f)==="fallback"&&(s=F(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){H(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")}o(f)||a("cannot mix other elements with its <Match> arms"),c.push(f)}c.length===0&&a("has no <Match> arms"),n._pendingSetup||(n._pendingSetup=[]);let p=[];for(let f of c){let I=null;for(let N of f.openingElement.attributes)e.isJSXAttribute(N)&&X(N)==="when"&&(I=F(N.value));I||a('has a <Match> with no "when" prop');let S=n._pendingSetup.length,v=Ye(f.children,n),M=n._pendingSetup.splice(S);M.length>0&&(v=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...M,e.returnStatement(v)])),[])),p.push([$e(I,n),v])}let x=p.some(([f])=>j(f,n.signalNames,n.importedIdentifiers)),h=s||e.nullLiteral();if(!x){let f=h;for(let I=p.length-1;I>=0;I--)f=e.conditionalExpression(p[I][0],p[I][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=p.length-1;f>=0;f--)l=e.conditionalExpression(p[f][0],e.numericLiteral(f),l);let u=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(u),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let g=h;for(let f=p.length-1;f>=0;f--)g=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(u),[]),e.numericLiteral(f)),p[f][1],g);return e.arrowFunctionExpression([],g)}function Ae(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,t=Se(i,n);if(t){n.needsMapArray=!0;let a=e.isCallExpression(t)&&e.isIdentifier(t.callee)&&(t.callee.name==="_$mapArray"||t.callee.name==="mapArray");if(e.isArrowFunctionExpression(t)&&e.isExpression(t.body))return t.body=Z(t.body,r,n),t;if(a)return t;let c=Z(t,r,n);return e.arrowFunctionExpression([],c)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):j(i,n.signalNames,n.importedIdentifiers)?(i=Z(i,r,n),e.arrowFunctionExpression([],i)):i}function ne(i,n){let{node:r}=i,t=r.children,o=[];for(let a of t)if(e.isJSXText(a)){let s=H(a.value);s&&o.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||o.push(Ae(a.expression,n)):e.isJSXElement(a)?o.push(K({node:a},n)):e.isJSXFragment(a)&&o.push(ne({node:a},n));return o.length===1?o[0]:e.arrayExpression(o)}function Le(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 Me(i,n,r){let t=i.scope,o=n._signalNamesCache;o||(o=n._signalNamesCache=new WeakMap);let a=o.get(t);a||(a=We(i),o.set(t,a)),n.signalNames=a,n._pendingSetup=[];let s=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let p=i,x=!1,h=!1;for(;p&&!p.isStatement();)(p.isArrowFunctionExpression()||p.isFunctionExpression())&&(x=!0),ze(p)&&(h=!0),p=p.parentPath;p&&p.isStatement()&&(p.listKey==="body"||p.listKey==="consequent")&&Array.isArray(p.container)&&!x&&!h?(p.insertBefore(c),i.replaceWith(s)):(c.push(e.returnStatement(s)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(s)}function en(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 nn(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 rn(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 Fe(i,n,r,t,o){let a=i.node.loc?.start||{line:0,column:0},s=`${o}:${a.line}:${a.column+1}`,c=`${o}#${t}`,p=n.serverActionIds.get(r);if(p)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${p.bindingName}" at ${p.source}; conflicts with "${t}" at ${s}.`);let x={id:r,key:c,bindingName:t,filename:o,source:s,loc:a};if(n.serverActionIds.set(r,x),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(x)}catch(h){throw i.buildCodeFrameError(h instanceof Error?h.message:String(h))}}function tn(i,n){if(!nn(i,n))return;let r=en(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 t=i.node.arguments[1],o=rn(t);if(o.property){o.value!==null&&Fe(i,n,o.value,r,n.serverActionFilename);return}let a=`wa1_${dn(`${n.serverActionFilename}#${r}`)}`;Fe(i,n,a,r,n.serverActionFilename);let s=e.objectProperty(e.identifier("id"),e.stringLiteral(a));t?e.isObjectExpression(t)?t.properties.unshift(s):i.node.arguments[1]=e.objectExpression([s,e.spreadElement(t)]):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.needsComponentVNode=!1,n.needsFragment=!1,n.needsIsland=!1,n.needsDelegation=!1,n.delegatedEvents=new Set,n.templates=[],n.templateMap=new Map,n.templateCount=0,n._varCounter=0,n._memoCounter=0,n._listCounter=0,n._pendingSetup=[],n.nextVarId=()=>`_el$${n._varCounter++}`,n.nextMemoId=()=>`_c$${n._memoCounter++}`,n.nextForIndex=()=>n._listCounter++,n.serverActionBindings=new Set,n.serverActionNamespaces=new Set,n.serverActionIds=new Map,n.serverActionFilename=mn(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 t=r.source.value,o=Ne(t),a=o||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let c=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(c=s.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),o?n.whatImports.add(c):t.startsWith(".")||n.foreignImports.add(c)),pn.has(t)&&(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){L(r)},CallExpression(r){tn(r,n)},VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let o=t.callee,a="";if(e.isIdentifier(o)?a=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(a=o.property.name),Pe.has(a)){let s=r.node.id;if(e.isIdentifier(s))n.signalNames.add(s.name);else if(e.isArrayPattern(s))for(let c of s.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(s))for(let c of s.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let o of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(o.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(o.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.needsComponentVNode&&r.push(e.importSpecifier(e.identifier("_$componentVNode"),e.identifier("_$componentVNode"))),n.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(n.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let o=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){o=a;break}if(o){let a=new Set(o.specifiers.filter(s=>e.isImportSpecifier(s)).map(s=>s.imported.name));for(let s of r)a.has(s.imported.name)||o.specifiers.push(s)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&hn(i,e,t),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let o=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"),[o]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Me(i,n,K)},JSXFragment(i,n){Me(i,n,ne)}}}}function hn(e,m,d){let y=null;for(let E of e.node.body)if(m.isImportDeclaration(E)&&(E.source.value==="what-core"||E.source.value==="what-framework")){y=E;break}if(y){let E=new Set(y.specifiers.filter(b=>m.isImportSpecifier(b)).map(b=>b.imported.name));for(let b of d)E.has(b.imported.name)||y.specifiers.push(b)}else{let E=m.importDeclaration(d,m.stringLiteral("what-framework"));e.unshiftContainer("body",E)}}import re from"fs";import z from"path";var Oe=new Set([".jsx",".tsx",".js",".ts"]),gn=new Set(["_layout","_error","_loading","_404"]);function En(e){let m=[],d=[],y=[];function E(w,C=""){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){if(A.name.match(/^\((.+)\)$/)){E(_,C);continue}if(A.name==="api"&&C===""){b(_,"/api");continue}E(_,C+"/"+ae(A.name));continue}let J=z.extname(A.name);if(!Oe.has(J))continue;let P=z.basename(A.name,J);if(P==="_layout"){d.push({filePath:_,urlPrefix:C||"/"});continue}if(gn.has(P))continue;let W=ae(P),V=P==="index"?C||"/":C+"/"+W;m.push({filePath:_,routePath:je(V),isDynamic:V.includes(":")||V.includes("*")})}}function b(w,C){if(!re.existsSync(w))return;let D=re.readdirSync(w,{withFileTypes:!0});for(let A of D){let _=z.join(w,A.name);if(A.isDirectory()){b(_,C+"/"+ae(A.name));continue}let J=z.extname(A.name);if(!Oe.has(J))continue;let P=z.basename(A.name,J),W=ae(P),V=P==="index"?C:C+"/"+W;y.push({filePath:_,routePath:je(V)})}}return E(e),m.sort((w,C)=>{let D=Te(w.routePath),A=Te(C.routePath);return D-A}),{pages:m,layouts:d,apiRoutes:y}}function ae(e){let m=e.match(/^\[\.\.\.(\w+)\]$/);if(m)return"*"+m[1];let d=e.match(/^\[(\w+)\]$/);return d?":"+d[1]:e.toLowerCase()}function je(e){let m=e.replace(/\/+/g,"/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m||"/"}function Te(e){return e.includes("*")?100:e.includes(":")?10:0}var xn=/export\s+const\s+page\s*=\s*\{/;function bn(e,m={}){let d=xn.exec(e);if(!d)return{mode:"client"};let y=d.index+d[0].length-1;try{return{mode:"client",...JSON.parse(vn(e,y))}}catch(E){return yn(E,m.filePath),{mode:"client"}}}function yn(e,m){let d=m?` in ${m}`:"";console.warn(`[what] Ignoring unparseable \`export const page\` config${d}: ${e.message}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.panel {
|
|
27
|
-
position: fixed;
|
|
28
|
-
inset: 2rem;
|
|
29
|
-
overflow: auto;
|
|
30
|
-
background: #1a1a2e;
|
|
31
|
-
border: 1px solid #2a2a4a;
|
|
32
|
-
border-radius: 12px;
|
|
33
|
-
box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
|
|
34
|
-
color: #e0e0e0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.header {
|
|
38
|
-
display: flex;
|
|
39
|
-
align-items: center;
|
|
40
|
-
justify-content: space-between;
|
|
41
|
-
padding: 1rem 1.5rem;
|
|
42
|
-
border-bottom: 1px solid #2a2a4a;
|
|
43
|
-
background: #16163a;
|
|
44
|
-
border-radius: 12px 12px 0 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.header-left {
|
|
48
|
-
display: flex;
|
|
49
|
-
align-items: center;
|
|
50
|
-
gap: 0.75rem;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.header-right {
|
|
54
|
-
display: flex;
|
|
55
|
-
align-items: center;
|
|
56
|
-
gap: 0.5rem;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.logo {
|
|
60
|
-
width: 28px;
|
|
61
|
-
height: 28px;
|
|
62
|
-
background: linear-gradient(135deg, #2563eb, #1d4ed8);
|
|
63
|
-
border-radius: 6px;
|
|
64
|
-
display: grid;
|
|
65
|
-
place-items: center;
|
|
66
|
-
font-weight: 800;
|
|
67
|
-
font-size: 14px;
|
|
68
|
-
color: #fff;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.brand {
|
|
72
|
-
font-size: 14px;
|
|
73
|
-
font-weight: 600;
|
|
74
|
-
color: #a0a0c0;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.tag {
|
|
78
|
-
font-size: 11px;
|
|
79
|
-
padding: 2px 8px;
|
|
80
|
-
border-radius: 4px;
|
|
81
|
-
font-weight: 600;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.tag-error {
|
|
85
|
-
background: #3b1219;
|
|
86
|
-
color: #f87171;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.tag-warning {
|
|
90
|
-
background: #3b2f19;
|
|
91
|
-
color: #fbbf24;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
.close-btn, .copy-btn {
|
|
95
|
-
background: none;
|
|
96
|
-
border: 1px solid #3a3a5a;
|
|
97
|
-
color: #a0a0c0;
|
|
98
|
-
border-radius: 6px;
|
|
99
|
-
padding: 4px 12px;
|
|
100
|
-
cursor: pointer;
|
|
101
|
-
font-family: inherit;
|
|
102
|
-
font-size: 12px;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.close-btn:hover, .copy-btn:hover {
|
|
106
|
-
background: #2a2a4a;
|
|
107
|
-
color: #fff;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.copy-btn.copied {
|
|
111
|
-
border-color: #22c55e;
|
|
112
|
-
color: #22c55e;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.body {
|
|
116
|
-
padding: 1.5rem;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.error-title {
|
|
120
|
-
font-size: 16px;
|
|
121
|
-
font-weight: 700;
|
|
122
|
-
color: #f87171;
|
|
123
|
-
margin: 0 0 0.5rem;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.error-message {
|
|
127
|
-
font-size: 14px;
|
|
128
|
-
color: #e0e0e0;
|
|
129
|
-
margin: 0 0 1rem;
|
|
130
|
-
line-height: 1.6;
|
|
131
|
-
white-space: pre-wrap;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.file-path {
|
|
135
|
-
display: inline-flex;
|
|
136
|
-
align-items: center;
|
|
137
|
-
gap: 0.5rem;
|
|
138
|
-
font-size: 12px;
|
|
139
|
-
color: #818cf8;
|
|
140
|
-
margin-bottom: 1rem;
|
|
141
|
-
padding: 0.25rem 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
.code-frame {
|
|
145
|
-
background: #0d0d1a;
|
|
146
|
-
border: 1px solid #2a2a4a;
|
|
147
|
-
border-radius: 8px;
|
|
148
|
-
overflow-x: auto;
|
|
149
|
-
margin-bottom: 1rem;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
.code-line {
|
|
153
|
-
display: flex;
|
|
154
|
-
padding: 0 1rem;
|
|
155
|
-
font-size: 13px;
|
|
156
|
-
line-height: 1.7;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.code-line.highlight {
|
|
160
|
-
background: rgba(248, 113, 113, 0.1);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
.line-number {
|
|
164
|
-
color: #4a4a6a;
|
|
165
|
-
min-width: 3ch;
|
|
166
|
-
text-align: right;
|
|
167
|
-
margin-right: 1rem;
|
|
168
|
-
user-select: none;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
.line-content {
|
|
172
|
-
white-space: pre;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.tip {
|
|
176
|
-
margin-top: 1rem;
|
|
177
|
-
padding: 0.75rem 1rem;
|
|
178
|
-
background: #1a2744;
|
|
179
|
-
border: 1px solid #1e3a5f;
|
|
180
|
-
border-radius: 8px;
|
|
181
|
-
font-size: 13px;
|
|
182
|
-
color: #93c5fd;
|
|
183
|
-
line-height: 1.5;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
.tip-label {
|
|
187
|
-
font-weight: 700;
|
|
188
|
-
color: #60a5fa;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
.stack {
|
|
192
|
-
margin-top: 1rem;
|
|
193
|
-
font-size: 12px;
|
|
194
|
-
color: #6a6a8a;
|
|
195
|
-
white-space: pre-wrap;
|
|
196
|
-
line-height: 1.5;
|
|
197
|
-
}
|
|
198
|
-
`,qn=`
|
|
199
|
-
class WhatErrorOverlay extends HTMLElement {
|
|
200
|
-
constructor(err) {
|
|
201
|
-
super();
|
|
202
|
-
this.root = this.attachShadow({ mode: 'open' });
|
|
203
|
-
this.root.innerHTML = '<style>${In}</style>';
|
|
204
|
-
this._err = err;
|
|
205
|
-
this.show(err);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// --- Inlined helper: escapeHTML ---
|
|
209
|
-
_escapeHTML(str) {
|
|
210
|
-
return String(str)
|
|
211
|
-
.replace(/&/g, '&')
|
|
212
|
-
.replace(/</g, '<')
|
|
213
|
-
.replace(/>/g, '>')
|
|
214
|
-
.replace(/"/g, '"');
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// --- Inlined helper: cleanStack ---
|
|
218
|
-
_cleanStack(stack) {
|
|
219
|
-
return stack
|
|
220
|
-
.split('\\n')
|
|
221
|
-
.filter(function(line) { return line.indexOf('node_modules') === -1; })
|
|
222
|
-
.slice(0, 10)
|
|
223
|
-
.join('\\n');
|
|
1
|
+
// src/vite-plugin.js
|
|
2
|
+
import p from "path";
|
|
3
|
+
import k from "node:fs";
|
|
4
|
+
import { createRequire as x } from "node:module";
|
|
5
|
+
import * as ge from "@babel/core";
|
|
6
|
+
import { transformSync as Q } from "@babel/core";
|
|
7
|
+
import ye from "./babel-plugin.min.js";
|
|
8
|
+
import ve, { runsStatements as _e } from "./hot.min.js";
|
|
9
|
+
import { generateRoutesModule as Re, generateServerRoutesModule as Ee } from "./file-router.min.js";
|
|
10
|
+
import { IMPORT_CHANGES as se, SUBPATH_ONLY as xe } from "./tables/import-changes.min.js";
|
|
11
|
+
import { runtimeMismatch as be } from "./release.min.js";
|
|
12
|
+
import { isFrameworkFile as ae } from "./framework-files.min.js";
|
|
13
|
+
var le = "virtual:what-routes", H = "\0" + le, ce = "virtual:what-routes/server", z = "\0" + ce, Se = /(?:from\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"]|import\s*['"](?:what-framework\/server|what-server(?:\/actions)?)['"])/, q = /\.[cm]?[jt]sx?$/, De = /\.[jt]sx$/, Oe = "/* what-react: react source */";
|
|
14
|
+
function P(t, n) {
|
|
15
|
+
return t ? Array.isArray(t) ? t.some((o) => P(o, n)) : t instanceof RegExp ? (t.lastIndex = 0, t.test(n)) : typeof t == "function" ? t(n) : !1 : !1;
|
|
16
|
+
}
|
|
17
|
+
function je({ rolldownVersion: t, viteVersion: n } = {}) {
|
|
18
|
+
let o = parseInt(String(n ?? ""), 10);
|
|
19
|
+
return !!t || Number.isFinite(o) && o >= 8 ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } };
|
|
20
|
+
}
|
|
21
|
+
async function Ie(t) {
|
|
22
|
+
try {
|
|
23
|
+
return x(p.resolve(t || process.cwd(), "package.json"))("vite/package.json").version || "";
|
|
24
|
+
} catch {
|
|
25
|
+
return import("vite").then((n) => n.version || "").catch(() => "");
|
|
224
26
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return 'Make sure your vite.config includes the What compiler plugin: import what from "what-compiler/vite"';
|
|
235
|
-
}
|
|
236
|
-
if (msg.indexOf('not a function') !== -1 && msg.indexOf('signal') !== -1) {
|
|
237
|
-
return 'Signals are functions: call sig() to read, sig(value) to write. Check you are not destructuring a signal.';
|
|
238
|
-
}
|
|
239
|
-
if (msg.indexOf('hydrat') !== -1) {
|
|
240
|
-
return 'Hydration mismatches happen when SSR output differs from client render. Ensure server and client see the same initial state.';
|
|
241
|
-
}
|
|
242
|
-
// New tips for common mistakes
|
|
243
|
-
if (msg.indexOf('signal') !== -1 && msg.indexOf('without') !== -1 && msg.indexOf('call') !== -1) {
|
|
244
|
-
return 'Signals must be called to read their value. Use {count()} in JSX, not {count}. The parentheses trigger the reactive subscription.';
|
|
245
|
-
}
|
|
246
|
-
if (msg.indexOf('innerhtml') !== -1 && msg.indexOf('__html') !== -1) {
|
|
247
|
-
return 'Raw innerHTML is blocked for security. Use innerHTML={{ __html: trustedString }} or dangerouslySetInnerHTML={{ __html: trustedString }} instead.';
|
|
248
|
-
}
|
|
249
|
-
if ((msg.indexOf('innerhtml') !== -1 || msg.indexOf('xss') !== -1) && msg.indexOf('raw string') !== -1) {
|
|
250
|
-
return 'Raw innerHTML is a security risk (XSS). Wrap your HTML in an object: innerHTML={{ __html: yourString }}.';
|
|
251
|
-
}
|
|
252
|
-
if (msg.indexOf('cleanup') !== -1 && (msg.indexOf('effect') !== -1 || msg.indexOf('listener') !== -1)) {
|
|
253
|
-
return 'Effects that add event listeners or timers should return a cleanup function: effect(() => { el.addEventListener(...); return () => el.removeEventListener(...); })';
|
|
254
|
-
}
|
|
255
|
-
if (msg.indexOf('route') !== -1 && (msg.indexOf('not found') !== -1 || msg.indexOf('404') !== -1 || msg.indexOf('no match') !== -1)) {
|
|
256
|
-
return 'No route matched the current URL. Check that your route paths are correct and you have a catch-all or 404 route defined.';
|
|
257
|
-
}
|
|
258
|
-
if (msg.indexOf('key') !== -1 && (msg.indexOf('missing') !== -1 || msg.indexOf('list') !== -1 || msg.indexOf('each') !== -1)) {
|
|
259
|
-
return 'Lists need unique keys for efficient DOM updates. Add a key prop: items.map(item => <Item key={item.id} />)';
|
|
27
|
+
}
|
|
28
|
+
function Y(t, n, o) {
|
|
29
|
+
if (!p.isAbsolute(t) || !t.includes("/node_modules/") && (!n || t.startsWith(n + "/"))) return null;
|
|
30
|
+
let d = p.dirname(t), c = [], f = null;
|
|
31
|
+
for (; d !== p.dirname(d) && !d.endsWith("/node_modules"); ) {
|
|
32
|
+
let b = o.get(d);
|
|
33
|
+
if (b !== void 0) {
|
|
34
|
+
f = b;
|
|
35
|
+
break;
|
|
260
36
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
var codeFrame = '';
|
|
271
|
-
var rawFrame = err.frame || err._frame;
|
|
272
|
-
if (rawFrame) {
|
|
273
|
-
var lines = rawFrame.split('\\n');
|
|
274
|
-
var frameLines = '';
|
|
275
|
-
for (var i = 0; i < lines.length; i++) {
|
|
276
|
-
var line = lines[i];
|
|
277
|
-
var isHighlight = line.trimStart().startsWith('>');
|
|
278
|
-
var cleaned = line.replace(/^\\s*>\\s?/, ' ').replace(/^\\s{2}/, '');
|
|
279
|
-
var match = cleaned.match(/^(\\s*\\d+)\\s*\\|(.*)$/);
|
|
280
|
-
if (match) {
|
|
281
|
-
frameLines += '<div class="code-line' + (isHighlight ? ' highlight' : '') + '"><span class="line-number">' + match[1].trim() + '</span><span class="line-content">' + this._escapeHTML(match[2]) + '</span></div>';
|
|
282
|
-
} else if (cleaned.trim().startsWith('|')) {
|
|
283
|
-
frameLines += '<div class="code-line highlight"><span class="line-number"></span><span class="line-content" style="color:#f87171">' + this._escapeHTML(cleaned.replace(/^\\s*\\|/, '')) + '</span></div>';
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (frameLines) {
|
|
287
|
-
codeFrame = '<div class="code-frame">' + frameLines + '</div>';
|
|
37
|
+
c.push(d);
|
|
38
|
+
try {
|
|
39
|
+
let S = JSON.parse(k.readFileSync(p.join(d, "package.json"), "utf8"));
|
|
40
|
+
if (typeof S.name == "string") {
|
|
41
|
+
let N = [S.dependencies, S.peerDependencies].some(
|
|
42
|
+
(D) => D && (Object.hasOwn(D, "what-framework") || Object.hasOwn(D, "what-core"))
|
|
43
|
+
);
|
|
44
|
+
f = { name: S.name, declaresWhat: N };
|
|
45
|
+
break;
|
|
288
46
|
}
|
|
47
|
+
} catch {
|
|
289
48
|
}
|
|
290
|
-
|
|
291
|
-
var filePath = err.id || (err.loc && err.loc.file) || '';
|
|
292
|
-
var lineNum = (err.loc && err.loc.line != null) ? err.loc.line : '';
|
|
293
|
-
var col = (err.loc && err.loc.column != null) ? err.loc.column : '';
|
|
294
|
-
var location = filePath
|
|
295
|
-
? '<div class="file-path">' + this._escapeHTML(filePath) + (lineNum ? ':' + lineNum : '') + (col ? ':' + col : '') + '</div>'
|
|
296
|
-
: '';
|
|
297
|
-
|
|
298
|
-
var tip = this._getTip(err);
|
|
299
|
-
var tipHTML = tip ? '<div class="tip"><span class="tip-label">Tip: </span>' + this._escapeHTML(tip) + '</div>' : '';
|
|
300
|
-
|
|
301
|
-
var stack = (err.stack && !isCompilerError)
|
|
302
|
-
? '<div class="stack">' + this._escapeHTML(this._cleanStack(err.stack)) + '</div>'
|
|
303
|
-
: '';
|
|
304
|
-
|
|
305
|
-
return '<div class="backdrop"></div>'
|
|
306
|
-
+ '<div class="panel">'
|
|
307
|
-
+ '<div class="header">'
|
|
308
|
-
+ '<div class="header-left">'
|
|
309
|
-
+ '<div class="logo">W</div>'
|
|
310
|
-
+ '<span class="brand">What Framework</span>'
|
|
311
|
-
+ '<span class="tag ' + tagClass + '">' + type + '</span>'
|
|
312
|
-
+ '</div>'
|
|
313
|
-
+ '<div class="header-right">'
|
|
314
|
-
+ '<button class="copy-btn">Copy Error</button>'
|
|
315
|
-
+ '<button class="close-btn">Dismiss (Esc)</button>'
|
|
316
|
-
+ '</div>'
|
|
317
|
-
+ '</div>'
|
|
318
|
-
+ '<div class="body">'
|
|
319
|
-
+ '<h2 class="error-title">' + this._escapeHTML(err.name || 'Error') + '</h2>'
|
|
320
|
-
+ location
|
|
321
|
-
+ '<pre class="error-message">' + this._escapeHTML(err.message || String(err)) + '</pre>'
|
|
322
|
-
+ codeFrame
|
|
323
|
-
+ tipHTML
|
|
324
|
-
+ stack
|
|
325
|
-
+ '</div>'
|
|
326
|
-
+ '</div>';
|
|
49
|
+
d = p.dirname(d);
|
|
327
50
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
51
|
+
for (let b of c) o.set(b, f);
|
|
52
|
+
return f;
|
|
53
|
+
}
|
|
54
|
+
function Me(t) {
|
|
55
|
+
if (!/<\s*(?:[\p{ID_Start}$]|>)/u.test(t)) return null;
|
|
56
|
+
let n = null;
|
|
57
|
+
try {
|
|
58
|
+
Q(t, {
|
|
59
|
+
ast: !1,
|
|
60
|
+
code: !1,
|
|
61
|
+
configFile: !1,
|
|
62
|
+
babelrc: !1,
|
|
63
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
64
|
+
plugins: [() => ({
|
|
65
|
+
visitor: {
|
|
66
|
+
"JSXElement|JSXFragment"(o) {
|
|
67
|
+
n = o.node.loc?.start ?? null, o.stop();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})]
|
|
342
71
|
});
|
|
343
|
-
|
|
344
|
-
// Copy Error button
|
|
345
|
-
var copyBtn = this.root.querySelector('.copy-btn');
|
|
346
|
-
if (copyBtn) {
|
|
347
|
-
copyBtn.addEventListener('click', function() {
|
|
348
|
-
self._copyError(copyBtn);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
72
|
+
} catch {
|
|
351
73
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
btn.textContent = 'Copied!';
|
|
370
|
-
btn.classList.add('copied');
|
|
371
|
-
setTimeout(function() {
|
|
372
|
-
btn.textContent = 'Copy Error';
|
|
373
|
-
btn.classList.remove('copied');
|
|
374
|
-
}, 2000);
|
|
375
|
-
}).catch(function() {
|
|
376
|
-
// Fallback: select text
|
|
377
|
-
prompt('Copy error details:', text);
|
|
378
|
-
});
|
|
379
|
-
} else {
|
|
380
|
-
prompt('Copy error details:', text);
|
|
74
|
+
return n;
|
|
75
|
+
}
|
|
76
|
+
var V;
|
|
77
|
+
function Ve() {
|
|
78
|
+
if (V !== void 0) return V;
|
|
79
|
+
let t = x(import.meta.url), n = [
|
|
80
|
+
() => t("@jridgewell/trace-mapping"),
|
|
81
|
+
// @babel/core depends on it (through @jridgewell/remapping), reachable
|
|
82
|
+
// from there under a strict layout.
|
|
83
|
+
() => x(x(t.resolve("@babel/core")).resolve("@jridgewell/remapping"))("@jridgewell/trace-mapping")
|
|
84
|
+
];
|
|
85
|
+
V = null;
|
|
86
|
+
for (let o of n)
|
|
87
|
+
try {
|
|
88
|
+
V = o();
|
|
89
|
+
break;
|
|
90
|
+
} catch {
|
|
381
91
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
close() {
|
|
385
|
-
document.removeEventListener('keydown', this._onKey);
|
|
386
|
-
this.remove();
|
|
387
|
-
}
|
|
92
|
+
return V;
|
|
388
93
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
94
|
+
function ke(t) {
|
|
95
|
+
let n = Ve();
|
|
96
|
+
if (n === null || typeof t?.getCombinedSourcemap != "function") return;
|
|
97
|
+
let o;
|
|
98
|
+
try {
|
|
99
|
+
o = t.getCombinedSourcemap();
|
|
100
|
+
} catch {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!o || !o.mappings) return;
|
|
104
|
+
let u = new n.TraceMap(o);
|
|
105
|
+
return (d, c) => {
|
|
106
|
+
let f = n.originalPositionFor(u, { line: d, column: c });
|
|
107
|
+
return f && f.line != null ? { line: f.line, column: f.column } : null;
|
|
108
|
+
};
|
|
392
109
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
110
|
+
function Ne(t) {
|
|
111
|
+
let n = [
|
|
112
|
+
() => x(p.resolve(t, "package.json"))("@babel/plugin-transform-typescript"),
|
|
113
|
+
() => {
|
|
114
|
+
let o = x(p.resolve(t, "package.json"));
|
|
115
|
+
return x(o.resolve("@babel/preset-typescript"))("@babel/plugin-transform-typescript");
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
for (let o of n)
|
|
119
|
+
try {
|
|
120
|
+
let u = o();
|
|
121
|
+
return u.default ?? u;
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
function $e(t) {
|
|
127
|
+
return t.appType === "custom" || !!(t.build && (t.build.ssr || t.build.ssrManifest));
|
|
128
|
+
}
|
|
129
|
+
function Ae(t) {
|
|
130
|
+
return Object.assign(
|
|
131
|
+
new Error(
|
|
132
|
+
`[what-compiler] ${t} is being compiled for the server with ssr: false, so what-compiler emits its client output, which builds DOM: _$template() calls that parse their markup with document.createElement(), so this module throws "document is not defined" the first time a server renders it.
|
|
398
133
|
|
|
399
|
-
|
|
134
|
+
Remove ssr: false to compile server modules with what-compiler's server target, which what-server renders directly. Or author server views with h() from what-framework, or compile them with the automatic JSX runtime (jsxImportSource: "what-framework").
|
|
400
135
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
136
|
+
If a DOM already exists in this process on purpose (a test runner such as Vitest applies an SSR transform under \`environment: 'node'\`), set ssrGuard: false to compile server transforms for the DOM.`
|
|
137
|
+
),
|
|
138
|
+
{ code: "ERR_COMPILED_JSX_IN_SSR", id: t, plugin: "vite-plugin-what" }
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
var Fe = /[\\/](?:src|dist)[\\/]vnode-adoption(\.min)?\.js$/;
|
|
142
|
+
function Pe(t) {
|
|
143
|
+
let n = t.replace(/[?#].*$/, ""), o = Fe.exec(n);
|
|
144
|
+
if (o === null || !ae(n, k, "what-core")) return null;
|
|
145
|
+
let u = o[1] ? ".min.js" : ".js";
|
|
146
|
+
return `import { _adoptVNodeKinds, _adoptVNodeRows, _carryFields } from './render${u}';
|
|
147
|
+
import { _installVNodeRuntime } from './vnode-renderer${u}';
|
|
148
|
+
export var adoptVNodeKinds, adoptVNodeRows, fieldCarry;
|
|
149
|
+
export function installFieldCarry() {
|
|
150
|
+
fieldCarry = _carryFields;
|
|
151
|
+
}
|
|
152
|
+
export function installVNodeRuntime(render, keyedRows, setProp, refuses) {
|
|
153
|
+
adoptVNodeKinds = _adoptVNodeKinds;
|
|
154
|
+
adoptVNodeRows = _adoptVNodeRows;
|
|
155
|
+
fieldCarry = _carryFields;
|
|
156
|
+
_installVNodeRuntime(render, keyedRows, setProp, refuses);
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
function ie(t, n) {
|
|
161
|
+
if (t && t.ssr) return !0;
|
|
162
|
+
let o = n && n.environment;
|
|
163
|
+
return !!(o && o.name === "ssr");
|
|
164
|
+
}
|
|
165
|
+
function Ce(t = {}) {
|
|
166
|
+
let {
|
|
167
|
+
// File extensions to process
|
|
168
|
+
include: n = /\.[jt]sx$/,
|
|
169
|
+
// Files to exclude: a node_modules directory, not a name that holds the
|
|
170
|
+
// word (`my_node_modules_backup/`)
|
|
171
|
+
exclude: o = /\/node_modules\//,
|
|
172
|
+
// A dependency's files to compile as the app's: under node_modules, or of
|
|
173
|
+
// one of What's own packages. See "What it compiles".
|
|
174
|
+
compileDependencies: u = null,
|
|
175
|
+
// Enable source maps
|
|
176
|
+
sourceMaps: d = !0,
|
|
177
|
+
// Production optimizations
|
|
178
|
+
production: c = !0,
|
|
179
|
+
// Pages directory (relative to project root)
|
|
180
|
+
pages: f = "src/pages",
|
|
181
|
+
// HMR: enabled by default in dev, disabled in production
|
|
182
|
+
hot: b = !c,
|
|
183
|
+
// Resolve the `production` exports condition (dist/*.min.js — pre-minified,
|
|
184
|
+
// dev warnings compiled out) during `vite build`. Set to false to build
|
|
185
|
+
// against package sources instead — needed e.g. in a monorepo where
|
|
186
|
+
// workspace-linked dist/ output may be stale or absent. See config() below.
|
|
187
|
+
prodBundles: S = !0,
|
|
188
|
+
// Compile server transforms with the server target. See "Server builds".
|
|
189
|
+
ssr: N = !0,
|
|
190
|
+
// With ssr: false, refuse server transforms whose output builds DOM; false
|
|
191
|
+
// compiles them for the DOM instead (a process that installs a DOM).
|
|
192
|
+
ssrGuard: D = !0,
|
|
193
|
+
// Rewrite `selected() === row.id` in keyed .map() rows to a createSelector
|
|
194
|
+
// lookup. Set to false to keep every comparison as written.
|
|
195
|
+
autoSelector: ue = !0,
|
|
196
|
+
// Compile client JSX so that hydrate() adopts server-rendered markup.
|
|
197
|
+
// 'auto' does when the project renders on the server. See "Hydration".
|
|
198
|
+
hydratable: C = "auto",
|
|
199
|
+
// Print the compiler's notes on correct code (what the auto-selector
|
|
200
|
+
// rewrote, that <For> and a keyed .map() compile alike). Warnings about
|
|
201
|
+
// code that misbehaves print either way.
|
|
202
|
+
verbose: de = !1
|
|
203
|
+
} = t, m = "", j = "", O = !1, T = !1, I = null, L = C === !0, $ = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), Z = (e, r) => {
|
|
204
|
+
if (e.isSelfAccepting || r.has(e)) return !1;
|
|
205
|
+
r.add(e);
|
|
206
|
+
for (let a of e.importers)
|
|
207
|
+
if (!a.isSelfAccepting && (a.file && F.get(a.file) === "reload" || Z(a, r)))
|
|
208
|
+
return !0;
|
|
209
|
+
return !1;
|
|
210
|
+
};
|
|
211
|
+
function pe(e) {
|
|
212
|
+
let r = $.get(e.id);
|
|
213
|
+
if (r && r.key !== e.key)
|
|
214
|
+
throw Object.assign(
|
|
215
|
+
new Error(
|
|
216
|
+
`Duplicate server action ID "${e.id}". First declared by "${r.bindingName}" at ${r.source}; conflicts with "${e.bindingName}" at ${e.source}.`
|
|
217
|
+
),
|
|
218
|
+
{ code: "ERR_DUPLICATE_ACTION_ID" }
|
|
219
|
+
);
|
|
220
|
+
$.set(e.id, e);
|
|
221
|
+
}
|
|
222
|
+
function ee(e) {
|
|
223
|
+
for (let [r, a] of $)
|
|
224
|
+
a.filename === e && $.delete(r);
|
|
225
|
+
}
|
|
226
|
+
function U(e) {
|
|
227
|
+
let r = e.replace(/[?#].*$/, "");
|
|
228
|
+
return m ? p.relative(m, r).split(p.sep).join("/") : r;
|
|
229
|
+
}
|
|
230
|
+
function te(e, r) {
|
|
231
|
+
return !q.test(r) || !Y(r, m, A) ? null : re.transform.call(this, e, r, { optimizer: !0 });
|
|
232
|
+
}
|
|
233
|
+
let re = {
|
|
234
|
+
name: "vite-plugin-what",
|
|
235
|
+
configResolved(e) {
|
|
236
|
+
let r = be(e.root, k);
|
|
237
|
+
if (r) throw r;
|
|
238
|
+
m = e.root, A.clear(), j = p.resolve(m, f), O = e.command === "serve", T = b && O && !c && !(e.server && e.server.hmr === !1), L = C === "auto" ? $e(e) : C === !0;
|
|
239
|
+
},
|
|
240
|
+
configureServer(e) {
|
|
241
|
+
let r = () => {
|
|
242
|
+
let a = !1;
|
|
243
|
+
for (let i of [H, z]) {
|
|
244
|
+
let h = e.moduleGraph.getModuleById(i);
|
|
245
|
+
h && (e.moduleGraph.invalidateModule(h), a = !0);
|
|
246
|
+
}
|
|
247
|
+
a && e.ws.send({ type: "full-reload" });
|
|
248
|
+
};
|
|
249
|
+
e.watcher.on("add", (a) => {
|
|
250
|
+
a.startsWith(j) && r();
|
|
251
|
+
}), e.watcher.on("unlink", (a) => {
|
|
252
|
+
ee(U(a)), a.startsWith(j) && r();
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
// Resolve the virtual routes modules
|
|
256
|
+
resolveId(e) {
|
|
257
|
+
if (e === le)
|
|
258
|
+
return H;
|
|
259
|
+
if (e === ce)
|
|
260
|
+
return z;
|
|
261
|
+
},
|
|
262
|
+
// Generate the routes modules; in a client build compiled for hydration,
|
|
263
|
+
// what-core's vnode adoption stands in (see "Vnode adoption").
|
|
264
|
+
load(e, r) {
|
|
265
|
+
if (e === H)
|
|
266
|
+
return Re(j, m);
|
|
267
|
+
if (e === z)
|
|
268
|
+
return Ee(j, m);
|
|
269
|
+
if (L && !ie(r, this)) return Pe(e);
|
|
270
|
+
},
|
|
271
|
+
// Transform JSX files
|
|
272
|
+
transform(e, r, a) {
|
|
273
|
+
let i = r.replace(/[?#].*$/, ""), h = u !== null && P(u, i);
|
|
274
|
+
if (e.includes(Oe))
|
|
275
|
+
return F.delete(i), null;
|
|
276
|
+
if (!h && t.exclude !== void 0 && P(o, i)) return null;
|
|
277
|
+
let w = i.includes("/node_modules/"), R = !h && ae(i, k);
|
|
278
|
+
if (R && (w || !De.test(i))) return null;
|
|
279
|
+
let v = !R && q.test(i), g = v ? Y(i, m, A) : null, _ = v && (g || w || h) ? Me(e) : null, M = _ !== null && g?.declaresWhat === !0;
|
|
280
|
+
if (!h && !M && (g || w)) {
|
|
281
|
+
if (_ === null) return null;
|
|
282
|
+
throw Object.assign(
|
|
283
|
+
new Error(
|
|
284
|
+
`[what-compiler] ERR_DEPENDENCY_JSX: ${g?.name ?? i} ships JSX in ${i}. Declare what-framework or what-core in the package manifest, or opt the file into what({ compileDependencies: \u2026 }).`
|
|
285
|
+
),
|
|
286
|
+
{ code: "ERR_DEPENDENCY_JSX", id: r, plugin: "vite-plugin-what", loc: { file: i, line: _.line, column: _.column } }
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
let J = P(n, i) || _ !== null, fe = v && Se.test(e), ne = (s) => se.find((l) => l.name === s && !l.onRoot || l.as === s) || xe.find((l) => l.name === s);
|
|
290
|
+
if ((v ? [...e.matchAll(/\b(?:import|export)\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*['"]what-(?:framework|core)['"]/g)] : []).some(([, s]) => s.split(",").some((l) => ne(l.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0])))) {
|
|
291
|
+
let s = [];
|
|
292
|
+
try {
|
|
293
|
+
s = Q(e, { ast: !0, code: !1, configFile: !1, babelrc: !1, parserOpts: { plugins: ["jsx", "typescript"] } }).ast.program.body;
|
|
294
|
+
} catch {
|
|
295
|
+
}
|
|
296
|
+
let l = [];
|
|
297
|
+
for (let y of s) {
|
|
298
|
+
let K = y.source && y.source.value;
|
|
299
|
+
if (!(K !== "what-framework" && K !== "what-core" || y.importKind === "type" || y.exportKind === "type"))
|
|
300
|
+
for (let E of y.specifiers || []) {
|
|
301
|
+
let B = E.type === "ImportSpecifier" ? E.imported : E.type === "ExportSpecifier" ? E.local : null, G = B && E.importKind !== "type" && E.exportKind !== "type" ? B.name ?? B.value : null, W = G && ne(G);
|
|
302
|
+
W && l.push({ start: E.loc.start, text: `"${G}" is not exported by ${K}. ${W.answer}`, changed: se.includes(W) });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (l.length)
|
|
306
|
+
throw Object.assign(
|
|
307
|
+
new Error(
|
|
308
|
+
`[what-compiler] ERR_MOVED_IMPORT in ${p.relative(m || process.cwd(), i)}:
|
|
309
|
+
` + l.map((y) => ` ${y.text}`).join(`
|
|
310
|
+
`) + (l.some((y) => y.changed) ? `
|
|
311
|
+
eslint --fix with eslint-plugin-what's no-moved-imports rule rewrites the moved names; UPGRADING.md lists every change.` : "")
|
|
312
|
+
),
|
|
313
|
+
{ code: "ERR_MOVED_IMPORT", id: r, plugin: "vite-plugin-what", loc: { file: i, line: l[0].start.line, column: l[0].start.column } }
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
v && ee(U(i));
|
|
317
|
+
let me = v && O && !c && /['"]what-(?:core|framework)['"]/.test(e);
|
|
318
|
+
if (!J && !fe && !me) return null;
|
|
319
|
+
let X = ie(a, this), oe = X && N !== !1 && D !== !1 ? "ssr" : "dom", he = X && N === !1 && D !== !1, we = T && !X && !R && !a?.optimizer;
|
|
320
|
+
try {
|
|
321
|
+
let s = Q(e, {
|
|
322
|
+
filename: r,
|
|
323
|
+
sourceMaps: d,
|
|
324
|
+
// Each statement on its source line in development (see config()).
|
|
325
|
+
retainLines: O && !c,
|
|
326
|
+
// Hermetic transform: never load the project's
|
|
327
|
+
// babel.config.js/.babelrc. A user's React preset or unrelated
|
|
328
|
+
// plugins corrupting What's JSX output is a debugging nightmare —
|
|
329
|
+
// and scanning the disk for config files on every transform is
|
|
330
|
+
// wasted I/O in dev.
|
|
331
|
+
configFile: !1,
|
|
332
|
+
babelrc: !1,
|
|
333
|
+
plugins: [
|
|
334
|
+
...we ? [[ve, { file: U(i), onMode: (l) => F.set(i, l) }]] : [],
|
|
335
|
+
...I !== null && i.endsWith(".tsx") ? [[I, { isTSX: !0, allowDeclareFields: !0 }]] : [],
|
|
336
|
+
[ye, {
|
|
337
|
+
generate: oe,
|
|
338
|
+
hydratable: oe === "dom" && L,
|
|
339
|
+
production: c,
|
|
340
|
+
devMetadata: O && !c,
|
|
341
|
+
sourceLoc: O && !c ? ke(this) : void 0,
|
|
342
|
+
autoSelector: ue,
|
|
343
|
+
verbose: de,
|
|
344
|
+
projectRoot: m || process.cwd(),
|
|
345
|
+
onActionId: pe,
|
|
346
|
+
appSource: h || M
|
|
347
|
+
}]
|
|
348
|
+
],
|
|
349
|
+
parserOpts: {
|
|
350
|
+
plugins: ["jsx", "typescript"]
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
if (!s || !s.code)
|
|
354
|
+
return null;
|
|
355
|
+
if (he && s.metadata && s.metadata.whatBuildsDom)
|
|
356
|
+
throw Ae(i);
|
|
357
|
+
return {
|
|
358
|
+
code: s.code,
|
|
359
|
+
map: s.map
|
|
360
|
+
};
|
|
361
|
+
} catch (s) {
|
|
362
|
+
throw s && s.code === "ERR_COMPILED_JSX_IN_SSR" || (s.plugin = "vite-plugin-what", s.id || (s.id = r), s.loc === void 0 && s._loc && (s.loc = { file: r, line: s._loc.line, column: s._loc.column }), console.error(`[what] Error transforming ${r}:`, s.message)), s;
|
|
410
363
|
}
|
|
364
|
+
},
|
|
365
|
+
// Hot replacement: Vite updates the modules that accept the edit (each
|
|
366
|
+
// module's mode, src/hot.js). A module that runs statements at its top
|
|
367
|
+
// level, edited or run again on the way to the modules that accept the
|
|
368
|
+
// update, reloads the page instead: running it again would run them twice.
|
|
369
|
+
async handleHotUpdate({ file: e, modules: r, read: a, server: i }) {
|
|
370
|
+
if (!(!T || !F.has(e) || !(_e(ge, await a(), e) || r.some((w) => Z(w, /* @__PURE__ */ new Set())))))
|
|
371
|
+
return i.ws.send({ type: "full-reload" }), [];
|
|
372
|
+
},
|
|
373
|
+
// Configure for development
|
|
374
|
+
async config(e, { mode: r, command: a }) {
|
|
375
|
+
let i = a === "build" && r === "production" && S, h = a === "build" && r !== "development", w = je({
|
|
376
|
+
rolldownVersion: this?.meta?.rolldownVersion,
|
|
377
|
+
viteVersion: await Ie(e.root)
|
|
378
|
+
}), R = w.oxc ? "oxc" : "esbuild";
|
|
379
|
+
return a === "serve" && !c && (I = Ne(e.root || process.cwd()), e[R] && "exclude" in e[R] ? I = null : w[R].exclude = I !== null ? /\.(?:jsx?|tsx)$/ : /\.jsx?$/), {
|
|
380
|
+
...i ? { resolve: { conditions: ["production"] } } : {},
|
|
381
|
+
...h ? { define: { __WHAT_DEV__: "false" } } : {},
|
|
382
|
+
...w,
|
|
383
|
+
optimizeDeps: {
|
|
384
|
+
// Vite 8's dependency scan transforms .jsx with these options, not
|
|
385
|
+
// `oxc`, and defaults to React's automatic runtime: it would look for
|
|
386
|
+
// react/jsx-dev-runtime and print "Failed to run dependency scan".
|
|
387
|
+
...w.oxc ? {
|
|
388
|
+
rolldownOptions: {
|
|
389
|
+
transform: { jsx: "preserve" },
|
|
390
|
+
plugins: [{ name: "what-dependency-jsx", transform: te }]
|
|
391
|
+
}
|
|
392
|
+
} : {
|
|
393
|
+
esbuildOptions: {
|
|
394
|
+
plugins: [{
|
|
395
|
+
name: "what-dependency-jsx",
|
|
396
|
+
setup(v) {
|
|
397
|
+
v.onLoad({ filter: q }, async ({ path: g }) => {
|
|
398
|
+
let _ = g.replace(/\\/g, "/");
|
|
399
|
+
if (!Y(_, m, A)) return;
|
|
400
|
+
let M = te.call(void 0, await k.promises.readFile(g, "utf8"), _);
|
|
401
|
+
if (M === null) return;
|
|
402
|
+
let J = /\.([jt]sx?)$/.exec(g)?.[1];
|
|
403
|
+
return { contents: M.code, loader: J ?? (/\.[cm]ts$/.test(g) ? "ts" : "js") };
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}]
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
// Exclude framework packages from Vite's dependency pre-bundling.
|
|
410
|
+
//
|
|
411
|
+
// Bug class this prevents — "dual module instance":
|
|
412
|
+
// The compiler emits `import { ... } from 'what-framework/render'`
|
|
413
|
+
// (a subpath resolved to the source file). Meanwhile user code
|
|
414
|
+
// imports `'what-framework'` (the package entry). If Vite
|
|
415
|
+
// pre-bundles `'what-framework'` into an esbuild chunk under
|
|
416
|
+
// node_modules/.vite, those two import paths resolve to two
|
|
417
|
+
// *different* module instances. Module-scoped state — the
|
|
418
|
+
// current owner that components and hooks resolve through,
|
|
419
|
+
// the signal subscriber registry — is duplicated, so a signal
|
|
420
|
+
// created in user code never notifies effects created via the
|
|
421
|
+
// compiler-emitted path, and `getCurrentComponent()` returns
|
|
422
|
+
// undefined inside components mounted through compiler output.
|
|
423
|
+
//
|
|
424
|
+
// Why `exclude` is the right knob:
|
|
425
|
+
// `include` would force pre-bundling of the package entry, which
|
|
426
|
+
// does not resolve the subpath import the compiler emits — so the
|
|
427
|
+
// split persists. Using `exclude` tells Vite to skip the optimizer
|
|
428
|
+
// for these packages and serve them via the normal module graph,
|
|
429
|
+
// where both the package entry and the `/render` subpath share
|
|
430
|
+
// a single ESM module record.
|
|
431
|
+
//
|
|
432
|
+
// Regression symptom if this is removed:
|
|
433
|
+
// Components mount but lifecycle hooks (onMount, onCleanup) and
|
|
434
|
+
// shared store state silently no-op; effects don't re-run on
|
|
435
|
+
// signal writes from user code; SSR/CSR hydration mismatches.
|
|
436
|
+
exclude: ["what-framework", "what-core", "what-compiler", "what-router"]
|
|
437
|
+
}
|
|
438
|
+
};
|
|
411
439
|
}
|
|
412
|
-
}
|
|
440
|
+
};
|
|
441
|
+
return re;
|
|
413
442
|
}
|
|
414
|
-
|
|
443
|
+
export {
|
|
444
|
+
Ce as default,
|
|
445
|
+
je as jsxPreserveConfig,
|
|
446
|
+
Ce as what
|
|
447
|
+
};
|