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/esbuild.js CHANGED
@@ -36,5 +36,5 @@ function _markReactElementSource(element, source) {
36
36
  }
37
37
  return element;
38
38
  }
39
- `;return Ir.parse(e,{ecmaVersion:"latest",sourceType:"module"}).body[0]}function kn(e,i){return{type:"CallExpression",callee:{type:"Identifier",name:"_markReactElementSource"},arguments:[e,{type:"Literal",value:i}],optional:!1}}function Nr(e,i){let{filename:a,projectRoot:o=process.cwd(),injectJsxSource:h=!0,injectComponentSource:x=!0}=i,v;try{v=gn(a).parse(e,{ecmaVersion:"latest",sourceType:"module",locations:!0})}catch{return null}let k=!1,_=!1,l=new Set,M=[];if(kr(v,{enter(z,Q){if(h&&z.type==="CallExpression"&&Sn(z)){let T=z.loc;T&&(this.replace(kn(z,ji(a,T.start,o))),_=!0,k=!0)}if(x&&z.type==="FunctionDeclaration"){let T=z.id?.name;T&&_r(T)&&!l.has(T)&&z.loc&&(M.push({node:z,parent:Q,assignment:Tr(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"&&_r(T.name)&&!l.has(T.name)){let I=z.init;if(I&&Cn(I)){let D=z.loc||I.loc;D&&(M.push({node:z,parent:Q,assignment:Tr(T.name,ji(a,D.start,o))}),l.add(T.name),k=!0)}}}}}),!k)return null;if(_){let z=wn();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:Cr(v,{generator:bn})}}function An(e){return e.endsWith(".tsx")?"tsx":e.endsWith(".ts")?"ts":e.endsWith(".jsx")?"jsx":"js"}function _n(e={}){let{projectRoot:i=process.cwd(),injectComponentSource:a=!0,injectJsxSource:o=!0}=e;return{name:"react-code-locator-source-transform",setup(h){h.onLoad({filter:/\.[mc]?[jt]sx?$/},async({path:x})=>{if(x.includes("/node_modules/"))return null;let v=await En(x,"utf8"),k=Nr(v,{filename:x,projectRoot:i,injectComponentSource:a,injectJsxSource:o});return{contents:k?k.code:v,loader:An(x)}})}}}function Tn(e={}){let i={projectRoot:process.cwd(),injectComponentSource:!0,injectJsxSource:!0,...e};return{kind:"esbuild",name:"react-code-locator/esbuild",options:i,config:{plugins:[_n(i)]}}}var $n=Tn();export{Tn as createEsbuildSourceAdapter,$n as esbuildSourceAdapter,_n as esbuildSourceTransformPlugin};
39
+ `;return Ir.parse(e,{ecmaVersion:"latest",sourceType:"module"}).body[0]}function kn(e,i){return{type:"CallExpression",callee:{type:"Identifier",name:"_markReactElementSource"},arguments:[e,{type:"Literal",value:i}],optional:!1}}function Nr(e,i){let{filename:a,projectRoot:o=process.cwd(),injectJsxSource:h=!0,injectComponentSource:x=!0}=i,v;try{v=gn(a).parse(e,{ecmaVersion:"latest",sourceType:"module",locations:!0})}catch{return null}let k=!1,_=!1,l=new Set,M=[];if(kr(v,{enter(z,Q){if(h&&z.type==="CallExpression"&&Sn(z)){let T=z.loc;T&&(this.replace(kn(z,ji(a,T.start,o))),this.skip(),_=!0,k=!0)}if(x&&z.type==="FunctionDeclaration"){let T=z.id?.name;T&&_r(T)&&!l.has(T)&&z.loc&&(M.push({node:z,parent:Q,assignment:Tr(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"&&_r(T.name)&&!l.has(T.name)){let I=z.init;if(I&&Cn(I)){let D=z.loc||I.loc;D&&(M.push({node:z,parent:Q,assignment:Tr(T.name,ji(a,D.start,o))}),l.add(T.name),k=!0)}}}}}),!k)return null;if(_){let z=wn();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:Cr(v,{generator:bn})}}function An(e){return e.endsWith(".tsx")?"tsx":e.endsWith(".ts")?"ts":e.endsWith(".jsx")?"jsx":"js"}function _n(e={}){let{projectRoot:i=process.cwd(),injectComponentSource:a=!0,injectJsxSource:o=!0}=e;return{name:"react-code-locator-source-transform",setup(h){h.onLoad({filter:/\.[mc]?[jt]sx?$/},async({path:x})=>{if(x.includes("/node_modules/"))return null;let v=await En(x,"utf8"),k=Nr(v,{filename:x,projectRoot:i,injectComponentSource:a,injectJsxSource:o});return{contents:k?k.code:v,loader:An(x)}})}}}function Tn(e={}){let i={projectRoot:process.cwd(),injectComponentSource:!0,injectJsxSource:!0,...e};return{kind:"esbuild",name:"react-code-locator/esbuild",options:i,config:{plugins:[_n(i)]}}}var $n=Tn();export{Tn as createEsbuildSourceAdapter,$n as esbuildSourceAdapter,_n as esbuildSourceTransformPlugin};
40
40
  //# sourceMappingURL=esbuild.js.map