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