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/babel-plugin.min.js
CHANGED
|
@@ -1 +1,101 @@
|
|
|
1
|
-
var Be=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ue=new Set(["once","capture","passive"]),He=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ge=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),W=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),qe=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"]),ge=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]),ze=new Set(["For","Show","Switch","Match"]),Ke=new Set(["what-framework/server","what-server","what-server/actions"]);function Se(e){return e==="what-framework"||e.startsWith("what-framework/")||e==="what-core"||e.startsWith("what-core/")}function Ze(e){let A=0xcbf29ce484222325n;for(let k=0;k<e.length;k++)A^=BigInt(e.charCodeAt(k)),A=BigInt.asUintN(64,A*0x100000001b3n);return A.toString(36)}function Qe(e,A){let k=String(e||"<unknown>").replace(/\\/g,"/").replace(/[?#].*$/,""),$=String(A||"").replace(/\\/g,"/").replace(/\/+$/,"");return $&&k.startsWith(`${$}/`)?k.slice($.length+1):k.replace(/^\.\//,"")}function M(e){if(!/[\r\n]/.test(e))return e.replace(/\t/g," ");let A=e.split(/\r\n|\n|\r/),k=-1;for(let y=0;y<A.length;y++)/[^ \t]/.test(A[y])&&(k=y);if(k===-1)return"";let $="";for(let y=0;y<A.length;y++){let C=A[y].replace(/\t/g," "),O=y===0,B=y===A.length-1;O||(C=C.replace(/^ +/,"")),B||(C=C.replace(/ +$/,"")),C&&(y!==k&&(C+=" "),$+=C)}return $}function Ye({types:e}){let A=new Set,k=new Set;function $(i,n){return!(!i.includes("__")||!i.startsWith("on")||i.split("__").slice(1).filter(s=>s!=="").length===0)}function y(i){let n=i.includes("|")?"|":"__",r=i.split(n),o=r[0],s=r.slice(1).filter(a=>Be.has(a));return{eventName:o,modifiers:s}}function C(i){return i.startsWith("bind:")}function O(i){return i.slice(5)}function B(i){return/^[A-Z]/.test(i)}function Z(i,n,r){if(typeof i?.buildCodeFrameError=="function")return i.buildCodeFrameError(r);let o=i?.node;if(o&&typeof n?.file?.buildCodeFrameError=="function")return n.file.buildCodeFrameError(o,r);let s=o?.loc?.start,a=n?.filename||n?.file?.opts?.filename||"<unknown>";return new Error(`[what-compiler] ${r} (${s?`${a}:${s.line}:${s.column+1}`:a})`)}function D(i){let n=i.openingElement?i.openingElement.name:i.name;return e.isJSXMemberExpression(n)?!0:e.isJSXIdentifier(n)&&B(n.name)}function R(i,n){return!!(n.foreignImports&&n.foreignImports.has(i))}function xe(i,n){return!!(n.whatImports&&n.whatImports.has(i))}function be(i){return i.children.some(n=>e.isJSXElement(n)&&e.isJSXIdentifier(n.openingElement.name,{name:"Match"}))}function ye(i){let n=i.parentPath;return!n||typeof n.isCallExpression!="function"||!n.isCallExpression()||n.node.arguments[0]!==i.node?!1:ve(n.node.callee,n.scope)}function ve(i,n){return e.isMemberExpression(i)&&!i.computed&&e.isIdentifier(i.property,{name:"hydrate"})&&e.isIdentifier(i.object)?Q(n.getBinding(i.object.name),e.isImportNamespaceSpecifier,null):e.isIdentifier(i)?Q(n.getBinding(i.name),e.isImportSpecifier,"hydrate"):!1}function Q(i,n,r){if(!i||i.kind!=="module"||!i.path)return!1;let o=i.path.node;if(!n(o))return!1;if(r!==null){let a=o.imported;if((e.isIdentifier(a)?a.name:e.isStringLiteral(a)?a.value:null)!==r)return!1}let s=i.path.parent;return e.isImportDeclaration(s)&&Se(s.source.value)}function Y(i){return e.isJSXMemberExpression(i)?e.memberExpression(Y(i.object),e.identifier(i.property.name)):e.identifier(i.name)}function we(i){let n=i.node.params;if(n.length!==1||!e.isObjectPattern(n[0]))return;let r=n[0],o=-1;for(let u=0;u<r.properties.length;u++){let E=r.properties[u];if(e.isRestElement(E))return;if(e.isObjectProperty(E)&&!E.computed&&e.isIdentifier(E.key,{name:"children"})){if(o!==-1||!e.isIdentifier(E.value))return;o=u}}if(o===-1)return;let s=i.scope.getBinding(r.properties[o].value.name);if(!s||s.constantViolations.length>0||s.referencePaths.length===0||!s.referencePaths.every(u=>{let E=u.parentPath;if(!E||!E.isJSXExpressionContainer())return!1;let d=E.parentPath;if(!d||!d.isJSXElement()||!D(d.node))return!1;let l=d.node.openingElement.name;return!(e.isJSXIdentifier(l)&&ze.has(l.name))}))return;let t=i.scope.generateUidIdentifier("props");r.typeAnnotation&&(t.typeAnnotation=r.typeAnnotation),n[0]=t;let c=r.properties.filter((u,E)=>E!==o);if(c.length>0){e.isBlockStatement(i.node.body)||(i.node.body=e.blockStatement([e.returnStatement(i.node.body)]));let u=e.objectPattern(c);i.node.body.body.unshift(e.variableDeclaration("const",[e.variableDeclarator(u,e.cloneNode(t))])),i.node._whatMovedProps=u}for(let u of s.referencePaths)u.replaceWith(e.memberExpression(e.cloneNode(t),e.identifier("children")));i.scope.crawl()}function Ie(i){return He.has(String(i).toLowerCase())}function _(i){return i?e.isJSXExpressionContainer(i)?i.expression:e.isStringLiteral(i)?i:e.stringLiteral(i.value||""):e.booleanLiteral(!0)}let Ae=new Map([["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"],["acceptCharset","accept-charset"]]);function L(i){return Ae.get(i)||i}function ee(i,n){let r=L(F(i[n]));for(let o=n+1;o<i.length;o+=1){let s=i[o];if(!e.isJSXSpreadAttribute(s)&&L(F(s))===r)return!0}return!1}function F(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 ne(i){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i)?e.identifier(i):e.stringLiteral(i)}function Ce(i){return!!i&&i.length>2&&/^on/i.test(i)}function ie(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 J(i,n){return n.has(i)}function _e(i){let n=new Set,r=new Set;n.fromDestructuredProps=r;function o(t){let c=t.init;if(!c||!e.isCallExpression(c))return;let u=c.callee,E="";if(e.isIdentifier(u)?E=u.name:e.isMemberExpression(u)&&e.isIdentifier(u.property)&&(E=u.property.name),ge.has(E)){let d=t.id;if(e.isIdentifier(d))n.add(d.name);else if(e.isArrayPattern(d))for(let l of d.elements)e.isIdentifier(l)&&n.add(l.name);else if(e.isObjectPattern(d))for(let l of d.properties)e.isObjectProperty(l)&&e.isIdentifier(l.value)&&n.add(l.value.name)}}function s(t){if(e.isObjectPattern(t))for(let c of t.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()&&o(c.path.node);let t=a.path&&a.path.node;if(t){if(t.params)for(let c of t.params)s(c);t._whatMovedProps&&s(t._whatMovedProps)}a=a.parent}return n}function ke(i){return e.isMemberExpression(i.callee)&&!i.callee.computed&&e.isIdentifier(i.callee.property)&&qe.has(i.callee.property.name)}function re(i){if(!e.isCallExpression(i))return!1;let n=i.callee;return e.isMemberExpression(n)&&e.isIdentifier(n.object)?W.has(n.object.name):e.isIdentifier(n)?W.has(n.name):!1}function oe(i,n,r){if(!n)return!1;if(e.isCallExpression(i)){if(e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)||re(i))return!1;if(i.arguments.some(o=>w(o,n,r)))return!0}return!1}function w(i,n,r){return n||(n=new Set),e.isCallExpression(i)?e.isIdentifier(i.callee)&&J(i.callee.name,n)||r&&e.isIdentifier(i.callee)&&r.has(i.callee.name)&&!W.has(i.callee.name)||e.isMemberExpression(i.callee)&&e.isIdentifier(i.callee.object)&&J(i.callee.object.name,n)?!0:re(i)?i.arguments.some(o=>w(o,n,r)):i.arguments.length===0&&!ke(i)?!0:e.isIdentifier(i.callee)?i.arguments.some(o=>w(o,n,r)):w(i.callee,n,r)||i.arguments.some(o=>w(o,n,r)):e.isIdentifier(i)?J(i.name,n)||r&&r.has(i.name):e.isMemberExpression(i)?w(i.object,n,r):e.isConditionalExpression(i)?w(i.test,n,r)||w(i.consequent,n,r)||w(i.alternate,n,r):e.isBinaryExpression(i)||e.isLogicalExpression(i)?w(i.left,n,r)||w(i.right,n,r):e.isUnaryExpression(i)?w(i.argument,n,r):e.isTemplateLiteral(i)?i.expressions.some(o=>w(o,n,r)):e.isObjectExpression(i)?i.properties.some(o=>e.isObjectProperty(o)&&w(o.value,n,r)):e.isArrayExpression(i)?i.elements.some(o=>o&&w(o,n,r)):(e.isArrowFunctionExpression(i)||e.isFunctionExpression(i),!1)}function N(i,n){if(!i||typeof i!="object")return n;switch(i.type){case"Identifier":n.add(i.name);break;case"AssignmentPattern":N(i.left,n);break;case"RestElement":N(i.argument,n);break;case"ArrayPattern":for(let r of i.elements)N(r,n);break;case"ObjectPattern":for(let r of i.properties)N(r.type==="RestElement"?r.argument:r.value,n);break;default:break}return n}function $e(i){let n=new Set;for(let o=1;o<i.params.length;o++)N(i.params[o],n);let r=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){o.forEach(r);return}switch(o.type){case"VariableDeclaration":for(let s of o.declarations)N(s.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":o.id&&n.add(o.id.name);return;case"FunctionExpression":case"ArrowFunctionExpression":case"ClassExpression":return;case"CatchClause":N(o.param,n),r(o.body);return;case"ForStatement":case"ForInStatement":case"ForOfStatement":r(o.init),r(o.left),r(o.body);return;default:break}for(let s of Object.keys(o)){if(s==="loc"||s==="start"||s==="end"||s==="type"||s==="leadingComments"||s==="trailingComments"||s==="innerComments")continue;let a=o[s];a&&typeof a=="object"&&r(a)}}};e.isBlockStatement(i.body)&&r(i.body.body);for(let o of N(i.params[0],new Set))n.delete(o);return n}function Fe(i,n){if(n.size===0)return null;let r=null,o=s=>{if(!(r||!s||typeof s!="object")){if(Array.isArray(s)){s.forEach(o);return}if(s.type==="Identifier"){n.has(s.name)&&(r=s.name);return}for(let a of Object.keys(s)){if(a==="loc"||a==="start"||a==="end"||a==="type"||a==="leadingComments"||a==="trailingComments"||a==="innerComments"||s.type==="MemberExpression"&&a==="property"&&!s.computed||(s.type==="ObjectProperty"||s.type==="ObjectMethod")&&a==="key"&&!s.computed)continue;let t=s[a];t&&typeof t=="object"&&o(t)}}};return o(i),r}function se(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=V(r.consequent,n),t=V(r.alternate,n);if(a||t){let c=e.conditionalExpression(r.test,a||r.consequent,t||r.alternate);return o?e.arrowFunctionExpression([],c):c}return null}if(e.isLogicalExpression(r)&&(r.operator==="&&"||r.operator==="||")){let a=V(r.right,n);if(a){let t=e.logicalExpression(r.operator,r.left,a);return o?e.arrowFunctionExpression([],t):t}return null}return V(r,n)}function V(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 m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}}else if(e.isFunctionExpression(r)){let m=r.body.body.find(f=>e.isReturnStatement(f));m&&(o=m.argument)}if(!o||!e.isJSXElement(o))return null;let s=o.openingElement.attributes,a=null;for(let m of s)if(e.isJSXAttribute(m)&&F(m)==="key"){a=m;break}if(!a)return null;let t=_(a.value);if(!t)return null;let c=$e(r);if(Fe(t,c)){let m=e.isIdentifier(t)&&r.params[1]&&e.isIdentifier(r.params[1],{name:t.name});return null}o.openingElement.attributes=s.filter(m=>m!==a);let E=i.callee.object,d=e.arrowFunctionExpression([],E),l=r.params[0]?e.cloneNode(r.params[0],!0):e.identifier("_item"),p=e.arrowFunctionExpression([l],e.cloneNode(t,!0));return e.callExpression(e.identifier("_$mapArray"),[d,r,e.objectExpression([e.objectProperty(e.identifier("key"),p),e.objectProperty(e.identifier("raw"),e.booleanLiteral(!0))])])}function U(i){if(e.isJSXText(i))return!0;if(e.isJSXExpressionContainer(i))return!1;if(e.isJSXElement(i)){let n=i.openingElement;if(D(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(U)}return!1}function te(i){return e.isJSXSpreadAttribute(i)?!0:i.value?e.isJSXExpressionContainer(i.value):!1}function H(i,n=[]){for(let r of i.children){if(e.isJSXText(r)){let o=M(r.value);o&&n.push({kind:"text",text:o});continue}if(e.isJSXFragment(r)){H(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 G(i){if(e.isJSXText(i)){let t=M(i.value);return t?ae(t):""}if(e.isJSXExpressionContainer(i))return e.isJSXEmptyExpression(i.expression)?"":"<!--$-->";if(!e.isJSXElement(i))return"";let n=i.openingElement,r=n.name.name;if(D(i))return"";let o=`<${r}`,s=n.attributes.findIndex(t=>e.isJSXSpreadAttribute(t));for(let[t,c]of n.attributes.entries()){if(e.isJSXSpreadAttribute(c)||s!==-1&&t>s||ee(n.attributes,t))continue;let u=F(c);if(u==="key"||Ce(u)||u.startsWith("bind:")||u.includes("|"))continue;let E=L(u);if(!c.value)o+=` ${E}`;else if(e.isStringLiteral(c.value))o+=` ${E}="${Me(c.value.value)}"`;else if(e.isJSXExpressionContainer(c.value))continue}let a=i.openingElement.selfClosing;if(a&&Ie(r))return o+=">",o;if(a)return o+=`></${r}>`,o;o+=">";for(let t of i.children)if(e.isJSXText(t)){let c=M(t.value);c&&(o+=ae(c))}else e.isJSXExpressionContainer(t)?e.isJSXEmptyExpression(t.expression)||(o+="<!--$-->"):e.isJSXElement(t)?D(t)?o+="<!--$-->":o+=G(t):e.isJSXFragment(t)&&(o+="<!--$-->".repeat(H(t).length));return o+=`</${r}>`,o}function ae(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Me(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function X(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name;if(!R(s,n)){if(s==="For")return Xe(i,n);if(s==="Show")return De(i,n)}if(s==="Switch"&&(!R(s,n)||be(r)))return Pe(i,n);if(D(r))return fe(i,n);let a=o.attributes,t=r.children,c=t.every(U),u=a.every(f=>!te(f)),E=a.every(f=>{if(e.isJSXSpreadAttribute(f))return!1;let x=F(f);return!x?.startsWith("on")&&!x?.startsWith("bind:")});if(c&&u&&E){let f=G(r);if(f){let x=me(n,f);return n.needsTemplate=!0,e.callExpression(e.identifier(x),[])}}let d=G(r);if(!d){let f=r.loc,x=n.filename||n.file?.opts?.filename||"<unknown>",h=f?`:${f.start.line}:${f.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${s}> at ${x}${h}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),n.needsH=!0,q(i,n)}let l=me(n,d);n.needsTemplate=!0;let p=n.nextVarId(),m=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier(l),[]))])];return le(m,p,a,n,s),ce(m,p,t,r,n),n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(...m),e.identifier(p)}function q(i,n){let{node:r}=i,o=r.openingElement,s=o.name.name,a=o.attributes,t=r.children,c=[];for(let d of a){if(e.isJSXSpreadAttribute(d))continue;let l=F(d),p=_(d.value),m=L(l);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(m)?e.identifier(m):e.stringLiteral(m),p))}let u=[];for(let d of t)if(e.isJSXText(d)){let l=M(d.value);l&&u.push(e.stringLiteral(l))}else e.isJSXExpressionContainer(d)?e.isJSXEmptyExpression(d.expression)||u.push(d.expression):e.isJSXElement(d)?u.push(X({node:d},n)):e.isJSXFragment(d)&&u.push(P({node:d},n));let E=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(s),E,...u])}let Ne=new Set(["input","textarea","select","option"]);function le(i,n,r,o,s){function a(E,d){return E==="class"?(o.needsSetClass=!0,e.callExpression(e.identifier("_$setClass"),[e.identifier(n),d])):E==="style"?(o.needsSetStyle=!0,e.callExpression(e.identifier("_$setStyle"),[e.identifier(n),d])):E==="value"&&s&&Ne.has(s)?(o.needsSetValue=!0,e.callExpression(e.identifier("_$setValue"),[e.identifier(n),d])):E==="checked"&&s==="input"?(o.needsSetChecked=!0,e.callExpression(e.identifier("_$setChecked"),[e.identifier(n),d])):E.startsWith("data-")||E.startsWith("aria-")?(o.needsSetAttr=!0,e.callExpression(e.identifier("_$setAttr"),[e.identifier(n),e.stringLiteral(E),d])):(o.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(n),e.stringLiteral(E),d]))}let t=!1;function c(){t||(t=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$delegate$"),[]))))}let u=!1;for(let[E,d]of r.entries()){if(e.isJSXSpreadAttribute(d)){u=!0,o.needsSpread=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(n),d.argument])));continue}if(ee(r,E))continue;let l=F(d);if(l!=="key"){if(l==="ref"){let p=_(d.value);i.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",p),e.stringLiteral("function")),e.callExpression(e.cloneNode(p),[e.identifier(n)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(p),e.identifier("current")),e.identifier(n)))));continue}if(l.startsWith("on")&&!l.includes("|")&&!$(l,o)){let p=l.slice(2).toLowerCase(),m=_(d.value);Ge.has(p)?(o.needsDelegation=!0,o.delegatedEvents||(o.delegatedEvents=new Set),o.delegatedEvents.add(p),c(),i.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(n),e.identifier(`$$${p}`)),m)))):i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),[e.stringLiteral(p),m])));continue}if(l.startsWith("on")&&(l.includes("|")||$(l,o))){let{eventName:p,modifiers:m}=y(l),f=_(d.value),x=ie(f,m),h=p.slice(2).toLowerCase(),g=m.filter(v=>Ue.has(v)),b=[e.stringLiteral(h),x];if(g.length>0){let v=g.map(S=>e.objectProperty(e.identifier(S),e.booleanLiteral(!0)));b.push(e.objectExpression(v))}i.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(n),e.identifier("addEventListener")),b)));continue}if(C(l)){let p=O(l),m=d.value.expression;o.needsEffect=!0,p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):p==="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(m),[])))]))),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(m),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(d.value)){let p=d.value.expression,m=L(l);if(w(p,o.signalNames,o.importedIdentifiers)){o.needsEffect=!0;let f=o.signalNames&&o.signalNames.fromDestructuredProps,x=e.isIdentifier(p)&&!(f&&f.has(p.name))&&J(p.name,o.signalNames)?e.callExpression(p,[]):p,h=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(m,x))]);oe(p,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(m,p)));continue}u&&i.push(e.expressionStatement(a(L(l),_(d.value))))}}}function z(i){if(!i||typeof i!="object")return!1;if(Array.isArray(i))return i.some(z);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"&&z(r))return!0}return!1}function Je(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 j(i,n,r){let o=null,s=!1;if(e.isConditionalExpression(i))o=i.test,s=!0;else if(e.isLogicalExpression(i)&&(i.operator==="&&"||i.operator==="||"))o=i.left;else return i;if(!w(o,r.signalNames,r.importedIdentifiers)||!(s?[i.consequent,i.alternate]:[i.right]).some(z))return i;let t=r.nextMemoId();r.needsMemo=!0;let c=s?e.unaryExpression("!",e.unaryExpression("!",o)):o;n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(t),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],c)]))]));let u=e.callExpression(e.identifier(t),[]);return s?e.conditionalExpression(u,i.consequent,i.alternate):e.logicalExpression(i.operator,u,i.right)}function ce(i,n,r,o,s){let a=[],t=0;for(let l of r){if(e.isJSXText(l)){M(l.value)&&t++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;a.push({type:"expression",child:l,childIndex:t}),t++;continue}if(e.isJSXElement(l)){let p=l.openingElement.name.name;if(D(l)||p==="For"||p==="Show")a.push({type:"component",child:l,childIndex:t}),t++;else{let m=l.openingElement.attributes.some(te)||l.openingElement.attributes.some(f=>!e.isJSXSpreadAttribute(f)&&F(f)?.startsWith("on"))||!l.children.every(U);a.push({type:"static",child:l,childIndex:t,hasAnythingDynamic:m}),t++}continue}if(e.isJSXFragment(l))for(let p of H(l))p.kind==="text"?a.push({type:"fragmentText",text:p.text,childIndex:t}):p.kind==="expression"?a.push({type:"expression",child:p.child,childIndex:t}):a.push({type:"component",child:p.child,childIndex:t}),t++}let c=a.filter(l=>l.type==="expression"||l.type==="component"||l.type==="fragmentText"||l.type==="static"&&l.hasAnythingDynamic),u=c.length>=2,E=new Map;if(u){let l=null,p=0;for(let m of c){let f=m.childIndex,x=s.nextVarId();E.set(f,x);let h;if(l===null)h=K(n,f);else{h=e.identifier(l);for(let g=p;g<f;g++)h=e.memberExpression(h,e.identifier("nextSibling"))}i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(x),h)])),l=x,p=f}}function d(l){return E.has(l)?e.identifier(E.get(l)):K(n,l)}for(let l of a){if(l.type==="expression"){let p=l.child.expression,m=d(l.childIndex);s.needsInsert=!0;let f=se(p,s);if(f){s.needsMapArray=!0;let h=e.isCallExpression(f)&&e.isIdentifier(f.callee)&&(f.callee.name==="_$mapArray"||f.callee.name==="mapArray"),g=e.isArrowFunctionExpression(f);g&&e.isExpression(f.body)?f.body=j(f.body,i,s):!h&&!g&&(f=j(f,i,s));let b=h||g?f:e.arrowFunctionExpression([],f);i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),b,m])));continue}if(e.isCallExpression(p)&&e.isIdentifier(p.callee)&&(p.callee.name==="mapArray"||p.callee.name==="_$mapArray")){s.needsMapArray=!0,p.callee.name==="mapArray"&&(p.callee.name="_$mapArray"),i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(w(p,s.signalNames,s.importedIdentifiers)){p=j(p,i,s);let h=e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.arrowFunctionExpression([],p),m]);oe(p,s.signalNames,s.importedIdentifiers)&&e.addComment(h,"leading"," @what-dev: reactive 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(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="component"){let p=X({node:l.child},s),m=d(l.childIndex);s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),p,m])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let p;E.has(l.childIndex)?p=E.get(l.childIndex):(p=s.nextVarId(),i.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),K(n,l.childIndex))]))),le(i,p,l.child.openingElement.attributes,s,l.child.openingElement.name.name),ce(i,p,l.child.children,l.child,s);continue}if(l.type==="fragmentText"){s.needsInsert=!0,i.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(n),e.stringLiteral(l.text),d(l.childIndex)])));continue}}}function K(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 fe(i,n){let{node:r}=i,o=r.openingElement,s=Y(o.name),a=o.attributes,t=r.children,c=null,u=[];for(let h of a){if(e.isJSXAttribute(h)){let g;if(e.isJSXNamespacedName(h.name)?g=`${h.name.namespace.name}:${h.name.name.name}`:g=h.name.name,g&&typeof g=="string"&&g.startsWith("client:")){let b=g.slice(7);h.value?c={type:b,value:h.value.value}:c={type:b};continue}}u.push(h)}function E(){let h=n._pendingSetup?n._pendingSetup.length:0,g=[],b=!1;for(let S of t)if(e.isJSXText(S)){let I=M(S.value);I&&g.push(e.stringLiteral(I))}else if(e.isJSXExpressionContainer(S))e.isJSXEmptyExpression(S.expression)||(b=!0,g.push(de(S.expression,n)));else if(e.isJSXElement(S)){let I=S.openingElement.name.name;I!=="For"&&I!=="Show"&&I!=="Switch"&&(b=!0),g.push(X({node:S},n))}else e.isJSXFragment(S)&&(b=!0,g.push(P({node:S},n)));let v=e.arrayExpression(g);if(b){let S=n._pendingSetup?n._pendingSetup.splice(h):[];v=e.arrowFunctionExpression([],S.length>0?e.blockStatement([...S,e.returnStatement(v)]):v)}return v}if(c){n.needsCreateComponent=!0,n.needsIsland=!0;let h=[e.objectProperty(e.identifier("component"),s),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&h.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));let g=[],b=[],v=()=>{b.length>0&&(g.push(e.objectExpression(b)),b=[])};for(let I of u){if(e.isJSXSpreadAttribute(I)){v(),g.push(I.argument);continue}let T=F(I);if(T==="key")continue;let We=_(I.value);b.push(e.objectProperty(ne(T),We))}let S;return g.length===0?S=e.objectExpression([...b,...h]):(v(),S=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),...g,e.objectExpression(h)])),e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),S,E()])}let d=ye(i);d?n.needsComponentVNode=!0:n.needsCreateComponent=!0;let l=[],p=[],m=()=>{p.length>0&&(l.push(e.objectExpression(p)),p=[])};for(let h of u){if(e.isJSXSpreadAttribute(h)){m(),l.push(h.argument);continue}let g=F(h);if(g==="key")continue;if(C(g)){let v=O(g),S=h.value.expression;v==="value"?(p.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(S),[]))),p.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):v==="checked"&&(p.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(S),[]))),p.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(S),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(g.startsWith("on")&&(g.includes("|")||$(g,n))){let{eventName:v,modifiers:S}=y(g),I=_(h.value),T=ie(I,S);p.push(e.objectProperty(e.identifier(v),T));continue}let b=_(h.value);p.push(e.objectProperty(ne(g),b))}m();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 x=E();return e.callExpression(e.identifier(d?"_$componentVNode":"_$createComponent"),[s,f,x])}function Xe(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null,c=null;for(let S of o)if(e.isJSXAttribute(S)){let I=F(S);I==="each"?a=_(S.value):I==="key"?t=_(S.value):I==="fallback"&&(c=_(S.value))}if(!a)return console.warn('[what-compiler] <For> element missing "each" attribute.'),n.needsH=!0,q(i,n);let u=null;for(let S of s)if(e.isJSXExpressionContainer(S)&&!e.isJSXEmptyExpression(S.expression)){u=S.expression;break}if(!u)return console.warn("[what-compiler] <For> element missing render function child."),n.needsH=!0,q(i,n);n.needsMapArray=!0;let E=S=>{let I=[S,u];return t&&I.push(e.objectExpression([e.objectProperty(e.identifier("key"),t)])),e.callExpression(e.identifier("_$mapArray"),I)};if(!c)return E(a);n._pendingSetup||(n._pendingSetup=[]);let d=n.nextForIndex(),l=`_each$${d}`,p=`_for$${d}`,m=`_fb$${d}`,f=n.nextMemoId();n.needsMemo=!0,n.needsInsert=!0;let x=i.scope?i.scope.generateUidIdentifier("list"):e.identifier("_list"),h=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(x,h)]),e.returnStatement(e.unaryExpression("!",e.unaryExpression("!",e.logicalExpression("&&",e.cloneNode(x),e.memberExpression(e.cloneNode(x),e.identifier("length"))))))]))]))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),E(e.identifier(l)))]),e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.arrowFunctionExpression([],e.conditionalExpression(e.callExpression(e.identifier(f),[]),e.nullLiteral(),c)))]));let g=e.identifier("_parent"),b=e.identifier("_marker"),v=e.identifier("_end");return e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.arrowFunctionExpression([g,b],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(v,e.callExpression(e.identifier(p),[e.cloneNode(g),e.cloneNode(b)]))]),e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.cloneNode(g),e.arrayExpression([e.identifier(m)]),e.cloneNode(b)])),e.returnStatement(e.cloneNode(v))])),e.identifier(p)])}function De(i,n){let{node:r}=i,o=r.openingElement.attributes,s=r.children,a=null,t=null;for(let m of o)if(e.isJSXAttribute(m)){let f=F(m);f==="when"?a=_(m.value):f==="fallback"&&(t=_(m.value))}if(!a)throw Z(i,n,'<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');let c=null;for(let m of s)if(e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)){c=m.expression;break}if(!c){n._pendingSetup||(n._pendingSetup=[]);let m=n._pendingSetup.length,f=[];for(let h of s)if(e.isJSXText(h)){let g=M(h.value);g&&f.push(e.stringLiteral(g))}else e.isJSXElement(h)&&f.push(X({node:h},n));f.length===1?c=f[0]:f.length>1?c=e.arrayExpression(f):c=e.nullLiteral();let x=n._pendingSetup.splice(m);x.length>0&&(c=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...x,e.returnStatement(c)])),[]))}let u=pe(a,n),E=i.scope?i.scope.generateUidIdentifier("v"):e.identifier("_v"),d=e.isFunction(c),l=d?e.callExpression(c,[e.cloneNode(E)]):c,p=t||e.nullLiteral();if(w(u,n.signalNames,n.importedIdentifiers)){let m=n.nextMemoId();n.needsMemo=!0;let f=d?u:e.unaryExpression("!",e.unaryExpression("!",u));n._pendingSetup||(n._pendingSetup=[]),n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(m),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],f)]))])),u=e.callExpression(e.identifier(m),[])}return e.arrowFunctionExpression([],e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(E,u)]),e.returnStatement(e.conditionalExpression(e.cloneNode(E),l,p))]))}function pe(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,o=a=>r&&r.has(a)||n.importedIdentifiers&&n.importedIdentifiers.has(a);if(e.isIdentifier(i))return o(i.name)?ue(i):n.signalNames&&J(i.name,n.signalNames)?e.callExpression(i,[]):i;let s=Le(i);return s&&o(s.name)?ue(i):i}function Le(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 ue(i){return e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",i),e.stringLiteral("function")),e.callExpression(e.cloneNode(i),[]),e.cloneNode(i))}function je(i,n){let r=[];for(let o of i)if(e.isJSXText(o)){let s=M(o.value);s&&r.push(e.stringLiteral(s))}else e.isJSXExpressionContainer(o)?e.isJSXEmptyExpression(o.expression)||r.push(o.expression):e.isJSXElement(o)?r.push(X({node:o},n)):e.isJSXFragment(o)&&r.push(P({node:o},n));return r.length===0?e.nullLiteral():r.length===1?r[0]:e.arrayExpression(r)}function Pe(i,n){let{node:r}=i,o=R(r.openingElement.name.name,n),s=f=>e.isJSXElement(f)&&e.isJSXIdentifier(f.openingElement.name,{name:"Match"})&&(o||!R("Match",n));if(!r.children.some(s)&&!xe(r.openingElement.name.name,n))return fe(i,n);let a=f=>{throw Z(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>`)},t=null;for(let f of r.openingElement.attributes)e.isJSXSpreadAttribute(f)&&a("cannot take a spread attribute"),F(f)==="fallback"&&(t=_(f.value));let c=[];for(let f of r.children){if(e.isJSXText(f)){M(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")}s(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 u=[];for(let f of c){let x=null;for(let v of f.openingElement.attributes)e.isJSXAttribute(v)&&F(v)==="when"&&(x=_(v.value));x||a('has a <Match> with no "when" prop');let h=n._pendingSetup.length,g=je(f.children,n),b=n._pendingSetup.splice(h);b.length>0&&(g=e.callExpression(e.arrowFunctionExpression([],e.blockStatement([...b,e.returnStatement(g)])),[])),u.push([pe(x,n),g])}let E=u.some(([f])=>w(f,n.signalNames,n.importedIdentifiers)),d=t||e.nullLiteral();if(!E){let f=d;for(let x=u.length-1;x>=0;x--)f=e.conditionalExpression(u[x][0],u[x][1],f);return e.arrowFunctionExpression([],f)}let l=e.numericLiteral(-1);for(let f=u.length-1;f>=0;f--)l=e.conditionalExpression(u[f][0],e.numericLiteral(f),l);let p=n.nextMemoId();n.needsMemo=!0,n._pendingSetup.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(p),e.callExpression(e.identifier("_$memo"),[e.arrowFunctionExpression([],l)]))]));let m=d;for(let f=u.length-1;f>=0;f--)m=e.conditionalExpression(e.binaryExpression("===",e.callExpression(e.identifier(p),[]),e.numericLiteral(f)),u[f][1],m);return e.arrowFunctionExpression([],m)}function de(i,n){n._pendingSetup||(n._pendingSetup=[]);let r=n._pendingSetup,o=se(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=j(o.body,r,n),o;if(a)return o;let c=j(o,r,n);return e.arrowFunctionExpression([],c)}return e.isCallExpression(i)&&e.isIdentifier(i.callee)&&(i.callee.name==="mapArray"||i.callee.name==="_$mapArray")?(n.needsMapArray=!0,i.callee.name==="mapArray"&&(i.callee.name="_$mapArray"),i):w(i,n.signalNames,n.importedIdentifiers)?(i=j(i,r,n),e.arrowFunctionExpression([],i)):i}function P(i,n){let{node:r}=i,o=r.children,s=[];for(let a of o)if(e.isJSXText(a)){let t=M(a.value);t&&s.push(e.stringLiteral(t))}else e.isJSXExpressionContainer(a)?e.isJSXEmptyExpression(a.expression)||s.push(de(a.expression,n)):e.isJSXElement(a)?s.push(X({node:a},n)):e.isJSXFragment(a)&&s.push(P({node:a},n));return s.length===1?s[0]:e.arrayExpression(s)}function me(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 Ee(i,n,r){let o=i.scope,s=n._signalNamesCache;s||(s=n._signalNamesCache=new WeakMap);let a=s.get(o);a||(a=_e(i),s.set(o,a)),n.signalNames=a,n._pendingSetup=[];let t=r(i,n),c=n._pendingSetup;if(n._pendingSetup=[],c.length>0){let u=i,E=!1,d=!1;for(;u&&!u.isStatement();)(u.isArrowFunctionExpression()||u.isFunctionExpression())&&(E=!0),Je(u)&&(d=!0),u=u.parentPath;u&&u.isStatement()&&(u.listKey==="body"||u.listKey==="consequent")&&Array.isArray(u.container)&&!E&&!d?(u.insertBefore(c),i.replaceWith(t)):(c.push(e.returnStatement(t)),i.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(c)),[])))}else i.replaceWith(t)}function Te(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 Oe(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 Re(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 he(i,n,r,o,s){let a=i.node.loc?.start||{line:0,column:0},t=`${s}:${a.line}:${a.column+1}`,c=`${s}#${o}`,u=n.serverActionIds.get(r);if(u)throw i.buildCodeFrameError(`Duplicate server action ID "${r}". First declared by "${u.bindingName}" at ${u.source}; conflicts with "${o}" at ${t}.`);let E={id:r,key:c,bindingName:o,filename:s,source:t,loc:a};if(n.serverActionIds.set(r,E),typeof n.opts?.onActionId=="function")try{n.opts.onActionId(E)}catch(d){throw i.buildCodeFrameError(d instanceof Error?d.message:String(d))}}function Ve(i,n){if(!Oe(i,n))return;let r=Te(i);if(!r){n.opts?.production||console.warn(`[what-compiler] Could not derive a stable server action ID at ${n.serverActionFilename}:${i.node.loc?.start.line||0}. Assign action(...) to a named local or export, or pass { id } explicitly.`);return}let o=i.node.arguments[1],s=Re(o);if(s.property){s.value!==null&&he(i,n,s.value,r,n.serverActionFilename);return}let a=`wa1_${Ze(`${n.serverActionFilename}#${r}`)}`;he(i,n,a,r,n.serverActionFilename);let t=e.objectProperty(e.identifier("id"),e.stringLiteral(a));o?e.isObjectExpression(o)?o.properties.unshift(t):i.node.arguments[1]=e.objectExpression([t,e.spreadElement(o)]):i.node.arguments.push(e.objectExpression([t]))}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=Qe(n.file?.opts?.filename,n.opts?.projectRoot||n.file?.opts?.cwd),n.signalNames=new Set,n.importedIdentifiers=new Set,n.whatImports=new Set,n.foreignImports=new Set;for(let r of i.node.body)if(e.isImportDeclaration(r)){let o=r.source.value,s=Se(o),a=s||o.startsWith("./")||o.startsWith("../");for(let t of r.specifiers){let c=null;(e.isImportSpecifier(t)&&e.isIdentifier(t.local)||e.isImportDefaultSpecifier(t)&&e.isIdentifier(t.local)||e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local))&&(c=t.local.name),c&&((a||/^(use|create)[A-Z]/.test(c))&&n.importedIdentifiers.add(c),s?n.whatImports.add(c):o.startsWith(".")||n.foreignImports.add(c)),Ke.has(o)&&(e.isImportSpecifier(t)&&e.isIdentifier(t.imported,{name:"action"})&&e.isIdentifier(t.local)?n.serverActionBindings.add(t.local.name):e.isImportNamespaceSpecifier(t)&&e.isIdentifier(t.local)&&n.serverActionNamespaces.add(t.local.name))}}i.traverse({Function(r){we(r)},CallExpression(r){Ve(r,n)},VariableDeclarator(r){let o=r.node.init;if(!o||!e.isCallExpression(o))return;let s=o.callee,a="";if(e.isIdentifier(s)?a=s.name:e.isMemberExpression(s)&&e.isIdentifier(s.property)&&(a=s.property.name),ge.has(a)){let t=r.node.id;if(e.isIdentifier(t))n.signalNames.add(t.name);else if(e.isArrayPattern(t))for(let c of t.elements)e.isIdentifier(c)&&n.signalNames.add(c.name);else if(e.isObjectPattern(t))for(let c of t.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&n.signalNames.add(c.value.name)}}})},exit(i,n){for(let s of n.templates.reverse()){let a=e.callExpression(e.identifier("_$template"),[e.stringLiteral(s.html)]);e.addComment(a,"leading"," @__PURE__ "),i.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(s.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 o=[];if(n.needsH&&o.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),n.needsFragment&&o.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),n.needsIsland&&o.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let s=null;for(let a of i.node.body)if(e.isImportDeclaration(a)&&(a.source.value==="what-framework/render"||a.source.value==="what-core/render")){s=a;break}if(s){let a=new Set(s.specifiers.filter(t=>e.isImportSpecifier(t)).map(t=>t.imported.name));for(let t of r)a.has(t.imported.name)||s.specifiers.push(t)}else i.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(o.length>0&&en(i,e,o),n.needsDelegation&&n.delegatedEvents&&n.delegatedEvents.size>0){let s=e.arrayExpression([...n.delegatedEvents].map(t=>e.stringLiteral(t))),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"),[s]))]));i.unshiftContainer("body",[e.variableDeclaration("let",[e.variableDeclarator(e.identifier("_$delegated$"),e.booleanLiteral(!1))]),a])}}},JSXElement(i,n){Ee(i,n,X)},JSXFragment(i,n){Ee(i,n,P)}}}}function en(e,A,k){let $=null;for(let y of e.node.body)if(A.isImportDeclaration(y)&&(y.source.value==="what-core"||y.source.value==="what-framework")){$=y;break}if($){let y=new Set($.specifiers.filter(C=>A.isImportSpecifier(C)).map(C=>C.imported.name));for(let C of k)y.has(C.imported.name)||$.specifiers.push(C)}else{let y=A.importDeclaration(k,A.stringLiteral("what-framework"));e.unshiftContainer("body",y)}}export{Ye as default};
|
|
1
|
+
// src/babel-plugin.js
|
|
2
|
+
import { t as o, setTypes as I } from "./babel/types.min.js";
|
|
3
|
+
import { deferPlacedProps as g, keepCleanupValues as E, liveHelperArgs as R, lowerLiveReturns as A, markHookResults as k, memoBranchValues as y, memoLiveLets as F, markPropFieldReads as C, readPropFields as J, warnDerivedPropOnce as N, warnLiveCleanup as T, warnStateReadOnce as _, initFileState as b, isComponentElement as x, isWhatModuleSource as B, recordName as D, spreadChildren as M, unwrapHostSpreads as X } from "./babel/common.min.js";
|
|
4
|
+
import { initDomState as L, finishDomProgram as O, transformJsxRoot as u, mayBuildTag as $ } from "./babel/dom.min.js";
|
|
5
|
+
import { initSsrState as V, finishSsrProgram as W, transformSsrRoot as S } from "./babel/ssr.min.js";
|
|
6
|
+
import { SERVER_ACTION_SOURCES as j, normalizeActionFilename as z, transformServerAction as Z } from "./babel/server-actions.min.js";
|
|
7
|
+
import { annotatePrimitive as H } from "./babel/dev-metadata.min.js";
|
|
8
|
+
import { resolveCallees as K } from "./babel/reactivity.min.js";
|
|
9
|
+
import { markRowKey as U } from "./babel/lists.min.js";
|
|
10
|
+
import { fileRuntimeMismatch as q } from "./release.min.js";
|
|
11
|
+
import { isFrameworkModule as G } from "./framework-files.min.js";
|
|
12
|
+
var v = "what-react", Q = /* @__PURE__ */ new Set(["_$translated", "_$inReact", "_$renderNative"]);
|
|
13
|
+
function Y(l) {
|
|
14
|
+
let r = l.node.body;
|
|
15
|
+
return o.isBlockStatement(r) && r.directives.some((e) => e.value.value === v);
|
|
16
|
+
}
|
|
17
|
+
function h(l) {
|
|
18
|
+
let r = l.node.openingElement.name;
|
|
19
|
+
if (!o.isJSXIdentifier(r) || !/^[A-Z]/.test(r.name)) return null;
|
|
20
|
+
let e = l.scope.getBinding(r.name);
|
|
21
|
+
if (!e || !e.constant || !o.isVariableDeclarator(e.path.node)) return null;
|
|
22
|
+
let c = e.path.node.init;
|
|
23
|
+
return o.isStringLiteral(c) && /^[a-z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$/.test(c.value) ? c.value : null;
|
|
24
|
+
}
|
|
25
|
+
function P({ types: l }) {
|
|
26
|
+
return I(l), {
|
|
27
|
+
name: "what-jsx-transform",
|
|
28
|
+
visitor: {
|
|
29
|
+
Program: {
|
|
30
|
+
enter(r, e) {
|
|
31
|
+
let c = q(e.file?.opts?.filename);
|
|
32
|
+
if (c) throw c;
|
|
33
|
+
let d = e.opts?.generate ?? "dom";
|
|
34
|
+
if (d !== "dom" && d !== "ssr")
|
|
35
|
+
throw new Error(`[what-compiler] Unknown "generate" option ${JSON.stringify(d)}: use "dom" or "ssr".`);
|
|
36
|
+
e.ssr = d === "ssr", b(e), e.frameworkFile = e.opts?.appSource !== !0 && G(e.file?.opts?.filename), e.ssr ? V(e) : L(e), e.serverActionBindings = /* @__PURE__ */ new Set(), e.serverActionNamespaces = /* @__PURE__ */ new Set(), e.serverActionIds = /* @__PURE__ */ new Map(), e.serverActionFilename = z(
|
|
37
|
+
e.file?.opts?.filename,
|
|
38
|
+
e.opts?.projectRoot || e.file?.opts?.cwd
|
|
39
|
+
), e.importedIdentifiers = /* @__PURE__ */ new Set(), e.whatImports = /* @__PURE__ */ new Set(), e.foreignImports = /* @__PURE__ */ new Set();
|
|
40
|
+
let a = /* @__PURE__ */ new Set();
|
|
41
|
+
e.translatedMarks = /* @__PURE__ */ new Set();
|
|
42
|
+
for (let i of r.node.body)
|
|
43
|
+
if (o.isImportDeclaration(i)) {
|
|
44
|
+
let s = i.source.value, f = B(s), w = f || s.startsWith("./") || s.startsWith("../");
|
|
45
|
+
for (let n of i.specifiers) {
|
|
46
|
+
let m = null;
|
|
47
|
+
if ((o.isImportSpecifier(n) && o.isIdentifier(n.local) || o.isImportDefaultSpecifier(n) && o.isIdentifier(n.local) || o.isImportNamespaceSpecifier(n) && o.isIdentifier(n.local)) && (m = n.local.name), m && s === "what-react/translated" && o.isImportSpecifier(n)) {
|
|
48
|
+
let p = n.imported.name ?? n.imported.value;
|
|
49
|
+
p === "_$hostProps" ? a.add(m) : Q.has(p) && e.translatedMarks.add(m);
|
|
50
|
+
}
|
|
51
|
+
m && ((w || /^(use|create)[A-Z]/.test(m)) && e.importedIdentifiers.add(m), f ? e.whatImports.add(m) : s.startsWith(".") || e.foreignImports.add(m)), j.has(s) && (o.isImportSpecifier(n) && o.isIdentifier(n.imported, { name: "action" }) && o.isIdentifier(n.local) ? e.serverActionBindings.add(n.local.name) : o.isImportNamespaceSpecifier(n) && o.isIdentifier(n.local) && e.serverActionNamespaces.add(n.local.name));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
X(r, a), o.traverseFast(r.node, (i) => {
|
|
55
|
+
(i.type === "Identifier" || i.type === "JSXIdentifier") && D(e, i.name);
|
|
56
|
+
}), e.ssr || o.traverseFast(r.node, (i) => {
|
|
57
|
+
i.type === "JSXElement" && o.isJSXIdentifier(i.openingElement.name, { name: "noscript" }) && (i.children = []);
|
|
58
|
+
}), r.traverse({
|
|
59
|
+
JSXElement(i) {
|
|
60
|
+
U(i, e);
|
|
61
|
+
let s = h(i);
|
|
62
|
+
s === null && !e.ssr && x(i.node) && (i.node._whatMayBuildTag = $(i.scope, i.node.openingElement.name)), s !== null && (i.node.openingElement.name = o.jsxIdentifier(s), i.node.closingElement && (i.node.closingElement.name = o.jsxIdentifier(s)));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
let t = [];
|
|
66
|
+
r.traverse({
|
|
67
|
+
Function(i) {
|
|
68
|
+
if (Y(i)) {
|
|
69
|
+
i.node.body.directives = i.node.body.directives.filter((s) => s.value.value !== v), i.skip();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
k(i, e), T(i, e), F(i, e), y(i, e), N(i, e), A(i, e), g(i, e), R(i, e), E(i, e), _(i, e), C(i, e);
|
|
73
|
+
},
|
|
74
|
+
CallExpression(i) {
|
|
75
|
+
e.frameworkFile || (Z(i, e), H(i, e)), t.push(i);
|
|
76
|
+
},
|
|
77
|
+
OptionalCallExpression(i) {
|
|
78
|
+
t.push(i);
|
|
79
|
+
}
|
|
80
|
+
}), r.traverse({
|
|
81
|
+
JSXElement(i) {
|
|
82
|
+
M(i, e);
|
|
83
|
+
}
|
|
84
|
+
}), K(r, t, e.importedIdentifiers);
|
|
85
|
+
},
|
|
86
|
+
exit(r, e) {
|
|
87
|
+
e.ssr ? W(r, e) : (J(r, e), O(r, e));
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
JSXElement(r, e) {
|
|
91
|
+
e.ssr ? S(r, e) : u(r, e);
|
|
92
|
+
},
|
|
93
|
+
JSXFragment(r, e) {
|
|
94
|
+
e.ssr ? S(r, e) : u(r, e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
P as default
|
|
101
|
+
};
|
package/dist/file-router.min.js
CHANGED
|
@@ -1,13 +1,369 @@
|
|
|
1
|
-
|
|
1
|
+
// src/file-router.js
|
|
2
|
+
import y from "fs";
|
|
3
|
+
import m from "path";
|
|
4
|
+
var E = /* @__PURE__ */ new Set([".jsx", ".tsx", ".js", ".ts"]), M = /* @__PURE__ */ new Set(["_layout", "_error", "_loading", "_404"]);
|
|
5
|
+
function C(t) {
|
|
6
|
+
let i = [], e = [], o = [];
|
|
7
|
+
function s(n, l = "") {
|
|
8
|
+
if (!y.existsSync(n)) return;
|
|
9
|
+
let u = y.readdirSync(n, { withFileTypes: !0 });
|
|
10
|
+
for (let p of u) {
|
|
11
|
+
let c = m.join(n, p.name);
|
|
12
|
+
if (p.isDirectory()) {
|
|
13
|
+
if (p.name.match(/^\((.+)\)$/)) {
|
|
14
|
+
s(c, l);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (p.name === "api" && l === "") {
|
|
18
|
+
r(c, "/api");
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
s(c, l + "/" + x(p.name));
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
let a = m.extname(p.name);
|
|
25
|
+
if (!E.has(a)) continue;
|
|
26
|
+
let h = m.basename(p.name, a);
|
|
27
|
+
if (h === "_layout") {
|
|
28
|
+
e.push({
|
|
29
|
+
filePath: c,
|
|
30
|
+
urlPrefix: l || "/"
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (M.has(h)) continue;
|
|
35
|
+
let f = x(h), d = h === "index" ? l || "/" : l + "/" + f;
|
|
36
|
+
i.push({
|
|
37
|
+
filePath: c,
|
|
38
|
+
routePath: _(d),
|
|
39
|
+
isDynamic: d.includes(":") || d.includes("*")
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function r(n, l) {
|
|
44
|
+
if (!y.existsSync(n)) return;
|
|
45
|
+
let u = y.readdirSync(n, { withFileTypes: !0 });
|
|
46
|
+
for (let p of u) {
|
|
47
|
+
let c = m.join(n, p.name);
|
|
48
|
+
if (p.isDirectory()) {
|
|
49
|
+
r(c, l + "/" + x(p.name));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
let a = m.extname(p.name);
|
|
53
|
+
if (!E.has(a)) continue;
|
|
54
|
+
let h = m.basename(p.name, a), f = x(h), d = h === "index" ? l : l + "/" + f;
|
|
55
|
+
o.push({
|
|
56
|
+
filePath: c,
|
|
57
|
+
routePath: _(d)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return s(t), i.sort((n, l) => {
|
|
62
|
+
let u = v(n.routePath), p = v(l.routePath);
|
|
63
|
+
return u - p;
|
|
64
|
+
}), { pages: i, layouts: e, apiRoutes: o };
|
|
65
|
+
}
|
|
66
|
+
function x(t) {
|
|
67
|
+
let i = t.match(/^\[\.\.\.(\w+)\]$/);
|
|
68
|
+
if (i) return "*" + i[1];
|
|
69
|
+
let e = t.match(/^\[(\w+)\]$/);
|
|
70
|
+
return e ? ":" + e[1] : t.toLowerCase();
|
|
71
|
+
}
|
|
72
|
+
function _(t) {
|
|
73
|
+
let i = t.replace(/\/+/g, "/");
|
|
74
|
+
return i.length > 1 && i.endsWith("/") && (i = i.slice(0, -1)), i || "/";
|
|
75
|
+
}
|
|
76
|
+
function v(t) {
|
|
77
|
+
return t.includes("*") ? 100 : t.includes(":") ? 10 : 0;
|
|
78
|
+
}
|
|
79
|
+
var I = /export\s+const\s+page\s*=\s*\{/;
|
|
80
|
+
function N(t, i = {}) {
|
|
81
|
+
let e = I.exec(t);
|
|
82
|
+
if (!e)
|
|
83
|
+
return { mode: "client" };
|
|
84
|
+
let o = e.index + e[0].length - 1;
|
|
85
|
+
try {
|
|
86
|
+
return { mode: "client", ...JSON.parse(G(t, o)) };
|
|
87
|
+
} catch (s) {
|
|
88
|
+
return R(s, i.filePath), { mode: "client" };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function R(t, i) {
|
|
92
|
+
let e = i ? ` in ${i}` : "";
|
|
93
|
+
console.warn(
|
|
94
|
+
`[what] Ignoring unparseable \`export const page\` config${e}: ${t.message}
|
|
2
95
|
This page falls back to mode 'client', so static generation will skip it.
|
|
3
|
-
\`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
96
|
+
\`page\` must be a plain object literal of JSON-shaped values (strings, numbers, booleans, null, arrays, nested objects).`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
var k = (t) => /[A-Za-z_$]/.test(t), A = (t) => /[A-Za-z0-9_$]/.test(t);
|
|
100
|
+
function G(t, i) {
|
|
101
|
+
let e = [], o = -1, s = 0, r = i;
|
|
102
|
+
for (; r < t.length; ) {
|
|
103
|
+
let n = t[r];
|
|
104
|
+
if (n === "/" && t[r + 1] === "/") {
|
|
105
|
+
let l = t.indexOf(`
|
|
106
|
+
`, r);
|
|
107
|
+
r = l === -1 ? t.length : l, e.push(" ");
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (n === "/" && t[r + 1] === "*") {
|
|
111
|
+
let l = t.indexOf("*/", r + 2);
|
|
112
|
+
if (l === -1) throw new SyntaxError("unterminated block comment");
|
|
113
|
+
r = l + 2, e.push(" ");
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (n === '"' || n === "'" || n === "`") {
|
|
117
|
+
let l = F(t, r);
|
|
118
|
+
e.push(JSON.stringify(l.value)), o = -1, r = l.end;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (k(n)) {
|
|
122
|
+
let l = r + 1;
|
|
123
|
+
for (; l < t.length && A(t[l]); ) l++;
|
|
124
|
+
let u = t.slice(r, l);
|
|
125
|
+
e.push(T(t, l) ? JSON.stringify(u) : u), o = -1, r = l;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (n === " " || n === " " || n === `
|
|
129
|
+
` || n === "\r") {
|
|
130
|
+
e.push(n), r++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (n === ",") {
|
|
134
|
+
e.push(","), o = e.length - 1, r++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (n === "}" || n === "]") {
|
|
138
|
+
if (o !== -1 && (e[o] = ""), o = -1, e.push(n), r++, n === "}" && --s === 0) return e.join("");
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
n === "{" && s++, e.push(n), o = -1, r++;
|
|
142
|
+
}
|
|
143
|
+
throw new SyntaxError("unterminated object literal");
|
|
144
|
+
}
|
|
145
|
+
function T(t, i) {
|
|
146
|
+
let e = i;
|
|
147
|
+
for (; e < t.length; ) {
|
|
148
|
+
let o = t[e];
|
|
149
|
+
if (o === " " || o === " " || o === `
|
|
150
|
+
` || o === "\r") {
|
|
151
|
+
e++;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (o === "/" && t[e + 1] === "/") {
|
|
155
|
+
let s = t.indexOf(`
|
|
156
|
+
`, e);
|
|
157
|
+
if (s === -1) return !1;
|
|
158
|
+
e = s + 1;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (o === "/" && t[e + 1] === "*") {
|
|
162
|
+
let s = t.indexOf("*/", e + 2);
|
|
163
|
+
if (s === -1) return !1;
|
|
164
|
+
e = s + 2;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
return o === ":";
|
|
168
|
+
}
|
|
169
|
+
return !1;
|
|
170
|
+
}
|
|
171
|
+
var j = {
|
|
172
|
+
n: `
|
|
173
|
+
`,
|
|
174
|
+
t: " ",
|
|
175
|
+
r: "\r",
|
|
176
|
+
b: "\b",
|
|
177
|
+
f: "\f",
|
|
178
|
+
v: "\v",
|
|
179
|
+
0: "\0",
|
|
180
|
+
"\\": "\\",
|
|
181
|
+
"'": "'",
|
|
182
|
+
'"': '"',
|
|
183
|
+
"`": "`",
|
|
184
|
+
"/": "/"
|
|
185
|
+
};
|
|
186
|
+
function F(t, i) {
|
|
187
|
+
let e = t[i], o = "", s = i + 1;
|
|
188
|
+
for (; s < t.length; ) {
|
|
189
|
+
let r = t[s];
|
|
190
|
+
if (r === "\\") {
|
|
191
|
+
let n = t[s + 1];
|
|
192
|
+
if (n === void 0) break;
|
|
193
|
+
if (n === `
|
|
194
|
+
`) {
|
|
195
|
+
s += 2;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (n === "\r") {
|
|
199
|
+
s += t[s + 2] === `
|
|
200
|
+
` ? 3 : 2;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (n === "u") {
|
|
204
|
+
if (t[s + 2] === "{") {
|
|
205
|
+
let l = t.indexOf("}", s + 3);
|
|
206
|
+
if (l === -1) throw new SyntaxError("invalid unicode escape");
|
|
207
|
+
o += String.fromCodePoint(parseInt(t.slice(s + 3, l), 16)), s = l + 1;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
o += String.fromCharCode(parseInt(t.slice(s + 2, s + 6), 16)), s += 6;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (n === "x") {
|
|
214
|
+
o += String.fromCharCode(parseInt(t.slice(s + 2, s + 4), 16)), s += 4;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
o += Object.prototype.hasOwnProperty.call(j, n) ? j[n] : n, s += 2;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (r === e) return { value: o, end: s + 1 };
|
|
221
|
+
if (e === "`" && r === "$" && t[s + 1] === "{")
|
|
222
|
+
throw new SyntaxError("template literal interpolation cannot be resolved at build time");
|
|
223
|
+
if (e !== "`" && (r === `
|
|
224
|
+
` || r === "\r")) break;
|
|
225
|
+
if (r === "\r") {
|
|
226
|
+
o += `
|
|
227
|
+
`, s += t[s + 1] === `
|
|
228
|
+
` ? 2 : 1;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
o += r, s++;
|
|
232
|
+
}
|
|
233
|
+
throw new SyntaxError("unterminated string literal");
|
|
234
|
+
}
|
|
235
|
+
function L(t) {
|
|
236
|
+
return {
|
|
237
|
+
hasLoader: /export\s+(?:async\s+)?(?:const|let|var|function)\s+loader\b/.test(t),
|
|
238
|
+
hasGetStaticPaths: /export\s+(?:async\s+)?(?:const|let|var|function)\s+getStaticPaths\b/.test(t),
|
|
239
|
+
hasPageConfig: /export\s+const\s+page\b/.test(t),
|
|
240
|
+
hasPreload: /export\s+(?:async\s+)?(?:const|let|var|function)\s+preload\b/.test(t),
|
|
241
|
+
hasMiddleware: /export\s+(?:const|let|var)\s+middleware\b/.test(t)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function W(t, i) {
|
|
245
|
+
let e = [];
|
|
246
|
+
return t.hasPreload && e.push("preload"), t.hasMiddleware && e.push("middleware"), {
|
|
247
|
+
named: e.map((o) => `${o} as ${i}_${o}`).join(", "),
|
|
248
|
+
fields: e.map((o) => `, ${o}: ${i}_${o}`).join("")
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function D(t, i) {
|
|
252
|
+
let { pages: e, layouts: o, apiRoutes: s } = C(t), r = [], n = [], l = o.map((c, a) => {
|
|
253
|
+
let h = `_layout${a}`, f = w(c.filePath, i);
|
|
254
|
+
return r.push(`import ${h} from '${f}';`), { dir: m.dirname(c.filePath), name: h };
|
|
255
|
+
});
|
|
256
|
+
e.forEach((c, a) => {
|
|
257
|
+
let h = `_page${a}`, f = w(c.filePath, i), d = { mode: "client" }, $ = { hasLoader: !1, hasGetStaticPaths: !1, hasPageConfig: !1, hasPreload: !1, hasMiddleware: !1 };
|
|
258
|
+
try {
|
|
259
|
+
let S = y.readFileSync(c.filePath, "utf-8");
|
|
260
|
+
d = N(S, { filePath: c.filePath }), $ = L(S);
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
let P = W($, h);
|
|
264
|
+
r.push(P.named ? `import ${h}, { ${P.named} } from '${f}';` : `import ${h} from '${f}';`);
|
|
265
|
+
let g = {
|
|
266
|
+
path: c.routePath,
|
|
267
|
+
component: h,
|
|
268
|
+
mode: d.mode || "client",
|
|
269
|
+
layout: O(c.filePath, l),
|
|
270
|
+
own: P.fields,
|
|
271
|
+
hasLoader: $.hasLoader
|
|
272
|
+
};
|
|
273
|
+
n.push(g);
|
|
274
|
+
});
|
|
275
|
+
let u = [];
|
|
276
|
+
return s.forEach((c, a) => {
|
|
277
|
+
let h = `_api${a}`, f = w(c.filePath, i);
|
|
278
|
+
r.push(`import * as ${h} from '${f}';`), u.push({
|
|
279
|
+
path: c.routePath,
|
|
280
|
+
handlers: h
|
|
281
|
+
});
|
|
282
|
+
}), [
|
|
283
|
+
"// Auto-generated by What Framework file router",
|
|
284
|
+
"// Do not edit \u2014 changes will be overwritten",
|
|
285
|
+
"",
|
|
286
|
+
...r,
|
|
287
|
+
"",
|
|
288
|
+
"export const routes = [",
|
|
289
|
+
...n.map(
|
|
290
|
+
(c) => ` { path: '${c.path}', component: ${c.component}, mode: '${c.mode}'${c.layout ? `, layout: ${c.layout}` : ""}${c.own}${c.hasLoader ? ", hasLoader: true" : ""} },`
|
|
291
|
+
),
|
|
292
|
+
"];",
|
|
293
|
+
"",
|
|
294
|
+
"export const apiRoutes = [",
|
|
295
|
+
...u.map(
|
|
296
|
+
(c) => ` { path: '${c.path}', handlers: ${c.handlers} },`
|
|
297
|
+
),
|
|
298
|
+
"];",
|
|
299
|
+
"",
|
|
300
|
+
// Export page modes for the build system
|
|
301
|
+
"export const pageModes = {",
|
|
302
|
+
...n.map(
|
|
303
|
+
(c) => ` '${c.path}': '${c.mode}',`
|
|
304
|
+
),
|
|
305
|
+
"};"
|
|
306
|
+
].join(`
|
|
307
|
+
`);
|
|
308
|
+
}
|
|
309
|
+
function V(t, i) {
|
|
310
|
+
let { pages: e, layouts: o, apiRoutes: s } = C(t), r = [], n = [], l = o.map((a, h) => {
|
|
311
|
+
let f = `_layout${h}`;
|
|
312
|
+
return r.push(`import ${f} from '${w(a.filePath, i)}';`), { dir: m.dirname(a.filePath), name: f };
|
|
313
|
+
});
|
|
314
|
+
e.forEach((a, h) => {
|
|
315
|
+
let f = `_page${h}`, d = `_page${h}_ns`, $ = w(a.filePath, i), P = { mode: "client" }, g = { hasLoader: !1, hasGetStaticPaths: !1, hasPageConfig: !1, hasPreload: !1, hasMiddleware: !1 };
|
|
316
|
+
try {
|
|
317
|
+
let b = y.readFileSync(a.filePath, "utf-8");
|
|
318
|
+
P = N(b, { filePath: a.filePath }), g = L(b);
|
|
319
|
+
} catch {
|
|
320
|
+
}
|
|
321
|
+
g.hasLoader || g.hasGetStaticPaths || g.hasPageConfig || g.hasPreload || g.hasMiddleware ? r.push(`import ${f}, * as ${d} from '${$}';`) : r.push(`import ${f} from '${$}';`), n.push({
|
|
322
|
+
path: a.routePath,
|
|
323
|
+
component: f,
|
|
324
|
+
ns: d,
|
|
325
|
+
mode: P.mode || "client",
|
|
326
|
+
layout: O(a.filePath, l),
|
|
327
|
+
...g
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
let u = [];
|
|
331
|
+
s.forEach((a, h) => {
|
|
332
|
+
let f = `_api${h}`;
|
|
333
|
+
r.push(`import * as ${f} from '${w(a.filePath, i)}';`), u.push({ path: a.routePath, handlers: f });
|
|
334
|
+
});
|
|
335
|
+
let p = (a) => ` { path: '${a.path}', component: ${a.component}, mode: '${a.mode}'${a.layout ? `, layout: ${a.layout}` : ""}${a.hasPreload ? `, preload: ${a.ns}.preload` : ""}${a.hasMiddleware ? `, middleware: ${a.ns}.middleware` : ""}${a.hasLoader ? `, loader: ${a.ns}.loader` : ""}${a.hasGetStaticPaths ? `, getStaticPaths: ${a.ns}.getStaticPaths` : ""}${a.hasPageConfig ? `, page: ${a.ns}.page` : ""} },`;
|
|
336
|
+
return [
|
|
337
|
+
"// Auto-generated by What Framework file router (server)",
|
|
338
|
+
"// Do not edit \u2014 changes will be overwritten",
|
|
339
|
+
"",
|
|
340
|
+
...r,
|
|
341
|
+
"",
|
|
342
|
+
"export const routes = [",
|
|
343
|
+
...n.map(p),
|
|
344
|
+
"];",
|
|
345
|
+
"",
|
|
346
|
+
"export const apiRoutes = [",
|
|
347
|
+
...u.map((a) => ` { path: '${a.path}', handlers: ${a.handlers} },`),
|
|
348
|
+
"];",
|
|
349
|
+
"",
|
|
350
|
+
"export const pageModes = {",
|
|
351
|
+
...n.map((a) => ` '${a.path}': '${a.mode}',`),
|
|
352
|
+
"};"
|
|
353
|
+
].join(`
|
|
354
|
+
`);
|
|
355
|
+
}
|
|
356
|
+
function w(t, i) {
|
|
357
|
+
return "/" + m.relative(i, t).split(m.sep).join("/");
|
|
358
|
+
}
|
|
359
|
+
function O(t, i) {
|
|
360
|
+
let e = i.filter((o) => t.startsWith(o.dir + m.sep)).sort((o, s) => o.dir.length - s.dir.length).map((o) => o.name);
|
|
361
|
+
return e.length === 0 ? null : e.length === 1 ? e[0] : `[${e.join(", ")}]`;
|
|
362
|
+
}
|
|
363
|
+
export {
|
|
364
|
+
L as detectPageExports,
|
|
365
|
+
N as extractPageConfig,
|
|
366
|
+
D as generateRoutesModule,
|
|
367
|
+
V as generateServerRoutesModule,
|
|
368
|
+
C as scanPages
|
|
369
|
+
};
|