ms-vite-plugin 1.5.28 → 1.5.30
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createDebugInstrumentPlugin=
|
|
2
|
-
`)+1;return t.slice(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createDebugInstrumentPlugin=W;const{parseSync:H}=require("oxc-parser"),I=require("magic-string"),w="__kjs_bp_hit",O="__kjs_bp",F="__kjs_enter",j="__kjs_leave",x="__kjs_throw",T="__kjs_pos",u="__kjsErr",D=0,P=1,R=2,J="<anonymous>";function W(){let t=process.cwd(),n="";const e=new Map,i=new Map;return{name:"kuaijs-debug-instrument",enforce:"pre",configResolved(r){t=r.root||t,n=r.build?.outDir??""},writeBundle(){z(t,n,e,i)},renderChunk(r){return G(r)},transform(r,a){const o=U(a,t);if(!o)return null;const{edits:s,lines:f,aliases:y}=q(r,o,a);if(s.length===0)return null;const b=e.get(o)??new Set;for(const p of f)b.add(p);e.set(o,b),y.size>0&&i.set(o,y);const $=new I(r);for(const p of s)p.start===p.end?$.appendLeft(p.start,p.text):$.overwrite(p.start,p.end,p.text);return{code:$.toString(),map:$.generateMap({hires:!0})}}}}function U(t,n){if(!t||t.startsWith("\0")||t.includes("node_modules"))return null;const e=t.split("?")[0].split("#")[0];return!/\.[cm]?[jt]sx?$/.test(e)||!e.startsWith(n)?null:e.slice(n.length).replace(/^[\\/]+/,"").replace(/\\/g,"/")}function V(t,n){try{const e=H(t,n);return Array.isArray(e?.errors)&&e.errors.length>0?null:e?.program??null}catch{return null}}function q(t,n,e){const i=V(e,t);if(!i)return{edits:[],lines:[],aliases:new Map};const r=[],a=ct(t),o=JSON.stringify(n),s=new Set,f=[],y=c=>`()=>({${c.map(l=>l.writable?`get ${l.name}(){return ${l.name}},set ${l.name}(v){${l.name}=v}`:`get ${l.name}(){return ${l.name}}`).join(",")}})`;M(i,[],{onStatement:(c,l)=>{if(typeof c.start!="number")return;const m=S(a,c.start),_=y(l),N=c.type==="DebuggerStatement",C=`${O}(${o},${m},${_}${N?",true":""})`;s.add(m),r.push({start:c.start,end:c.start,text:N?`${C};`:`${w}(${o},${m})&&${C};`}),B(c)&&r.push({start:c.start,end:c.start,text:`${T}(${o},${m});`})},onFunctionBody:c=>Q(r,c,n,S(a,c.start)),onExpressionBody:c=>X(r,c,t,n,S(a,c.start)),onCatchClause:c=>tt(r,c,t,n,S(a,c.start)),onExpression:(c,l)=>{if(typeof c.start!="number"||typeof c.end!="number")return;const m=S(a,c.start),_=y(l);s.add(m),r.push({start:c.start,end:c.start,text:`(${w}(${o},${m})&&${O}(${o},${m},${_}),`}),r.push({start:c.end,end:c.end,text:")"})},onLabel:(c,l)=>{typeof c?.start!="number"||typeof l?.start!="number"||f.push({line:S(a,c.start),minLine:S(a,l.start)})}});const p=new Map;for(const c of f){let l=-1;for(const m of[...s].sort((_,N)=>_-N))if(m>=c.minLine){l=m;break}l>0&&l!==c.line&&p.set(c.line,l)}return{edits:r,lines:[...s].sort((c,l)=>c-l),aliases:p}}function G(t){if(!t||/(^|[\s;])export[\s{]/.test(t)||/(^|[\s;])import[\s({]/.test(t))return null;const n=new I(t);return n.prepend("try{"),n.appendLeft(K(t),`}catch(${u}){if(typeof ${x}==='function')${x}(${u},"",0,()=>({exception:${u}}),${R});throw ${u}}`),{code:n.toString(),map:n.generateMap({hires:!0})}}function K(t){const e=t.lastIndexOf(`
|
|
2
|
+
`)+1;return t.slice(e).trimStart().startsWith("//")?e:t.length}const Y="kuaijs-debug-lines.json";function z(t,n,e,i){if(!t||!n)return;const r={};for(const[o,s]of e)r[o]=[...s].sort((f,y)=>f-y);const a={};for(const[o,s]of i){const f={};for(const[y,b]of s)f[String(y)]=b;a[o]=f}try{const o=require("fs"),s=require("path"),f=s.join(t,n);o.mkdirSync(f,{recursive:!0}),o.writeFileSync(s.join(f,Y),JSON.stringify({files:r,aliases:a}),"utf8")}catch{}}function Q(t,n,e,i){const r=n?.body;if(!r||typeof r.start!="number"||typeof r.end!="number")return;const a=JSON.stringify(L(n));let o=r.start+1;if(Array.isArray(r.body)){let s=0;for(;s<r.body.length&&k(r.body[s]);){const f=r.body[s];typeof f.end=="number"&&(o=f.end),s+=1}}t.push({start:o,end:o,text:`${F}(${a},${JSON.stringify(e)},${i});try{`}),t.push({start:r.end-1,end:r.end-1,text:`}catch(${u}){${x}(${u},${JSON.stringify(e)},${i},()=>({exception:${u}}),${D});throw ${u}}finally{${j}();}`})}function X(t,n,e,i,r){const a=n.body;if(!a||typeof a.start!="number"||typeof a.end!="number")return;const o=e.slice(a.start,a.end),s=n.async?"(async()=>":"(()=>",f=JSON.stringify(L(n));t.push({start:a.start,end:a.end,text:`${s}{${F}(${f},${JSON.stringify(i)},${r});try{return ${o};}catch(${u}){${x}(${u},${JSON.stringify(i)},${r},()=>({exception:${u}}),${D});throw ${u}}finally{${j}();}})()`})}function L(t){const n=t?.id?.name;if(typeof n=="string"&&n)return n;const e=t?.__kjsNameHint;return typeof e=="string"&&e?e:J}function Z(t,n,e){if(!A(e))return"";if(t?.type==="VariableDeclarator"&&n==="init"&&t.id?.type==="Identifier")return t.id.name;if(t?.type==="Property"&&n==="value"||(t?.type==="MethodDefinition"||t?.type==="PropertyDefinition")&&n==="value")return v(t.key);if(t?.type==="AssignmentExpression"&&n==="right"){const i=t.left;if(i?.type==="Identifier")return i.name;if(i?.type==="MemberExpression"&&i.property)return v(i.property)}return""}function v(t){return t?t.type==="Identifier"&&typeof t.name=="string"?t.name:t.type==="Literal"&&typeof t.value=="string"?t.value:"":""}function tt(t,n,e,i,r){const a=n?.body;if(typeof a?.start!="number")return;const o=n.param;let s="",f=u;if(o?.type==="Identifier")f=o.name;else if(!o)t.push({start:a.start,end:a.start,text:`(${u})`});else if(typeof o.start=="number"&&typeof o.end=="number"){const y=e.slice(o.start,o.end);t.push({start:o.start,end:o.end,text:u}),s=`let ${y}=${u};`}else return;t.push({start:a.start+1,end:a.start+1,text:s+`${x}(${f},${JSON.stringify(i)},${r},()=>({exception:${f}}),${P});`})}function M(t,n,e,i=!1){if(!(!t||typeof t!="object")){if(A(t)){const r=new Map;for(const a of t.params??[])g(a,r);t.body?.type==="BlockStatement"?(nt(t.body,r),e.onFunctionBody(t)):t.body&&e.onExpressionBody(t),n.push(r),d(t,n,e,i),n.pop();return}if(t.type==="Program"){const r=new Map;for(const a of t.body??[])if(a?.type==="ImportDeclaration")for(const o of a.specifiers??[])o?.local?.name&&r.set(o.local.name,!1);n.push(r),d(t,n,e,i),n.pop();return}if(t.type==="CatchClause"){e.onCatchClause(t);const r=new Map;t.param&&g(t.param,r,!0),n.push(r),d(t,n,e,i),n.pop();return}if(st(t)){n.push(new Map),d(t,n,e,i),n.pop();return}d(t,n,e,i)}}function d(t,n,e,i){for(const r of Object.keys(t)){if(r==="start"||r==="end"||r==="type")continue;const a=t[r],o=Array.isArray(a)?a:[a];for(const s of o){if(!s||typeof s!="object")continue;const f=E(t)&&it.has(r),y=t.type==="LabeledStatement"&&r==="body";if(!f&&rt(t,r,s)&&e.onExpression(s,h(n)),E(t)&&r==="test")e.onExpression(s,h(n));else if(E(t)&&r==="update"&&!t.test)e.onExpression(s,h(n));else if(E(t)&&r==="init"&&!t.test&&!t.update&&s?.type!=="VariableDeclaration")e.onExpression(s,h(n));else if(t.type==="ForStatement"&&r==="init"&&!t.test&&!t.update&&s?.type==="VariableDeclaration"&&s.declarations?.length===1){const p=s.declarations[0];p?.init&&e.onExpression(p.init,h(n))}(t.type==="ForInStatement"||t.type==="ForOfStatement")&&r==="right"&&e.onExpression(s,h(n)),t.type==="LabeledStatement"&&r==="body"&&e.onLabel(t,s);const b=(t.type==="ExportNamedDeclaration"||t.type==="ExportDefaultDeclaration")&&r==="declaration",$=Z(t,r,s);$&&!s.__kjsNameHint&&(s.__kjsNameHint=$),!i&&!f&&!y&&!b&&at(s)&&!k(s)&&!ot(s)&&e.onStatement(s,h(n)),M(s,n,e,i||f),et(s,n)}}}function h(t){const n=new Map;for(let e=t.length-1;e>=0;e-=1)for(const[i,r]of t[e])n.has(i)||n.set(i,r);return[...n.entries()].map(([e,i])=>({name:e,writable:i})).sort((e,i)=>e.name<i.name?-1:e.name>i.name?1:0)}function et(t,n){const e=n[n.length-1];if(!e)return;if(t?.type==="VariableDeclaration"&&t.kind!=="var"){const r=t.kind!=="const";for(const a of t.declarations??[])g(a.id,e,r);return}const i=t?.declaration;i?.type==="ClassDeclaration"&&i.id?.name&&e.set(i.id.name,!0)}function g(t,n,e=!0){if(t)switch(t.type){case"Identifier":n.set(t.name,e);return;case"ObjectPattern":for(const i of t.properties??[])g(i.value??i.argument??i.key,n,e);return;case"ArrayPattern":for(const i of t.elements??[])g(i,n,e);return;case"AssignmentPattern":g(t.left,n,e);return;case"RestElement":g(t.argument,n);return;default:return}}function nt(t,n){const e=[t];for(;e.length>0;){const i=e.pop();if(!(!i||typeof i!="object")){if(i.type==="VariableDeclaration"&&i.kind==="var")for(const r of i.declarations??[])g(r.id,n);if(i.type==="FunctionDeclaration"&&i.id?.name&&n.set(i.id.name,!0),!(A(i)&&i!==t))for(const r of Object.keys(i)){if(r==="start"||r==="end"||r==="type")continue;const a=i[r],o=Array.isArray(a)?a:[a];for(const s of o)s&&typeof s=="object"&&e.push(s)}}}}function A(t){return t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"}function rt(t,n,e){return n!=="value"||!e||typeof e.start!="number"?!1:t?.type==="PropertyDefinition"||t?.type==="AccessorProperty"}const it=new Set(["init","left","right","test","update"]);function E(t){return t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function st(t){return t.type==="BlockStatement"||t.type==="Program"||t.type==="SwitchStatement"||t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function at(t){return t.type==="BlockStatement"||t.type==="EmptyStatement"||t.type==="LabeledStatement"?!1:typeof t.type=="string"&&(t.type.endsWith("Statement")||t.type.endsWith("Declaration"))}function k(t){return t?.type==="ExpressionStatement"&&t.expression?.type==="Literal"&&typeof t.expression.value=="string"}function B(t){if(!t||typeof t!="object")return!1;if(t.type==="CallExpression"||t.type==="NewExpression"||t.type==="TaggedTemplateExpression")return!0;for(const n of Object.keys(t)){if(n==="start"||n==="end"||n==="type")continue;const e=t[n],i=Array.isArray(e)?e:[e];for(const r of i)if(r&&typeof r=="object"&&B(r))return!0}return!1}function ot(t){const n=t?.expression;if(n?.type!=="CallExpression")return!1;const e=n.callee?.name;return e===w||e===O||e===F||e===j||e===x||e===T}function ct(t){const n=[0];for(let e=0;e<t.length;e+=1)t.charCodeAt(e)===10&&n.push(e+1);return n}function S(t,n){let e=0,i=t.length-1;for(;e<i;){const r=e+i+1>>1;t[r]<=n?e=r:i=r-1}return e+1}
|