ms-vite-plugin 1.5.27 → 1.5.29

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