@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
4 lines (3 loc) • 3.26 kB
JavaScript
// @bun
import{a as v,b as R,c as f,d as L,e as b,f as M,g as C,h as g,i as x,j as y,k as S,l as p,m as d,n as u,o as h,p as m,q as r,r as o,s as c}from"../chunk-mjstdqy6.js";function U(w){return w.replace(/^(\s*\/\*[\s\S]*?\*\/\s*|\s*\/\/.*\n)*/g,"").trim()}function V(w,K){let J=w.substring(0,K).split(`
`),G=[],j=J.length-1,N=!1,D=[];while(j>=0){let z=J[j].trim();if(z.endsWith("*/")&&!N)N=!0,D.unshift(z);else if(z.startsWith("/*")&&N)D.unshift(z),G.unshift(...D),D=[],N=!1;else if(N)D.unshift(z);else if(z.startsWith("//"))G.unshift(z);else if(z.startsWith("*")&&(j>0&&J[j-1].trim().startsWith("/*")))G.unshift(z);else if(z===""&&G.length>0);else if(z!=="")break;j--}return G}function W(w){let K=!1,H="",J=!1;for(let G=0;G<w.length;G++){let j=w[G];if(!J&&!K&&(j==='"'||j==="'"||j==="`"))K=!0,H=j;else if(!J&&K&&j===H)K=!1;else if(j==="\\"&&!J){J=!0;continue}else if(!K&&j==="/"&&G<w.length-1){if(w[G+1]==="/")return w.substring(G)}J=!1}return null}function X(w){return w.map((K)=>{return K})}function Q(w,K,H){let J=0,G=!1,j="",N=!1,D=0;if(!w.startsWith(K))return null;for(D=0;D<w.length;D++){let z=w[D],O=D>0?w[D-1]:"";if(!N&&(z==='"'||z==="'"||z==="`")){if(!G)G=!0,j=z;else if(z===j)G=!1}if(z==="\\"&&!N){N=!0;continue}if(N=!1,!G){if(w.substring(D,D+K.length)===K)J++;else if(w.substring(D,D+H.length)===H){if(J--,J===0)return{content:w.substring(0,D+H.length),rest:w.substring(D+H.length)}}}}return null}function Y(w){let K=U(w).trim(),H=K.match(/^(export\s+)?(async\s+)?function\s*(\*?)\s*([a-zA-Z_$][\w$]*)/);if(!H)return null;let J=[];if(H[1])J.push("export");if(H[2])J.push("async");if(H[3])J.push("generator");let G=H[4],j=K.substring(H[0].length).trim(),N="";if(j.startsWith("<")){let O=Q(j,"<",">");if(O)N=O.content,j=O.rest.trim()}let D="";if(j.startsWith("(")){let O=Q(j,"(",")");if(O)D=O.content.slice(1,-1).trim(),j=O.rest.trim()}let z="void";if(j.startsWith(":")){let O=j.match(/^:\s*([^{;]+)/);if(O)z=O[1].trim()}return{name:G,generics:N,parameters:D,returnType:z,modifiers:J}}function Z(w){return/^\s*export\s+/.test(w)}function _(w){return/^\s*export\s+type\s+/.test(w)}function $(w){let K=U(w).trim(),H=K.match(/^(export\s+)?(const|let|var)\s+([a-zA-Z_$][\w$]*)/);if(!H)return null;let J=H[2],G=H[3],j=K.substring(H[0].length).trim(),N;if(j.startsWith(":")){let z=j.indexOf("=");if(z!==-1)N=j.substring(1,z).trim(),j=j.substring(z).trim();else N=j.substring(1).replace(/;?\s*$/,"").trim(),j=""}let D;if(j.startsWith("="))D=j.substring(1).replace(/;?\s*$/,"").trim();return{kind:J,name:G,typeAnnotation:N,value:D}}export{h as writeToFile,U as removeLeadingComments,M as processVariableDeclaration,g as processTypeDeclaration,d as processModuleDeclaration,C as processInterfaceDeclaration,S as processImportDeclaration,b as processFunctionDeclaration,c as processFile,p as processExportDeclaration,y as processEnumDeclaration,L as processDeclarations,x as processClassDeclaration,$ as parseVariableDeclaration,Y as parseFunctionDeclaration,_ as isTypeOnlyExport,Z as isExportStatement,u as inferNarrowType,m as getAllTypeScriptFiles,o as generate,X as formatComments,W as extractTrailingComment,V as extractLeadingComments,f as extractDeclarations,Q as extractBalancedSymbols,v as defaultConfig,R as config,r as checkIsolatedDeclarations};