what-compiler 0.5.5 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/babel-plugin.js +1307 -0
- package/dist/babel-plugin.js.map +7 -0
- package/dist/babel-plugin.min.js +2 -0
- package/dist/babel-plugin.min.js.map +7 -0
- package/dist/file-router.js +195 -0
- package/dist/file-router.js.map +7 -0
- package/dist/file-router.min.js +3 -0
- package/dist/file-router.min.js.map +7 -0
- package/dist/index.js +2065 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.js +397 -0
- package/dist/index.min.js.map +7 -0
- package/dist/runtime.js +9 -0
- package/dist/runtime.js.map +7 -0
- package/dist/runtime.min.js +2 -0
- package/dist/runtime.min.js.map +7 -0
- package/dist/vite-plugin.js +2054 -0
- package/dist/vite-plugin.js.map +7 -0
- package/dist/vite-plugin.min.js +397 -0
- package/dist/vite-plugin.min.js.map +7 -0
- package/package.json +26 -10
- package/src/babel-plugin.js +943 -559
- package/src/error-overlay.js +190 -119
- package/src/file-router.js +2 -1
- package/src/vite-plugin.js +86 -3
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
var xe=new Set(["preventDefault","stopPropagation","once","capture","passive","self"]),Ee=new Set(["once","capture","passive"]),be=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Se=new Set(["click","input","change","keydown","keyup","submit","focusin","focusout","mousedown","mouseup"]),R=new Set(["Math","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","JSON","Date","Array","Object","console","RegExp"]),te=new Set(["useSignal","signal","computed","useComputed","useState","useReducer","createResource","useSWR","useQuery","useInfiniteQuery"]);function W({types:e}){function f(n){let i=n.split("|"),r=i[0],t=i.slice(1).filter(a=>xe.has(a));return{eventName:r,modifiers:t}}function b(n){return n.startsWith("bind:")}function I(n){return n.slice(5)}function w(n){return/^[A-Z]/.test(n)}function P(n){return be.has(String(n).toLowerCase())}function v(n){return n?e.isJSXExpressionContainer(n)?n.expression:e.isStringLiteral(n)?n:e.stringLiteral(n.value||""):e.booleanLiteral(!0)}function C(n){return n==="className"?"class":n==="htmlFor"?"for":n}function L(n){return e.isJSXNamespacedName(n.name)?`${n.name.namespace.name}:${n.name.name.name}`:typeof n.name.name=="string"?n.name.name:String(n.name.name)}function $(n,i){if(i.length===0)return n;let r=n;for(let t of i)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 d(n,i){return i.has(n)}function m(n){let i=new Set;function r(a){let s=a.init;if(!s||!e.isCallExpression(s))return;let o=s.callee,c="";if(e.isIdentifier(o)?c=o.name:e.isMemberExpression(o)&&e.isIdentifier(o.property)&&(c=o.property.name),te.has(c)){let u=a.id;if(e.isIdentifier(u))i.add(u.name);else if(e.isArrayPattern(u))for(let S of u.elements)e.isIdentifier(S)&&i.add(S.name);else if(e.isObjectPattern(u))for(let S of u.properties)e.isObjectProperty(S)&&e.isIdentifier(S.value)&&i.add(S.value.name)}}let t=n.scope;for(;t;){for(let[a,s]of Object.entries(t.bindings))if(s.path.isVariableDeclarator()&&r(s.path.node),s.path.isIdentifier()||s.kind==="param"){let o=s.scope.path;if(o&&o.node&&o.node.params){for(let c of o.node.params)if(e.isObjectPattern(c))for(let u of c.properties)e.isObjectProperty(u)&&e.isIdentifier(u.value)?i.add(u.value.name):e.isRestElement(u)&&e.isIdentifier(u.argument)&&i.add(u.argument.name)}}t=t.parent}return i}function x(n){return m(n)}function g(n){if(!e.isCallExpression(n))return!1;let i=n.callee;return e.isMemberExpression(i)&&e.isIdentifier(i.object)?R.has(i.object.name):e.isIdentifier(i)?R.has(i.name):!1}function T(n,i,r){if(!i)return!1;if(e.isCallExpression(n)){if(e.isIdentifier(n.callee)&&d(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&d(n.callee.object.name,i)||g(n))return!1;if(n.arguments.some(t=>k(t,i,r)))return!0}return!1}function k(n,i,r){return i||(i=new Set),e.isCallExpression(n)?e.isIdentifier(n.callee)&&d(n.callee.name,i)||r&&e.isIdentifier(n.callee)&&r.has(n.callee.name)&&!R.has(n.callee.name)||e.isMemberExpression(n.callee)&&e.isIdentifier(n.callee.object)&&d(n.callee.object.name,i)?!0:g(n)?n.arguments.some(t=>k(t,i,r)):e.isIdentifier(n.callee)?n.arguments.some(t=>k(t,i,r)):k(n.callee,i,r)||n.arguments.some(t=>k(t,i,r)):e.isIdentifier(n)?d(n.name,i):e.isMemberExpression(n)?k(n.object,i,r):e.isConditionalExpression(n)?k(n.test,i,r)||k(n.consequent,i,r)||k(n.alternate,i,r):e.isBinaryExpression(n)||e.isLogicalExpression(n)?k(n.left,i,r)||k(n.right,i,r):e.isUnaryExpression(n)?k(n.argument,i,r):e.isTemplateLiteral(n)?n.expressions.some(t=>k(t,i,r)):e.isObjectExpression(n)?n.properties.some(t=>e.isObjectProperty(t)&&k(t.value,i,r)):e.isArrayExpression(n)?n.elements.some(t=>t&&k(t,i,r)):(e.isArrowFunctionExpression(n)||e.isFunctionExpression(n),!1)}function J(n){if(e.isJSXText(n))return!0;if(e.isJSXExpressionContainer(n))return!1;if(e.isJSXElement(n)){let i=n.openingElement,r=i.name.name;if(w(r))return!1;for(let t of i.attributes){if(e.isJSXSpreadAttribute(t))return!1;let a=t.value;if(e.isJSXExpressionContainer(a))return!1}return n.children.every(J)}return!1}function j(n){return e.isJSXSpreadAttribute(n)?!0:n.value?e.isJSXExpressionContainer(n.value):!1}function z(n){if(e.isJSXText(n)){let s=n.value.replace(/\n\s+/g," ").trim();return s?K(s):""}if(e.isJSXExpressionContainer(n))return e.isJSXEmptyExpression(n.expression)?"":"<!--$-->";if(!e.isJSXElement(n))return"";let i=n.openingElement,r=i.name.name;if(w(r))return"";let t=`<${r}`;for(let s of i.attributes){if(e.isJSXSpreadAttribute(s))continue;let o=L(s);if(o.startsWith("on")||o.startsWith("bind:")||o.includes("|"))continue;let c=o;if(o==="className"&&(c="class"),o==="htmlFor"&&(c="for"),!s.value)t+=` ${c}`;else if(e.isStringLiteral(s.value))t+=` ${c}="${ue(s.value.value)}"`;else if(e.isJSXExpressionContainer(s.value))continue}let a=n.openingElement.selfClosing;if(a&&P(r))return t+=">",t;if(a)return t+=`></${r}>`,t;t+=">";for(let s of n.children)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&(t+=K(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||(t+="<!--$-->"):e.isJSXElement(s)&&(w(s.openingElement.name.name)?t+="<!--$-->":t+=z(s));return t+=`</${r}>`,t}function K(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ue(n){return n.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function X(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name;if(w(a))return ie(n,i);if(a==="For")return de(n,i);if(a==="Show")return me(n,i);let s=t.attributes,o=r.children,c=o.every(J),u=s.every(E=>!j(E)),S=s.every(E=>{if(e.isJSXSpreadAttribute(E))return!1;let p=L(E);return!p?.startsWith("on")&&!p?.startsWith("bind:")});if(c&&u&&S){let E=z(r);if(E){let p=re(i,E);return i.needsTemplate=!0,e.callExpression(e.identifier(p),[])}}let y=z(r);if(!y){let E=r.loc,p=i.filename||i.file?.opts?.filename||"<unknown>",_=E?`:${E.start.line}:${E.start.column}`:"";return console.warn(`[what-compiler] Could not extract template for <${a}> at ${p}${_}. Falling back to h() for this element. This element could not be statically analyzed. Consider simplifying the JSX.`),i.needsH=!0,U(n,i)}let M=re(i,y);i.needsTemplate=!0;let l=i.nextVarId(),h=[e.variableDeclaration("const",[e.variableDeclarator(e.identifier(l),e.callExpression(e.identifier(M),[]))])];return ee(h,l,s,i),ne(h,l,o,r,i),i._pendingSetup||(i._pendingSetup=[]),i._pendingSetup.push(...h),e.identifier(l)}function U(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,c=[];for(let y of s){if(e.isJSXSpreadAttribute(y))continue;let M=L(y),l=v(y.value),h=C(M);c.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h)?e.identifier(h):e.stringLiteral(h),l))}let u=[];for(let y of o)if(e.isJSXText(y)){let M=y.value.replace(/\n\s+/g," ").trim();M&&u.push(e.stringLiteral(M))}else e.isJSXExpressionContainer(y)?e.isJSXEmptyExpression(y.expression)||u.push(y.expression):e.isJSXElement(y)?u.push(X({node:y},i)):e.isJSXFragment(y)&&u.push(H({node:y},i));let S=c.length>0?e.objectExpression(c):e.nullLiteral();return e.callExpression(e.identifier("h"),[e.stringLiteral(a),S,...u])}function ee(n,i,r,t){function a(s,o){return t.needsSetProp=!0,e.callExpression(e.identifier("_$setProp"),[e.identifier(i),e.stringLiteral(s),o])}for(let s of r){if(e.isJSXSpreadAttribute(s)){t.needsSpread=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$spread"),[e.identifier(i),s.argument])));continue}let o=L(s);if(o==="ref"){let c=v(s.value);n.push(e.expressionStatement(e.conditionalExpression(e.binaryExpression("===",e.unaryExpression("typeof",c),e.stringLiteral("function")),e.callExpression(e.cloneNode(c),[e.identifier(i)]),e.assignmentExpression("=",e.memberExpression(e.cloneNode(c),e.identifier("current")),e.identifier(i)))));continue}if(o.startsWith("on")&&!o.includes("|")){let c=o.slice(2).toLowerCase(),u=v(s.value);Se.has(c)?(t.needsDelegation=!0,t.delegatedEvents||(t.delegatedEvents=new Set),t.delegatedEvents.add(c),n.push(e.expressionStatement(e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier(`__${c}`)),u)))):n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral(c),u])));continue}if(o.startsWith("on")&&o.includes("|")){let{eventName:c,modifiers:u}=f(o),S=v(s.value),y=$(S,u),M=c.slice(2).toLowerCase(),l=u.filter(E=>Ee.has(E)),h=[e.stringLiteral(M),y];if(l.length>0){let E=l.map(p=>e.objectProperty(e.identifier(p),e.booleanLiteral(!0)));h.push(e.objectExpression(E))}n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),h)));continue}if(b(o)){let c=I(o),u=s.value.expression;t.needsEffect=!0,c==="value"?(n.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier("value")),e.callExpression(e.cloneNode(u),[])))]))),n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral("input"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(u),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))])))):c==="checked"&&(t.needsEffect=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],e.assignmentExpression("=",e.memberExpression(e.identifier(i),e.identifier("checked")),e.callExpression(e.cloneNode(u),[])))]))),n.push(e.expressionStatement(e.callExpression(e.memberExpression(e.identifier(i),e.identifier("addEventListener")),[e.stringLiteral("change"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(u),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))]))]))));continue}if(e.isJSXExpressionContainer(s.value)){let c=s.value.expression,u=C(o);if(k(c,t.signalNames,t.importedIdentifiers)){t.needsEffect=!0;let S=e.callExpression(e.identifier("_$effect"),[e.arrowFunctionExpression([],a(u,c))]);T(c,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),n.push(e.expressionStatement(S))}else n.push(e.expressionStatement(a(u,c)))}}}function ne(n,i,r,t,a){let s=[],o=0;for(let l of r){if(e.isJSXText(l)){l.value.replace(/\n\s+/g," ").trim()&&o++;continue}if(e.isJSXExpressionContainer(l)){if(e.isJSXEmptyExpression(l.expression))continue;s.push({type:"expression",child:l,childIndex:o}),o++;continue}if(e.isJSXElement(l)){let h=l.openingElement.name.name;if(w(h)||h==="For"||h==="Show")s.push({type:"component",child:l,childIndex:o}),o++;else{let E=l.openingElement.attributes.some(j)||l.openingElement.attributes.some(p=>!e.isJSXSpreadAttribute(p)&&L(p)?.startsWith("on"))||!l.children.every(J);s.push({type:"static",child:l,childIndex:o,hasAnythingDynamic:E}),o++}continue}e.isJSXFragment(l)&&s.push({type:"fragment",child:l})}let c=s.filter(l=>l.type==="expression"||l.type==="component"||l.type==="static"&&l.hasAnythingDynamic),u=s.some(l=>l.type==="expression"||l.type==="component"),S=c.length>=2&&u,y=new Map;if(S)for(let l of c){let h=`_m$${l.childIndex}`,E=a.nextVarId();y.set(l.childIndex,E),n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),G(i,l.childIndex))]))}function M(l){return y.has(l)?e.identifier(y.get(l)):G(i,l)}for(let l of s){if(l.type==="expression"){let h=l.child.expression,E=M(l.childIndex);if(a.needsInsert=!0,k(h,a.signalNames,a.importedIdentifiers)){let p=e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],h),E]);T(h,a.signalNames,a.importedIdentifiers)&&e.addComment(p,"leading"," @what-dev: reactive wrapping may be unnecessary \u2014 expression contains a non-signal function call with reactive args ",!1),n.push(e.expressionStatement(p))}else n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),h,E])));continue}if(l.type==="component"){let h=X({node:l.child},a),E=M(l.childIndex);a.needsInsert=!0,n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),h,E])));continue}if(l.type==="static"&&l.hasAnythingDynamic){let h;y.has(l.childIndex)?h=y.get(l.childIndex):(h=a.nextVarId(),n.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(h),G(i,l.childIndex))]))),ee(n,h,l.child.openingElement.attributes,a),ne(n,h,l.child.children,l.child,a);continue}if(l.type==="fragment"){for(let h of l.child.children)if(e.isJSXExpressionContainer(h)&&!e.isJSXEmptyExpression(h.expression)){a.needsInsert=!0;let E=h.expression;k(E,a.signalNames,a.importedIdentifiers)?n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),e.arrowFunctionExpression([],E)]))):n.push(e.expressionStatement(e.callExpression(e.identifier("_$insert"),[e.identifier(i),E])))}}}}function G(n,i){if(i===0)return e.memberExpression(e.identifier(n),e.identifier("firstChild"));let r=e.memberExpression(e.identifier(n),e.identifier("firstChild"));for(let t=0;t<i;t++)r=e.memberExpression(r,e.identifier("nextSibling"));return r}function ie(n,i){let{node:r}=n,t=r.openingElement,a=t.name.name,s=t.attributes,o=r.children,c=null,u=[];for(let p of s){if(e.isJSXAttribute(p)){let _;if(e.isJSXNamespacedName(p.name)?_=`${p.name.namespace.name}:${p.name.name.name}`:_=p.name.name,_&&typeof _=="string"&&_.startsWith("client:")){let O=_.slice(7);p.value?c={type:O,value:p.value.value}:c={type:O};continue}}u.push(p)}if(c){i.needsCreateComponent=!0,i.needsIsland=!0;let p=[e.objectProperty(e.identifier("component"),e.identifier(a)),e.objectProperty(e.identifier("mode"),e.stringLiteral(c.type))];c.value&&p.push(e.objectProperty(e.identifier("mediaQuery"),e.stringLiteral(c.value)));for(let _ of u){if(e.isJSXSpreadAttribute(_))continue;let O=L(_),A=v(_.value);p.push(e.objectProperty(e.identifier(O),A))}return e.callExpression(e.identifier("_$createComponent"),[e.identifier("Island"),e.objectExpression(p),e.arrayExpression([])])}i.needsCreateComponent=!0;let S=[],y=!1,M=null;for(let p of u){if(e.isJSXSpreadAttribute(p)){y=!0,M=p.argument;continue}let _=L(p);if(b(_)){let A=I(_),N=p.value.expression;A==="value"?(S.push(e.objectProperty(e.identifier("value"),e.callExpression(e.cloneNode(N),[]))),S.push(e.objectProperty(e.identifier("onInput"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("value"))]))))):A==="checked"&&(S.push(e.objectProperty(e.identifier("checked"),e.callExpression(e.cloneNode(N),[]))),S.push(e.objectProperty(e.identifier("onChange"),e.arrowFunctionExpression([e.identifier("e")],e.callExpression(e.memberExpression(e.cloneNode(N),e.identifier("set")),[e.memberExpression(e.memberExpression(e.identifier("e"),e.identifier("target")),e.identifier("checked"))])))));continue}if(_.startsWith("on")&&_.includes("|")){let{eventName:A,modifiers:N}=f(_),he=v(p.value),ge=$(he,N);S.push(e.objectProperty(e.identifier(A),ge));continue}let O=v(p.value);S.push(e.objectProperty(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(_)?e.identifier(_):e.stringLiteral(_),O))}let l=[];for(let p of o)if(e.isJSXText(p)){let _=p.value.replace(/\n\s+/g," ").trim();_&&l.push(e.stringLiteral(_))}else e.isJSXExpressionContainer(p)?e.isJSXEmptyExpression(p.expression)||l.push(p.expression):e.isJSXElement(p)?l.push(X({node:p},i)):e.isJSXFragment(p)&&l.push(H({node:p},i));let h;y?S.length>0?h=e.callExpression(e.memberExpression(e.identifier("Object"),e.identifier("assign")),[e.objectExpression([]),M,e.objectExpression(S)]):h=M:S.length>0?h=e.objectExpression(S):h=e.nullLiteral();let E=l.length>0?e.arrayExpression(l):e.arrayExpression([]);return e.callExpression(e.identifier("_$createComponent"),[e.identifier(a),h,E])}function de(n,i){let{node:r}=n,t=r.openingElement.attributes,a=r.children,s=null;for(let c of t)e.isJSXAttribute(c)&&L(c)==="each"&&(s=v(c.value));if(!s)return console.warn('[what-compiler] <For> element missing "each" attribute.'),i.needsH=!0,U(n,i);let o=null;for(let c of a)if(e.isJSXExpressionContainer(c)&&!e.isJSXEmptyExpression(c.expression)){o=c.expression;break}return o?(i.needsMapArray=!0,e.callExpression(e.identifier("_$mapArray"),[s,o])):(console.warn("[what-compiler] <For> element missing render function child."),i.needsH=!0,U(n,i))}function me(n,i){return i.needsCreateComponent=!0,ie(n,i)}function H(n,i){let{node:r}=n,t=r.children,a=[];for(let s of t)if(e.isJSXText(s)){let o=s.value.replace(/\n\s+/g," ").trim();o&&a.push(e.stringLiteral(o))}else e.isJSXExpressionContainer(s)?e.isJSXEmptyExpression(s.expression)||a.push(s.expression):e.isJSXElement(s)?a.push(X({node:s},i)):e.isJSXFragment(s)&&a.push(H({node:s},i));return a.length===1?a[0]:e.arrayExpression(a)}function re(n,i){if(n.templateMap.has(i))return n.templateMap.get(i);let r=`_tmpl$${n.templateCount++}`;return n.templateMap.set(i,r),n.templates.push({id:r,html:i}),r}return{name:"what-jsx-transform",visitor:{Program:{enter(n,i){i.needsTemplate=!1,i.needsInsert=!1,i.needsEffect=!1,i.needsMapArray=!1,i.needsSpread=!1,i.needsSetProp=!1,i.needsH=!1,i.needsCreateComponent=!1,i.needsFragment=!1,i.needsIsland=!1,i.needsDelegation=!1,i.delegatedEvents=new Set,i.templates=[],i.templateMap=new Map,i.templateCount=0,i._varCounter=0,i._pendingSetup=[],i.nextVarId=()=>`_el$${i._varCounter++}`,i.signalNames=new Set,i.importedIdentifiers=new Set;for(let r of n.node.body)if(e.isImportDeclaration(r)){let t=r.source.value,a=t==="what-framework"||t.startsWith("what-framework/")||t==="what-core"||t.startsWith("what-core/")||t.startsWith("./")||t.startsWith("../");for(let s of r.specifiers){let o=null;(e.isImportSpecifier(s)&&e.isIdentifier(s.local)||e.isImportDefaultSpecifier(s)&&e.isIdentifier(s.local)||e.isImportNamespaceSpecifier(s)&&e.isIdentifier(s.local))&&(o=s.local.name),o&&(a||/^(use|create)[A-Z]/.test(o))&&i.importedIdentifiers.add(o)}}n.traverse({VariableDeclarator(r){let t=r.node.init;if(!t||!e.isCallExpression(t))return;let a=t.callee,s="";if(e.isIdentifier(a)?s=a.name:e.isMemberExpression(a)&&e.isIdentifier(a.property)&&(s=a.property.name),te.has(s)){let o=r.node.id;if(e.isIdentifier(o))i.signalNames.add(o.name);else if(e.isArrayPattern(o))for(let c of o.elements)e.isIdentifier(c)&&i.signalNames.add(c.name);else if(e.isObjectPattern(o))for(let c of o.properties)e.isObjectProperty(c)&&e.isIdentifier(c.value)&&i.signalNames.add(c.value.name)}}})},exit(n,i){for(let a of i.templates.reverse())n.unshiftContainer("body",e.variableDeclaration("const",[e.variableDeclarator(e.identifier(a.id),e.callExpression(e.identifier("_$template"),[e.stringLiteral(a.html)]))]));let r=[];i.needsTemplate&&r.push(e.importSpecifier(e.identifier("_$template"),e.identifier("template"))),i.needsInsert&&r.push(e.importSpecifier(e.identifier("_$insert"),e.identifier("insert"))),i.needsEffect&&r.push(e.importSpecifier(e.identifier("_$effect"),e.identifier("effect"))),i.needsMapArray&&r.push(e.importSpecifier(e.identifier("_$mapArray"),e.identifier("mapArray"))),i.needsSpread&&r.push(e.importSpecifier(e.identifier("_$spread"),e.identifier("spread"))),i.needsSetProp&&r.push(e.importSpecifier(e.identifier("_$setProp"),e.identifier("setProp"))),i.needsCreateComponent&&r.push(e.importSpecifier(e.identifier("_$createComponent"),e.identifier("_$createComponent"))),i.needsDelegation&&r.push(e.importSpecifier(e.identifier("_$delegateEvents"),e.identifier("delegateEvents")));let t=[];if(i.needsH&&t.push(e.importSpecifier(e.identifier("h"),e.identifier("h"))),i.needsFragment&&t.push(e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))),i.needsIsland&&t.push(e.importSpecifier(e.identifier("Island"),e.identifier("Island"))),r.length>0){let a=null;for(let s of n.node.body)if(e.isImportDeclaration(s)&&(s.source.value==="what-framework/render"||s.source.value==="what-core/render")){a=s;break}if(a){let s=new Set(a.specifiers.filter(o=>e.isImportSpecifier(o)).map(o=>o.imported.name));for(let o of r)s.has(o.imported.name)||a.specifiers.push(o)}else n.unshiftContainer("body",e.importDeclaration(r,e.stringLiteral("what-framework/render")))}if(t.length>0&&ye(n,e,t),i.needsDelegation&&i.delegatedEvents&&i.delegatedEvents.size>0){let a=e.arrayExpression([...i.delegatedEvents].map(s=>e.stringLiteral(s)));n.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("_$delegateEvents"),[a])))}}},JSXElement(n,i){i.signalNames=m(n),i._pendingSetup=[];let r=X(n,i),t=i._pendingSetup;if(i._pendingSetup=[],t.length>0){let a=n;for(;a&&!a.isStatement();)a=a.parentPath;if(a&&a.isStatement()){for(let s of t)a.insertBefore(s);n.replaceWith(r)}else t.push(e.returnStatement(r)),n.replaceWith(e.callExpression(e.arrowFunctionExpression([],e.blockStatement(t)),[]))}else n.replaceWith(r)},JSXFragment(n,i){let r=H(n,i);n.replaceWith(r)}}}}function ye(e,f,b){let I=null;for(let w of e.node.body)if(f.isImportDeclaration(w)&&(w.source.value==="what-core"||w.source.value==="what-framework")){I=w;break}if(I){let w=new Set(I.specifiers.filter(P=>f.isImportSpecifier(P)).map(P=>P.imported.name));for(let P of b)w.has(P.imported.name)||I.specifiers.push(P)}else{let w=f.importDeclaration(b,f.stringLiteral("what-framework"));e.unshiftContainer("body",w)}}import Y from"path";import{transformSync as Ce}from"@babel/core";import D from"fs";import F from"path";var se=new Set([".jsx",".tsx",".js",".ts"]),ve=new Set(["_layout","_error","_loading","_404"]);function le(e){let f=[],b=[],I=[];function w(v,C=""){if(!D.existsSync(v))return;let L=D.readdirSync(v,{withFileTypes:!0});for(let $ of L){let d=F.join(v,$.name);if($.isDirectory()){if($.name.match(/^\((.+)\)$/)){w(d,C);continue}if($.name==="api"&&C===""){P(d,"/api");continue}w(d,C+"/"+V($.name));continue}let m=F.extname($.name);if(!se.has(m))continue;let x=F.basename($.name,m);if(x==="_layout"){b.push({filePath:d,urlPrefix:C||"/"});continue}if(ve.has(x))continue;let g=V(x),T=x==="index"?C||"/":C+"/"+g;f.push({filePath:d,routePath:oe(T),isDynamic:T.includes(":")||T.includes("*")})}}function P(v,C){if(!D.existsSync(v))return;let L=D.readdirSync(v,{withFileTypes:!0});for(let $ of L){let d=F.join(v,$.name);if($.isDirectory()){P(d,C+"/"+V($.name));continue}let m=F.extname($.name);if(!se.has(m))continue;let x=F.basename($.name,m),g=V(x),T=x==="index"?C:C+"/"+g;I.push({filePath:d,routePath:oe(T)})}}return w(e),f.sort((v,C)=>{let L=ae(v.routePath),$=ae(C.routePath);return L-$}),{pages:f,layouts:b,apiRoutes:I}}function V(e){let f=e.match(/^\[\.\.\.(\w+)\]$/);if(f)return"*"+f[1];let b=e.match(/^\[(\w+)\]$/);return b?":"+b[1]:e.toLowerCase()}function oe(e){let f=e.replace(/\/+/g,"/");return f.length>1&&f.endsWith("/")&&(f=f.slice(0,-1)),f||"/"}function ae(e){return e.includes("*")?100:e.includes(":")?10:0}function ce(e){let f=e.match(/export\s+const\s+page\s*=\s*(\{[^}]*\})/s);if(!f)return{mode:"client"};try{let b=f[1].replace(/'/g,'"').replace(/(\w+)\s*:/g,'"$1":').replace(/,\s*}/g,"}").replace(/\/\/[^\n]*/g,"");return{mode:"client",...JSON.parse(b)}}catch{return{mode:"client"}}}function Z(e,f){let{pages:b,layouts:I,apiRoutes:w}=le(e),P=[],v=[],C=new Map;I.forEach((d,m)=>{let x=`_layout${m}`,g=q(d.filePath,f);P.push(`import ${x} from '${g}';`),C.set(d.urlPrefix,x)}),b.forEach((d,m)=>{let x=`_page${m}`,g=q(d.filePath,f);P.push(`import ${x} from '${g}';`);let T={mode:"client"};try{let j=D.readFileSync(d.filePath,"utf-8");T=ce(j)}catch{}let k=we(d.routePath,C),J={path:d.routePath,component:x,mode:T.mode||"client",layout:k||null};v.push(J)});let L=[];return w.forEach((d,m)=>{let x=`_api${m}`,g=q(d.filePath,f);P.push(`import * as ${x} from '${g}';`),L.push({path:d.routePath,handlers:x})}),["// Auto-generated by What Framework file router","// Do not edit \u2014 changes will be overwritten","",...P,"","export const routes = [",...v.map(d=>` { path: '${d.path}', component: ${d.component}, mode: '${d.mode}'${d.layout?`, layout: ${d.layout}`:""} },`),"];","","export const apiRoutes = [",...L.map(d=>` { path: '${d.path}', handlers: ${d.handlers} },`),"];","","export const pageModes = {",...v.map(d=>` '${d.path}': '${d.mode}',`),"};"].join(`
|
|
2
|
+
`)}function q(e,f){return"/"+F.relative(f,e).split(F.sep).join("/")}function we(e,f){let b=e.split("/").filter(Boolean);for(;b.length>0;){let I="/"+b.join("/");if(f.has(I))return f.get(I);b.pop()}return f.has("/")?f.get("/"):null}var _e=`
|
|
3
|
+
:host {
|
|
4
|
+
position: fixed;
|
|
5
|
+
inset: 0;
|
|
6
|
+
z-index: 99999;
|
|
7
|
+
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.backdrop {
|
|
11
|
+
position: fixed;
|
|
12
|
+
inset: 0;
|
|
13
|
+
background: rgba(0, 0, 0, 0.66);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.panel {
|
|
17
|
+
position: fixed;
|
|
18
|
+
inset: 2rem;
|
|
19
|
+
overflow: auto;
|
|
20
|
+
background: #1a1a2e;
|
|
21
|
+
border: 1px solid #2a2a4a;
|
|
22
|
+
border-radius: 12px;
|
|
23
|
+
box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
|
|
24
|
+
color: #e0e0e0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.header {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: space-between;
|
|
31
|
+
padding: 1rem 1.5rem;
|
|
32
|
+
border-bottom: 1px solid #2a2a4a;
|
|
33
|
+
background: #16163a;
|
|
34
|
+
border-radius: 12px 12px 0 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.header-left {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: 0.75rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.header-right {
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: 0.5rem;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.logo {
|
|
50
|
+
width: 28px;
|
|
51
|
+
height: 28px;
|
|
52
|
+
background: linear-gradient(135deg, #2563eb, #1d4ed8);
|
|
53
|
+
border-radius: 6px;
|
|
54
|
+
display: grid;
|
|
55
|
+
place-items: center;
|
|
56
|
+
font-weight: 800;
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
color: #fff;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.brand {
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
color: #a0a0c0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.tag {
|
|
68
|
+
font-size: 11px;
|
|
69
|
+
padding: 2px 8px;
|
|
70
|
+
border-radius: 4px;
|
|
71
|
+
font-weight: 600;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.tag-error {
|
|
75
|
+
background: #3b1219;
|
|
76
|
+
color: #f87171;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.tag-warning {
|
|
80
|
+
background: #3b2f19;
|
|
81
|
+
color: #fbbf24;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.close-btn, .copy-btn {
|
|
85
|
+
background: none;
|
|
86
|
+
border: 1px solid #3a3a5a;
|
|
87
|
+
color: #a0a0c0;
|
|
88
|
+
border-radius: 6px;
|
|
89
|
+
padding: 4px 12px;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
font-family: inherit;
|
|
92
|
+
font-size: 12px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.close-btn:hover, .copy-btn:hover {
|
|
96
|
+
background: #2a2a4a;
|
|
97
|
+
color: #fff;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.copy-btn.copied {
|
|
101
|
+
border-color: #22c55e;
|
|
102
|
+
color: #22c55e;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.body {
|
|
106
|
+
padding: 1.5rem;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.error-title {
|
|
110
|
+
font-size: 16px;
|
|
111
|
+
font-weight: 700;
|
|
112
|
+
color: #f87171;
|
|
113
|
+
margin: 0 0 0.5rem;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.error-message {
|
|
117
|
+
font-size: 14px;
|
|
118
|
+
color: #e0e0e0;
|
|
119
|
+
margin: 0 0 1rem;
|
|
120
|
+
line-height: 1.6;
|
|
121
|
+
white-space: pre-wrap;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.file-path {
|
|
125
|
+
display: inline-flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
gap: 0.5rem;
|
|
128
|
+
font-size: 12px;
|
|
129
|
+
color: #818cf8;
|
|
130
|
+
margin-bottom: 1rem;
|
|
131
|
+
padding: 0.25rem 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.code-frame {
|
|
135
|
+
background: #0d0d1a;
|
|
136
|
+
border: 1px solid #2a2a4a;
|
|
137
|
+
border-radius: 8px;
|
|
138
|
+
overflow-x: auto;
|
|
139
|
+
margin-bottom: 1rem;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.code-line {
|
|
143
|
+
display: flex;
|
|
144
|
+
padding: 0 1rem;
|
|
145
|
+
font-size: 13px;
|
|
146
|
+
line-height: 1.7;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.code-line.highlight {
|
|
150
|
+
background: rgba(248, 113, 113, 0.1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.line-number {
|
|
154
|
+
color: #4a4a6a;
|
|
155
|
+
min-width: 3ch;
|
|
156
|
+
text-align: right;
|
|
157
|
+
margin-right: 1rem;
|
|
158
|
+
user-select: none;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.line-content {
|
|
162
|
+
white-space: pre;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.tip {
|
|
166
|
+
margin-top: 1rem;
|
|
167
|
+
padding: 0.75rem 1rem;
|
|
168
|
+
background: #1a2744;
|
|
169
|
+
border: 1px solid #1e3a5f;
|
|
170
|
+
border-radius: 8px;
|
|
171
|
+
font-size: 13px;
|
|
172
|
+
color: #93c5fd;
|
|
173
|
+
line-height: 1.5;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.tip-label {
|
|
177
|
+
font-weight: 700;
|
|
178
|
+
color: #60a5fa;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.stack {
|
|
182
|
+
margin-top: 1rem;
|
|
183
|
+
font-size: 12px;
|
|
184
|
+
color: #6a6a8a;
|
|
185
|
+
white-space: pre-wrap;
|
|
186
|
+
line-height: 1.5;
|
|
187
|
+
}
|
|
188
|
+
`,Ae=`
|
|
189
|
+
class WhatErrorOverlay extends HTMLElement {
|
|
190
|
+
constructor(err) {
|
|
191
|
+
super();
|
|
192
|
+
this.root = this.attachShadow({ mode: 'open' });
|
|
193
|
+
this.root.innerHTML = '<style>${_e}</style>';
|
|
194
|
+
this._err = err;
|
|
195
|
+
this.show(err);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// --- Inlined helper: escapeHTML ---
|
|
199
|
+
_escapeHTML(str) {
|
|
200
|
+
return String(str)
|
|
201
|
+
.replace(/&/g, '&')
|
|
202
|
+
.replace(/</g, '<')
|
|
203
|
+
.replace(/>/g, '>')
|
|
204
|
+
.replace(/"/g, '"');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// --- Inlined helper: cleanStack ---
|
|
208
|
+
_cleanStack(stack) {
|
|
209
|
+
return stack
|
|
210
|
+
.split('\\n')
|
|
211
|
+
.filter(function(line) { return line.indexOf('node_modules') === -1; })
|
|
212
|
+
.slice(0, 10)
|
|
213
|
+
.join('\\n');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// --- Inlined helper: getTip ---
|
|
217
|
+
_getTip(err) {
|
|
218
|
+
var msg = (err.message || '').toLowerCase();
|
|
219
|
+
|
|
220
|
+
if (msg.indexOf('infinite') !== -1 && msg.indexOf('effect') !== -1) {
|
|
221
|
+
return 'An effect is writing to a signal it also reads. Use untrack() to read without subscribing, or move the write to a different effect.';
|
|
222
|
+
}
|
|
223
|
+
if (msg.indexOf('jsx') !== -1 && msg.indexOf('unexpected') !== -1) {
|
|
224
|
+
return 'Make sure your vite.config includes the What compiler plugin: import what from "what-compiler/vite"';
|
|
225
|
+
}
|
|
226
|
+
if (msg.indexOf('not a function') !== -1 && msg.indexOf('signal') !== -1) {
|
|
227
|
+
return 'Signals are functions: call sig() to read, sig(value) to write. Check you are not destructuring a signal.';
|
|
228
|
+
}
|
|
229
|
+
if (msg.indexOf('hydrat') !== -1) {
|
|
230
|
+
return 'Hydration mismatches happen when SSR output differs from client render. Ensure server and client see the same initial state.';
|
|
231
|
+
}
|
|
232
|
+
// New tips for common mistakes
|
|
233
|
+
if (msg.indexOf('signal') !== -1 && msg.indexOf('without') !== -1 && msg.indexOf('call') !== -1) {
|
|
234
|
+
return 'Signals must be called to read their value. Use {count()} in JSX, not {count}. The parentheses trigger the reactive subscription.';
|
|
235
|
+
}
|
|
236
|
+
if (msg.indexOf('innerhtml') !== -1 && msg.indexOf('__html') !== -1) {
|
|
237
|
+
return 'Raw innerHTML is blocked for security. Use innerHTML={{ __html: trustedString }} or dangerouslySetInnerHTML={{ __html: trustedString }} instead.';
|
|
238
|
+
}
|
|
239
|
+
if ((msg.indexOf('innerhtml') !== -1 || msg.indexOf('xss') !== -1) && msg.indexOf('raw string') !== -1) {
|
|
240
|
+
return 'Raw innerHTML is a security risk (XSS). Wrap your HTML in an object: innerHTML={{ __html: yourString }}.';
|
|
241
|
+
}
|
|
242
|
+
if (msg.indexOf('cleanup') !== -1 && (msg.indexOf('effect') !== -1 || msg.indexOf('listener') !== -1)) {
|
|
243
|
+
return 'Effects that add event listeners or timers should return a cleanup function: effect(() => { el.addEventListener(...); return () => el.removeEventListener(...); })';
|
|
244
|
+
}
|
|
245
|
+
if (msg.indexOf('route') !== -1 && (msg.indexOf('not found') !== -1 || msg.indexOf('404') !== -1 || msg.indexOf('no match') !== -1)) {
|
|
246
|
+
return 'No route matched the current URL. Check that your route paths are correct and you have a catch-all or 404 route defined.';
|
|
247
|
+
}
|
|
248
|
+
if (msg.indexOf('key') !== -1 && (msg.indexOf('missing') !== -1 || msg.indexOf('list') !== -1 || msg.indexOf('each') !== -1)) {
|
|
249
|
+
return 'Lists need unique keys for efficient DOM updates. Add a key prop: items.map(item => <Item key={item.id} />)';
|
|
250
|
+
}
|
|
251
|
+
return '';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// --- Build overlay HTML ---
|
|
255
|
+
_buildHTML(err) {
|
|
256
|
+
var isCompilerError = err._isCompilerError || err.plugin === 'vite-plugin-what';
|
|
257
|
+
var type = isCompilerError ? 'Compiler Error' : 'Runtime Error';
|
|
258
|
+
var tagClass = isCompilerError ? 'tag-error' : 'tag-warning';
|
|
259
|
+
|
|
260
|
+
var codeFrame = '';
|
|
261
|
+
var rawFrame = err.frame || err._frame;
|
|
262
|
+
if (rawFrame) {
|
|
263
|
+
var lines = rawFrame.split('\\n');
|
|
264
|
+
var frameLines = '';
|
|
265
|
+
for (var i = 0; i < lines.length; i++) {
|
|
266
|
+
var line = lines[i];
|
|
267
|
+
var isHighlight = line.trimStart().startsWith('>');
|
|
268
|
+
var cleaned = line.replace(/^\\s*>\\s?/, ' ').replace(/^\\s{2}/, '');
|
|
269
|
+
var match = cleaned.match(/^(\\s*\\d+)\\s*\\|(.*)$/);
|
|
270
|
+
if (match) {
|
|
271
|
+
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>';
|
|
272
|
+
} else if (cleaned.trim().startsWith('|')) {
|
|
273
|
+
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>';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (frameLines) {
|
|
277
|
+
codeFrame = '<div class="code-frame">' + frameLines + '</div>';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
var filePath = err.id || (err.loc && err.loc.file) || '';
|
|
282
|
+
var lineNum = (err.loc && err.loc.line != null) ? err.loc.line : '';
|
|
283
|
+
var col = (err.loc && err.loc.column != null) ? err.loc.column : '';
|
|
284
|
+
var location = filePath
|
|
285
|
+
? '<div class="file-path">' + this._escapeHTML(filePath) + (lineNum ? ':' + lineNum : '') + (col ? ':' + col : '') + '</div>'
|
|
286
|
+
: '';
|
|
287
|
+
|
|
288
|
+
var tip = this._getTip(err);
|
|
289
|
+
var tipHTML = tip ? '<div class="tip"><span class="tip-label">Tip: </span>' + this._escapeHTML(tip) + '</div>' : '';
|
|
290
|
+
|
|
291
|
+
var stack = (err.stack && !isCompilerError)
|
|
292
|
+
? '<div class="stack">' + this._escapeHTML(this._cleanStack(err.stack)) + '</div>'
|
|
293
|
+
: '';
|
|
294
|
+
|
|
295
|
+
return '<div class="backdrop"></div>'
|
|
296
|
+
+ '<div class="panel">'
|
|
297
|
+
+ '<div class="header">'
|
|
298
|
+
+ '<div class="header-left">'
|
|
299
|
+
+ '<div class="logo">W</div>'
|
|
300
|
+
+ '<span class="brand">What Framework</span>'
|
|
301
|
+
+ '<span class="tag ' + tagClass + '">' + type + '</span>'
|
|
302
|
+
+ '</div>'
|
|
303
|
+
+ '<div class="header-right">'
|
|
304
|
+
+ '<button class="copy-btn">Copy Error</button>'
|
|
305
|
+
+ '<button class="close-btn">Dismiss (Esc)</button>'
|
|
306
|
+
+ '</div>'
|
|
307
|
+
+ '</div>'
|
|
308
|
+
+ '<div class="body">'
|
|
309
|
+
+ '<h2 class="error-title">' + this._escapeHTML(err.name || 'Error') + '</h2>'
|
|
310
|
+
+ location
|
|
311
|
+
+ '<pre class="error-message">' + this._escapeHTML(err.message || String(err)) + '</pre>'
|
|
312
|
+
+ codeFrame
|
|
313
|
+
+ tipHTML
|
|
314
|
+
+ stack
|
|
315
|
+
+ '</div>'
|
|
316
|
+
+ '</div>';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
show(err) {
|
|
320
|
+
var template = document.createElement('template');
|
|
321
|
+
template.innerHTML = this._buildHTML(err);
|
|
322
|
+
this.root.appendChild(template.content.cloneNode(true));
|
|
323
|
+
|
|
324
|
+
// Close handlers
|
|
325
|
+
var self = this;
|
|
326
|
+
var closeBtn = this.root.querySelector('.close-btn');
|
|
327
|
+
if (closeBtn) closeBtn.addEventListener('click', function() { self.close(); });
|
|
328
|
+
var backdrop = this.root.querySelector('.backdrop');
|
|
329
|
+
if (backdrop) backdrop.addEventListener('click', function() { self.close(); });
|
|
330
|
+
document.addEventListener('keydown', this._onKey = function(e) {
|
|
331
|
+
if (e.key === 'Escape') self.close();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// Copy Error button
|
|
335
|
+
var copyBtn = this.root.querySelector('.copy-btn');
|
|
336
|
+
if (copyBtn) {
|
|
337
|
+
copyBtn.addEventListener('click', function() {
|
|
338
|
+
self._copyError(copyBtn);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
_copyError(btn) {
|
|
344
|
+
var err = this._err;
|
|
345
|
+
var data = {
|
|
346
|
+
name: err.name || 'Error',
|
|
347
|
+
message: err.message || String(err),
|
|
348
|
+
file: err.id || (err.loc && err.loc.file) || null,
|
|
349
|
+
line: (err.loc && err.loc.line != null) ? err.loc.line : null,
|
|
350
|
+
column: (err.loc && err.loc.column != null) ? err.loc.column : null,
|
|
351
|
+
stack: err.stack ? this._cleanStack(err.stack) : null,
|
|
352
|
+
framework: 'What Framework',
|
|
353
|
+
timestamp: new Date().toISOString()
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
var text = JSON.stringify(data, null, 2);
|
|
357
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
358
|
+
navigator.clipboard.writeText(text).then(function() {
|
|
359
|
+
btn.textContent = 'Copied!';
|
|
360
|
+
btn.classList.add('copied');
|
|
361
|
+
setTimeout(function() {
|
|
362
|
+
btn.textContent = 'Copy Error';
|
|
363
|
+
btn.classList.remove('copied');
|
|
364
|
+
}, 2000);
|
|
365
|
+
}).catch(function() {
|
|
366
|
+
// Fallback: select text
|
|
367
|
+
prompt('Copy error details:', text);
|
|
368
|
+
});
|
|
369
|
+
} else {
|
|
370
|
+
prompt('Copy error details:', text);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
close() {
|
|
375
|
+
document.removeEventListener('keydown', this._onKey);
|
|
376
|
+
this.remove();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!customElements.get('what-error-overlay')) {
|
|
381
|
+
customElements.define('what-error-overlay', WhatErrorOverlay);
|
|
382
|
+
}
|
|
383
|
+
`;function fe(e){let f=e.ws.send.bind(e.ws);e.ws.send=function(b){return b?.type==="error"&&b.err?.plugin==="vite-plugin-what"&&(b.err._isCompilerError=!0),f(b)}}var pe="virtual:what-routes",B="\0"+pe,Le=/export\s+(?:default\s+)?function\s+([A-Z]\w*)/,ke=/(?:store|signal|state|context|util|helper|lib|config)\b/i;function Q(e={}){let{include:f=/\.[jt]sx$/,exclude:b=/node_modules/,sourceMaps:I=!0,production:w=!0,pages:P="src/pages",hot:v=!w}=e,C="",L="",$=null,d=!1;return{name:"vite-plugin-what",configResolved(m){C=m.root,L=Y.resolve(C,P),d=m.command==="serve"},configureServer(m){$=m,fe(m),m.watcher.on("add",x=>{if(x.startsWith(L)){let g=m.moduleGraph.getModuleById(B);g&&(m.moduleGraph.invalidateModule(g),m.ws.send({type:"full-reload"}))}}),m.watcher.on("unlink",x=>{if(x.startsWith(L)){let g=m.moduleGraph.getModuleById(B);g&&(m.moduleGraph.invalidateModule(g),m.ws.send({type:"full-reload"}))}})},resolveId(m){if(m===pe)return B},load(m){if(m===B)return Z(L,C)},transform(m,x){if(!f.test(x)||b&&b.test(x))return null;try{let g=Ce(m,{filename:x,sourceMaps:I,plugins:[[W,{production:w}]],parserOpts:{plugins:["jsx","typescript"]}});if(!g||!g.code)return null;let T=g.code;return v&&d&&!w&&$e(m,x)&&(T+=Ie(x)),{code:T,map:g.map}}catch(g){throw g.plugin="vite-plugin-what",g.id||(g.id=x),g.loc===void 0&&g._loc&&(g.loc={file:x,line:g._loc.line,column:g._loc.column}),console.error(`[what] Error transforming ${x}:`,g.message),g}},handleHotUpdate({file:m,server:x,modules:g}){if(v&&f.test(m)&&!(b&&b.test(m))&&Pe(m))return x.ws.send({type:"full-reload"}),[]},config(m,{mode:x}){return{esbuild:{jsx:"preserve"},optimizeDeps:{include:["what-framework"]}}}}}function $e(e,f){return!!(Le.test(e)||f.includes("/pages/")||f.includes("\\pages\\"))}function Pe(e){let f=Y.basename(e,Y.extname(e));return ke.test(f)}function Ie(e){return`
|
|
384
|
+
|
|
385
|
+
// --- What Framework HMR Boundary ---
|
|
386
|
+
if (import.meta.hot) {
|
|
387
|
+
import.meta.hot.accept((newModule) => {
|
|
388
|
+
if (newModule) {
|
|
389
|
+
// Signal to the What runtime that this module was hot-updated
|
|
390
|
+
if (window.__WHAT_HMR_ACCEPT__) {
|
|
391
|
+
window.__WHAT_HMR_ACCEPT__(${JSON.stringify(e)}, newModule);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
`}import{h as ze,Fragment as Ue,mount as Ge,Island as qe}from"what-core";export{Ue as Fragment,qe as Island,W as babelPlugin,ce as extractPageConfig,Z as generateRoutesModule,ze as h,Ge as mount,le as scanPages,Q as vitePlugin,Q as what};
|
|
397
|
+
//# sourceMappingURL=index.min.js.map
|