react-code-locator 0.2.0 → 0.2.2

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/dist/swc.cjs CHANGED
@@ -36,5 +36,5 @@ function _markReactElementSource(element, source) {
36
36
  }
37
37
  return element;
38
38
  }
39
- `;return Lr.parse(e,{ecmaVersion:"latest",sourceType:"module"}).body[0]}function _n(e,i){return{type:"CallExpression",callee:{type:"Identifier",name:"_markReactElementSource"},arguments:[e,{type:"Literal",value:i}],optional:!1}}function Rr(e,i){let{filename:a,projectRoot:o=process.cwd(),injectJsxSource:h=!0,injectComponentSource:x=!0}=i,v;try{v=Cn(a).parse(e,{ecmaVersion:"latest",sourceType:"module",locations:!0})}catch{return null}let k=!1,_=!1,l=new Set,M=[];if(Er(v,{enter(z,Q){if(h&&z.type==="CallExpression"&&kn(z)){let T=z.loc;T&&(this.replace(_n(z,ji(a,T.start,o))),_=!0,k=!0)}if(x&&z.type==="FunctionDeclaration"){let T=z.id?.name;T&&Pr(T)&&!l.has(T)&&z.loc&&(M.push({node:z,parent:Q,assignment:Ir(T,ji(a,z.loc.start,o))}),l.add(T),k=!0)}if(x&&z.type==="VariableDeclarator"){let T=z.id;if(T.type==="Identifier"&&Pr(T.name)&&!l.has(T.name)){let I=z.init;if(I&&An(I)){let D=z.loc||I.loc;D&&(M.push({node:z,parent:Q,assignment:Ir(T.name,ji(a,D.start,o))}),l.add(T.name),k=!0)}}}}}),!k)return null;if(_){let z=En();v.body.some(T=>T.type==="FunctionDeclaration"&&T.id?.name==="_markReactElementSource")||v.body.unshift(z)}for(let{node:z,parent:Q,assignment:T}of M.reverse())if(Q?.type==="Program"){let I=v.body.indexOf(z);I!==-1&&v.body.splice(I+1,0,T)}else if(Q?.type==="ExportNamedDeclaration"){let I=v.body.find(D=>D.type==="ExportNamedDeclaration"&&D.declaration===Q);I&&v.body.splice(v.body.indexOf(I)+1,0,T)}else Q?.type==="ExportDefaultDeclaration"&&v.body.splice(v.body.indexOf(Q)+1,0,T);return{code:kr(v,{generator:wn})}}async function Vr(e,i){let a=Rr(e,i);return{code:a?a.code:e,map:a?.map??null}}function Or(e={}){let i={projectRoot:process.cwd(),injectComponentSource:!0,injectJsxSource:!0,...e};return{kind:"swc",name:"react-code-locator/swc",options:i,config:{transform:(o,h)=>Vr(o,{...i,...h})}}}var Tn=Or();0&&(module.exports={createSwcSourceAdapter,swcSourceAdapter,transformSourceWithSwcLocator});
39
+ `;return Lr.parse(e,{ecmaVersion:"latest",sourceType:"module"}).body[0]}function _n(e,i){return{type:"CallExpression",callee:{type:"Identifier",name:"_markReactElementSource"},arguments:[e,{type:"Literal",value:i}],optional:!1}}function Rr(e,i){let{filename:a,projectRoot:o=process.cwd(),injectJsxSource:h=!0,injectComponentSource:x=!0}=i,v;try{v=Cn(a).parse(e,{ecmaVersion:"latest",sourceType:"module",locations:!0})}catch{return null}let k=!1,_=!1,l=new Set,M=[];if(Er(v,{enter(z,Q){if(h&&z.type==="CallExpression"&&kn(z)){let T=z.loc;T&&(this.replace(_n(z,ji(a,T.start,o))),this.skip(),_=!0,k=!0)}if(x&&z.type==="FunctionDeclaration"){let T=z.id?.name;T&&Pr(T)&&!l.has(T)&&z.loc&&(M.push({node:z,parent:Q,assignment:Ir(T,ji(a,z.loc.start,o))}),l.add(T),k=!0)}if(x&&z.type==="VariableDeclarator"){let T=z.id;if(T.type==="Identifier"&&Pr(T.name)&&!l.has(T.name)){let I=z.init;if(I&&An(I)){let D=z.loc||I.loc;D&&(M.push({node:z,parent:Q,assignment:Ir(T.name,ji(a,D.start,o))}),l.add(T.name),k=!0)}}}}}),!k)return null;if(_){let z=En();v.body.some(T=>T.type==="FunctionDeclaration"&&T.id?.name==="_markReactElementSource")||v.body.unshift(z)}for(let{node:z,parent:Q,assignment:T}of M.reverse())if(Q?.type==="Program"){let I=v.body.indexOf(z);I!==-1&&v.body.splice(I+1,0,T)}else if(Q?.type==="ExportNamedDeclaration"){let I=v.body.find(D=>D.type==="ExportNamedDeclaration"&&D.declaration===Q);I&&v.body.splice(v.body.indexOf(I)+1,0,T)}else Q?.type==="ExportDefaultDeclaration"&&v.body.splice(v.body.indexOf(Q)+1,0,T);return{code:kr(v,{generator:wn})}}async function Vr(e,i){let a=Rr(e,i);return{code:a?a.code:e,map:a?.map??null}}function Or(e={}){let i={projectRoot:process.cwd(),injectComponentSource:!0,injectJsxSource:!0,...e};return{kind:"swc",name:"react-code-locator/swc",options:i,config:{transform:(o,h)=>Vr(o,{...i,...h})}}}var Tn=Or();0&&(module.exports={createSwcSourceAdapter,swcSourceAdapter,transformSourceWithSwcLocator});
40
40
  //# sourceMappingURL=swc.cjs.map