"use strict";var m=(t,d,a)=>new Promise((o,l)=>{var p=n=>{try{c(a.next(n))}catch(s){l(s)}},e=n=>{try{c(a.throw(n))}catch(s){l(s)}},c=n=>n.done?o(n.value):Promise.resolve(n.value).then(p,e);c((a=a.apply(t,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("code-inspector-core"),x=require("fs"),T=require("path"),v="esbuild-code-inspector-plugin";function b(t){return{name:v,setup(d){if(t.close||!r.isDev(t.dev,!1))return;const a={port:0,entry:"",output:t.output},{escapeTags:o=[]}=t,l=new Map;d.onLoad({filter:t.match||/\.(jsx|tsx|js|ts|mjs|mts)?$/},p=>m(this,null,function*(){let e=p.path;e=r.getMappingFilePath(e,t.mappings);let c=yield x.promises.readFile(e,"utf8"),n=l.get(e);if(!n||n.originCode!==c){let s=c,u=t.exclude||[];Array.isArray(u)||(u=[u]);const h=r.matchCondition([...u,/\/node_modules\//],e),g=r.matchCondition(t.include||[],e);if(h&&!g)return s;s=yield r.getCodeWithWebComponent({options:t,file:e,code:s,record:a});let i="";if(r.isJsTypeFile(e)?i="jsx":e.endsWith(".svelte")&&(i="svelte"),i)s=r.transformCode({content:s,filePath:e,fileType:i,escapeTags:o,pathType:t.pathType});else if(e.endsWith(".vue")){i="vue";const{descriptor:f}=r.parseSFC(s,{sourceMap:!1}),y=r.transformCode({content:f.template.content,filePath:e,fileType:i,escapeTags:o,pathType:t.pathType});s=s.replace(f.template.content,y)}const C=T.extname(e).replace(".","");n={originCode:c,output:{contents:s,loader:C}},l.set(e,n)}return n.output}))}}}exports.EsbuildCodeInspectorPlugin=b;
