@visulima/rollup-plugin-dts 1.0.0-alpha.15 → 1.0.0-alpha.17
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## @visulima/rollup-plugin-dts [1.0.0-alpha.17](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.16...@visulima/rollup-plugin-dts@1.0.0-alpha.17) (2026-04-24)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* correctly handle peer-dep/types-only/merged-declaration edge cases in DTS ([42b6f7c](https://github.com/visulima/packem/commit/42b6f7c0888b6e51f7755a1afca5954b1e8ba1d3))
|
|
6
|
+
|
|
7
|
+
## @visulima/rollup-plugin-dts [1.0.0-alpha.16](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.15...@visulima/rollup-plugin-dts@1.0.0-alpha.16) (2026-04-24)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **rollup-plugin-dts:** inline bundled-package types in emitted .d.ts ([ce4c00d](https://github.com/visulima/packem/commit/ce4c00d24ebf14b25c799dc51f3b5f8939a9fae3))
|
|
12
|
+
|
|
1
13
|
## @visulima/rollup-plugin-dts [1.0.0-alpha.15](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.14...@visulima/rollup-plugin-dts@1.0.0-alpha.15) (2026-04-24)
|
|
2
14
|
|
|
3
15
|
### Bug Fixes
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}if(e){const
|
|
3
|
-
${
|
|
1
|
+
var $=Object.defineProperty;var p=(t,e)=>$(t,"name",{value:e,configurable:!0});import{createDebug as k}from"obug";import j from"magic-string";import{RE_DTS as m,resolveTemplateFn as I,replaceTemplateName as w,RE_TS as T,RE_VUE as C,RE_JSON as J,RE_CSS as M,filename_to_dts as P,RE_NODE_MODULES as R}from"./filename.js";import{RE_DTS_MAP as ce,RE_JS as de}from"./filename.js";import W from"./packem_shared/createFakeJsPlugin-DhesHehE.js";import{c as A}from"./packem_shared/generate-vg0AGQZR.js";import{resolveOptions as B}from"./packem_shared/resolveOptions-Bp8RzeQ2.js";import F from"node:path";import{ResolverFactory as U}from"oxc-resolver";var q=Object.defineProperty,z=p((t,e)=>q(t,"name",{value:e,configurable:!0}),"o$1");const G=z(({banner:t,footer:e})=>({name:"rollup-plugin-dts:banner",async renderChunk(s,l){if(!m.test(l.fileName))return;const a=new j(s);if(t){const c=await(typeof t=="function"?t(l):t);c&&a.prepend(`${c}
|
|
2
|
+
`)}if(e){const c=await(typeof e=="function"?e(l):e);c&&a.append(`
|
|
3
|
+
${c}`)}return{code:a.toString(),get map(){return a.generateMap({hires:"boundary",includeContent:!0,source:l.fileName})}}}}),"createBannerPlugin");var L=Object.defineProperty,V=p((t,e)=>L(t,"name",{value:e,configurable:!0}),"m");const H=V(({sideEffects:t})=>({name:"rollup-plugin-dts:dts-input",options:t===!1?e=>({treeshake:e.treeshake===!1?!1:{...typeof e.treeshake=="object"&&e.treeshake!==null?e.treeshake:{},moduleSideEffects:!1},...e}):void 0,outputOptions(e){return{...e,entryFileNames(s){const{entryFileNames:l}=e;if(l){const a=I(l,s),c=w(a,s.name);if(m.test(c))return a;const g=w(a,`${s.name}.d`);if(m.test(g))return g}return m.test(s.name)?s.name:s.name.endsWith(".d")?"[name].ts":"[name].d.ts"}}}}),"createDtsInputPlugin");var K=Object.defineProperty,b=p((t,e)=>K(t,"name",{value:e,configurable:!0}),"a");const h=b(t=>T.test(t)||C.test(t)||J.test(t),"isSourceFile"),Q=b(({cwd:t,resolve:e,resolver:s,sideEffects:l,tsconfig:a,tsconfigRaw:c})=>{const g=new U({conditionNames:["types","typings","import","require"],mainFields:["types","typings","module","main"],tsconfig:a?{configFile:a,references:"auto"}:void 0}),v=l?!0:null;return{name:"rollup-plugin-dts:resolver",resolveId:{async handler(n,r,u){if(!r||!m.test(r))return;const o={external:!0,id:n,moduleSideEffects:l};if(M.test(n))return o;if(!y(n)&&E(n)){const i=await O(n,r,null);if(i&&m.test(i))return{id:i,moduleSideEffects:v};if(i&&h(i))return await this.load({id:i}),{id:P(i),moduleSideEffects:v}}const d=await this.resolve(n,r,u);if(d?.external)return o;const f=await O(n,r,d);return f?R.test(f)&&!E(n)&&!(y(n)&&R.test(r)&&N(r))?o:m.test(f)?{id:f,moduleSideEffects:v}:h(f)?(await this.load({id:f}),{id:P(f),moduleSideEffects:v}):null:y(n)?null:o},order:"pre"}};function E(n){return typeof e=="boolean"?e:e.some(r=>typeof r=="string"?n===r:r.test(n))}function N(n){const r=n.replace(/\\/g,"/"),u="/node_modules/",o=r.lastIndexOf(u);if(o<0)return!1;const d=r.slice(o+u.length),f=d.indexOf("/");let i=f===-1?d:d.slice(0,f);if(i.startsWith("@")){const S=d.slice(i.length+1),_=S.indexOf("/"),x=_===-1?S:S.slice(0,_);i=`${i}/${x}`}return E(i)}async function O(n,r,u){let o;if(s==="tsc"){const{default:d}=await import("./packem_chunks/resolver.js");o=d(n,r,t,a,c)}else o=g.resolveDtsSync(r,n).path;return o&&(o=F.normalize(o)),!o||!h(o)?u&&y(u.id)&&h(u.id)&&!u.external?u.id:null:o}},"createDtsResolvePlugin"),y=b(t=>t.startsWith(".")||F.isAbsolute(t),"isFilePath");var X=Object.defineProperty,Y=p((t,e)=>X(t,"name",{value:e,configurable:!0}),"o");const D=k("rollup-plugin-dts:options"),le=Y((t={})=>{D("resolving dts options");const e=B(t);D("resolved dts options %o",e);const s=[];return t.dtsInput?s.push(H(e)):s.push(A(e)),s.push(Q(e),W(e)),(t.banner||t.footer)&&s.push(G(e)),s},"dts");export{M as RE_CSS,m as RE_DTS,ce as RE_DTS_MAP,de as RE_JS,J as RE_JSON,R as RE_NODE_MODULES,T as RE_TS,C as RE_VUE,W as createFakeJsPlugin,A as createGeneratePlugin,le as dts,B as resolveOptions};
|
package/dist/packem_shared/{createFakeJsPlugin-Yi-FbbFw.js → createFakeJsPlugin-DhesHehE.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
${x}`,{cause:x})}const{comments:i,program:y}=d,C=[];if(i){const x=fe(i);j.set(s,x)}const h=[],v=new Map,n=new Map,r=new Set;for(const[x,o]of y.body.entries()){const k=b(
|
|
3
|
-
${n}`,{cause:n})}const{program:i}=d;if(i.body=Oe(i.body),i.body=Ae(i.body),i.body=i.body.flatMap(n=>{if(ke(n))return[];if(n.type==="ExpressionStatement")return[];const r=Me(n,u,e);if(r===!1)return[];if(r)return[r];if(n.type!=="VariableDeclaration")return[n];if(!Ce(n))return[];const[x,o,k]=n.declarations[0].init.elements,M=x.value,g=Y(M);K(g.decl,{enter(l){l.type!=="CommentBlock"&&(l.leadingComments?.length||delete l.loc)}});for(const[l,S]of n.declarations.entries()){const m={...S.id,typeAnnotation:g.bindings[l].typeAnnotation};R(g.bindings[l],m)}const U=g.primaryChildrenCount??g.children.length,W=g.primaryParamsCount??g.params.length,D=g.primaryDepsCount??g.deps.length;for(let l=0;l<U;l++){const S=k.elements[l];Object.assign(g.children[l],{loc:S.loc})}const J=o.params;for(let l=0;l<W;l++){const S=J[l].name;for(const m of g.params[l].typeParams)m.name=S}const I=o.body.elements;for(let l=0;l<D;l++){const S=g.deps[l];let m=I[l];m&&m.type==="UnaryExpression"&&m.operator==="void"?m={...f.identifier("undefined"),end:m.end,loc:m.loc,start:m.start}:G(m)&&(m.name="__Infer"),S.replace?S.replace(m):Object.assign(S,m)}g.decl.type==="TSModuleDeclaration"&&g.resolvedModuleId&&(g.decl.id.value=z+g.resolvedModuleId);const O=[];if(g.overloads)for(const l of g.overloads){K(l.decl,{enter(S){S.type!=="CommentBlock"&&delete S.loc}}),"id"in l.decl&&l.decl.id&&R(l.decl.id,{...g.bindings[0]});for(const[S,m]of l.children.entries()){const T=k.elements[l.childrenOffset+S];T&&Object.assign(m,{loc:T.loc})}for(const[S,m]of l.params.entries()){const T=J[l.paramsOffset+S];if(T)for(const Q of m.typeParams)Q.name=T.name}for(const[S,m]of l.deps.entries()){let T=I[l.depsOffset+S];T&&(T.type==="UnaryExpression"&&T.operator==="void"?T={...f.identifier("undefined"),end:T.end,loc:T.loc,start:T.start}:G(T)&&(T.name="__Infer"),m.replace?m.replace(T):Object.assign(m,T))}O.push(l.decl)}return[Re(n,g.decl),...O]}).filter(n=>!!n),i.body.length===0)return"export { };";const y=i.body.some(n=>n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration"||n.type==="ExportAllDeclaration"),C=i.body.some(n=>n.type==="TSModuleDeclaration"&&n.id.type==="StringLiteral");!y&&C&&i.body.push({declaration:null,source:null,specifiers:[],type:"ExportNamedDeclaration"});const h=new Set,v=new Set;for(const n of s.moduleIds){const r=j.get(n);r&&(r.forEach(x=>{const o=x.type+x.value;v.has(o)||(v.add(o),h.add(x))}),j.delete(n))}return h.size>0&&(i.body[0].leadingComments||=[],i.body[0].leadingComments.unshift(...h)),ae(d,{comments:!0,sourceFileName:s.fileName,sourceMaps:E})}function L(c,s){return s in c?c[s]++:c[s]=0}function q(c){const s=t++;return w.set(s,c),s}function Y(c){return w.get(c)}function me(c){const s=[];K(c,{leave(d){"typeParameters"in d&&d.typeParameters?.type==="TSTypeParameterDeclaration"&&s.push(...d.typeParameters.params)}});const u=new Map;for(const d of s){const{name:i}=d,y=u.get(i);y?y.push(d):u.set(i,[d])}return Array.from(u.entries(),([d,i])=>({name:d,typeParams:i}))}function ye(c){const s=[];return K(c,{enter(u){u.type==="TSInferType"&&u.typeParameter&&s.push(u.typeParameter.name)}}),s}function he(c,s,u,d){const i=new Set,y=new Set,C=[];let h=new Set;function v(r){return r.type==="Identifier"&&h.has(r.name)}return _(v,"b"),b(v,"isInferred"),K(c,{enter(r){if(r.type==="TSConditionalType"){const x=ye(r.extendsType);C.push(x)}},leave(r,x){if(r.type==="TSConditionalType")C.pop();else if(x?.type==="TSConditionalType"){const o=x.trueType===r;h=new Set((o?C:C.slice(0,-1)).flat())}else h=new Set;if(r.type==="ExportNamedDeclaration")for(const o of r.specifiers)o.type==="ExportSpecifier"&&n(o.local);else if(r.type==="TSInterfaceDeclaration"&&r.extends)for(const o of r.extends||[])n(F(o.expression));else if(r.type==="ClassDeclaration"){if(r.superClass&&n(r.superClass),r.implements)for(const o of r.implements)o.type!=="ClassImplements"&&n(F(o.expression))}else if($(r,["ObjectMethod","ObjectProperty","ClassProperty","TSPropertySignature","TSDeclareMethod"]))r.computed&&ce(r.key)&&n(r.key),"value"in r&&ce(r.value)&&n(r.value);else switch(r.type){case"TSImportType":{y.add(r);const o=r.argument,k=r.qualifier,M=xe(r,k,o,s,d);n(M);break}case"TSTypeQuery":{if(y.has(r.exprName))return;if(r.exprName.type==="TSImportType")break;n(F(r.exprName));break}case"TSTypeReference":{n(F(r.typeName));break}}x&&!i.has(r)&&de(r,x)&&u.add(r)}}),[...i];function n(r){ue(r)||v(r)||i.add(r)}_(n,"P")}function xe(c,s,u,d,i){const y=u.value.replaceAll(/\W/g,"_"),C=`_$${Ee(u.value)?u.value:`${y}${L(i,y)}`}`;let h=f.identifier(C);if(d.has(u.value)?h=d.get(u.value).local:d.set(u.value,{local:h,stmt:f.importDeclaration([f.importNamespaceSpecifier(h)],u)}),s){const n=X(s);R(n,f.tsQualifiedName(h,{...n})),h=s}let v=c;return c.typeParameters?(R(c,f.tsTypeReference(h,c.typeParameters)),v=h):R(c,h),{...F(h),replace(n){R(v,n)}}}},"createFakeJsPlugin");function de(e,a){return!!(e.type==="Identifier"||$(a,["TSPropertySignature","TSMethodSignature"])&&a.key===e)}_(de,"Ie");b(de,"isChildSymbol");const Ne=/\/\s*<reference\s+(?:path|types)=/,fe=b((e,a=!1)=>e.filter(E=>Ne.test(E.value)!==a),"collectReferenceDirectives"),Ce=b(e=>f.isVariableDeclaration(e)&&e.declarations.length>0&&f.isVariableDeclarator(e.declarations[0])&&_e(e.declarations[0].init),"isRuntimeBindingVariableDeclaration"),_e=b(e=>f.isArrayExpression(e)&&je(e.elements),"isRuntimeBindingArrayExpression"),we=b(e=>f.arrayExpression(e),"runtimeBindingArrayExpression"),je=b(e=>{const[a,E,t,w]=e;return a?.type==="NumericLiteral"&&E?.type==="ArrowFunctionExpression"&&t?.type==="ArrayExpression"&&(!w||w.type==="CallExpression")},"isRuntimeBindingArrayElements"),G=b(e=>Z(e,"infer"),"isInfer"),ue=b(e=>Z(e,"this")||e.type==="ThisExpression"||e.type==="MemberExpression"&&ue(e.object),"isThisExpression"),F=b(e=>{if(e.type==="Identifier")return e;const a=F(e.left);return Object.assign(e,f.memberExpression(a,e.right))},"TSEntityNameToRuntime"),X=b(e=>e.type==="Identifier"?e:X(e.left),"getIdFromTSEntityName"),ce=b(e=>$(e,["Identifier","MemberExpression"]),"isReferenceId"),ke=b(e=>e.type==="ImportDeclaration"&&e.specifiers.length===1&&e.specifiers.every(a=>a.type==="ImportSpecifier"&&a.imported.type==="Identifier"&&["__export","__reExport"].includes(a.local.name)),"isHelperImport"),Me=b((e,a,E)=>{if(e.type==="ExportNamedDeclaration"&&!e.declaration&&!e.source&&e.specifiers.length===0&&!e.attributes?.length)return!1;if(e.type==="ImportDeclaration"&&e.specifiers.length)for(const t of e.specifiers)G(t.local)&&(t.local.name="__Infer");if($(e,["ImportDeclaration","ExportAllDeclaration","ExportNamedDeclaration"])){if(e.type==="ExportNamedDeclaration"&&a.length>0)for(const t of e.specifiers){const w=H(t.exported);a.includes(w)&&(t.type==="ExportSpecifier"?t.exportKind="type":e.exportKind="type")}if(e.source?.value&&A.test(e.source.value))return e.source.value=pe(e.source.value,"js"),e;if(E&&e.type==="ExportNamedDeclaration"&&!e.source&&e.specifiers.length===1&&e.specifiers[0].type==="ExportSpecifier"&&H(e.specifiers[0].exported)==="default")return{expression:e.specifiers[0].local,type:"TSExportAssignment"}}},"patchImportExport"),Oe=b(e=>{const a=new Set;for(const[t,w]of e.entries()){const j=E(w);if(!j)continue;const[V,B]=j;B.properties.length!==0&&(e[t]={body:{body:[{declaration:null,source:null,specifiers:B.properties.filter(P=>P.type==="ObjectProperty").map(P=>{const L=P.value.body,q=P.key;return f.exportSpecifier(L,q)}),type:"ExportNamedDeclaration"}],type:"TSModuleBlock"},declare:!0,id:V,kind:"namespace",type:"TSModuleDeclaration"})}return e.filter(t=>!a.has(t));function E(t){if(t.type!=="VariableDeclaration"||t.declarations.length!==1||t.declarations[0].id.type!=="Identifier"||t.declarations[0].init?.type!=="CallExpression"||t.declarations[0].init.callee.type!=="Identifier"||t.declarations[0].init.callee.name!=="__export"||t.declarations[0].init.arguments.length!==1||t.declarations[0].init.arguments[0].type!=="ObjectExpression")return!1;const w=t.declarations[0].id,j=t.declarations[0].init.arguments[0];return[w,j]}},"patchTsNamespace"),Ae=b(e=>{const a=new Map;for(const[E,t]of e.entries())if(t.type==="ImportDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ImportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&t.specifiers[0].local.name.endsWith("_exports"))a.set(t.specifiers[0].local.name,t.specifiers[0].local.name);else if(t.type==="ExpressionStatement"&&t.expression.type==="CallExpression"&&Z(t.expression.callee,"__reExport")){const w=t.expression.arguments;a.set(w[0].name,w[1].name)}else t.type==="VariableDeclaration"&&t.declarations.length===1&&t.declarations[0].init?.type==="MemberExpression"&&t.declarations[0].init.object.type==="Identifier"&&a.has(t.declarations[0].init.object.name)?e[E]={id:{name:t.declarations[0].id.name,type:"Identifier"},type:"TSTypeAliasDeclaration",typeAnnotation:{type:"TSTypeReference",typeName:{left:{name:a.get(t.declarations[0].init.object.name),type:"Identifier"},right:{name:t.declarations[0].init.property.name,type:"Identifier"},type:"TSQualifiedName"}}}:t.type==="ExportNamedDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ExportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&a.has(t.specifiers[0].local.name)&&(t.specifiers[0].local.name=a.get(t.specifiers[0].local.name));return e},"patchReExport"),Pe=b((e,a,E)=>{if(e.type==="ImportDeclaration"||e.type==="ExportNamedDeclaration"&&!e.declaration){for(const t of e.specifiers)("exportKind"in t&&t.exportKind==="type"||"exportKind"in e&&e.exportKind==="type")&&E.push(H(t.exported)),t.type==="ImportSpecifier"?t.importKind="value":t.type==="ExportSpecifier"&&(t.exportKind="value");return e.type==="ImportDeclaration"?e.importKind="value":e.type==="ExportNamedDeclaration"&&(e.exportKind="value"),!0}return e.type==="ExportAllDeclaration"?(e.exportKind="value",!0):e.type==="TSImportEqualsDeclaration"?(e.moduleReference.type==="TSExternalModuleReference"&&a({source:e.moduleReference.expression,specifiers:[{local:e.id,type:"ImportDefaultSpecifier"}],type:"ImportDeclaration"}),!0):e.type==="TSExportAssignment"&&e.expression.type==="Identifier"?(a({specifiers:[{exported:{name:"default",type:"Identifier"},local:e.expression,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):e.type==="ExportDefaultDeclaration"&&e.declaration.type==="Identifier"?(a({specifiers:[{exported:f.identifier("default"),local:e.declaration,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):!1},"rewriteImportExport"),R=b((e,a)=>{for(const E of Object.keys(e))delete e[E];return Object.assign(e,a),e},"overwriteNode"),Re=b((e,a)=>{a.leadingComments||=[];const E=e.leadingComments?.filter(t=>t.value.startsWith("#"));return E&&a.leadingComments.unshift(...E),a.leadingComments=fe(a.leadingComments,!0),a},"inheritNodeComments");export{Qe as default};
|
|
1
|
+
var Ee=Object.defineProperty;var _=(e,a)=>Ee(e,"name",{value:a,configurable:!0});import ne from"node:path";import{generate as ae}from"@babel/generator";import{isIdentifierName as Se}from"@babel/helper-validator-identifier";import{parse as se}from"@babel/parser";import f from"@babel/types";import{isTypeOf as $,isDeclarationType as be,walkAST as K,resolveString as H,isIdentifierOf as Z}from"ast-kit";import{RE_DTS as A,resolveTemplateFn as De,filename_js_to_dts as oe,replaceTemplateName as le,filename_dts_to as ce,RE_DTS_MAP as ve,filename_to_dts as Te}from"../filename.js";var Ie=Object.defineProperty,b=_((e,a)=>Ie(e,"name",{value:a,configurable:!0}),"c");const z="__rollup_dts_resolve__:",Qe=b(({cjsDefault:e,sideEffects:a,sourcemap:S})=>{let t=0;const w=new Map,j=new Map,V=new Map;return{generateBundle(p,s){const u=new Map;for(const i of Object.values(s))if(i.type==="chunk")for(const y of i.moduleIds)u.set(y,i.fileName);const d=new RegExp(`"${z}(.+?)"`,"g");for(const i of Object.values(s))i.type!=="chunk"||!A.test(i.fileName)||i.code.includes(z)&&(i.code=i.code.replaceAll(d,(y,C)=>{const h=u.get(C);if(!h)return y;let v=ne.posix.relative(ne.posix.dirname(i.fileName),h);return v.startsWith(".")||(v=`./${v}`),v=ce(v,"js"),JSON.stringify(v)}));for(const i of Object.values(s))if(ve.test(i.fileName))if(S){if(i.type==="chunk"||typeof i.source!="string")continue;const y=JSON.parse(i.source);y.sourcesContent=void 0,i.source=JSON.stringify(y)}else delete s[i.fileName]},name:"rollup-plugin-dts:fake-js",outputOptions(p){const{chunkFileNames:s,entryFileNames:u}=p;return(p.format==="cjs"||p.format==="commonjs")&&(p={...p,format:"es"}),{...p,chunkFileNames(d){const i=De(d.isEntry?u||"[name].js":s||"[name]-[hash].js",d);if(d.name.endsWith(".d")){const y=oe(le(i,d.name.slice(0,-2)));if(A.test(y))return y;const C=oe(le(i,d.name));if(A.test(C))return C}return i},sourcemap:p.sourcemap||S}},renderChunk:P,async transform(p,s){if(A.test(s))return B.call(this,p,s)}};async function B(p,s){const u=Object.create(null);let d;try{d=se(p,{createParenthesizedExpressions:!0,errorRecovery:!0,plugins:[["typescript",{dts:!0}],"decoratorAutoAccessors"],sourceType:"module"})}catch(x){throw new Error(`Failed to parse ${s}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/visulima/packem
|
|
2
|
+
${x}`,{cause:x})}const{comments:i,program:y}=d,C=[];if(i){const x=fe(i);j.set(s,x)}const h=[],v=new Map,n=new Map,r=new Set;for(const[x,o]of y.body.entries()){const k=b(c=>y.body[x]=c,"setStmt");if(Pe(o,k,C))continue;const M=o.type==="TSModuleDeclaration"&&o.kind!=="namespace";let g;if(M&&o.id.type==="StringLiteral"){const c=await this.resolve(o.id.value,s);c&&!c.external?g=A.test(c.id)?c.id:Te(c.id):o.id.value[0]==="."&&this.warn(`\`declare module ${JSON.stringify(o.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${s}.`)}if(M&&s.endsWith(".vue.d.ts")&&p.slice(o.start,o.end).includes("__VLS_"))continue;const U=o.type==="ExportDefaultDeclaration",W=$(o,["ExportNamedDeclaration","ExportDefaultDeclaration"])&&o.declaration,T=W?o.declaration:o,J=W?c=>o.declaration=c:k;if(T.type!=="TSDeclareFunction"&&!be(T))continue;$(T,["TSEnumDeclaration","ClassDeclaration","FunctionDeclaration","TSDeclareFunction","TSModuleDeclaration","VariableDeclaration"])&&(T.declare=!0);const I=[];if(T.type==="VariableDeclaration")I.push(...T.declarations.map(c=>c.id));else if("id"in T&&T.id){let c=T.id;c.type==="TSQualifiedName"&&(c=X(c)),c=M?f.identifier(`_${L(u,"")}`):c,I.push(c)}else{const c=f.identifier("export_default");I.push(c),T.id=c}const O=me(T),l=new Set,E=he(T,v,l,u),m=[...l].filter(c=>I.every(N=>c!==N));if(T!==o&&(T.leadingComments=o.leadingComments),I.length===1&&n.has(I[0].name)){const c=n.get(I[0].name),N=Y(c);N.overloads||(N.overloads=[],N.primaryDepsCount=N.deps.length,N.primaryParamsCount=N.params.length,N.primaryChildrenCount=N.children.length),N.overloads.push({children:m,childrenOffset:N.children.length,decl:T,deps:E,depsOffset:N.deps.length,params:O,paramsOffset:N.params.length}),N.deps.push(...E),N.params.push(...O),N.children.push(...m),r.add(x);continue}const D=q({bindings:I,children:m,decl:T,deps:E,params:O,resolvedModuleId:g});I.length===1&&n.set(I[0].name,D);const Q=f.numericLiteral(D),ee=f.arrowFunctionExpression(O.map(({name:c})=>f.identifier(c)),f.arrayExpression(E)),te=f.arrayExpression(m.map(c=>({end:c.end,loc:c.loc,start:c.start,type:"StringLiteral",value:""}))),re=M&&f.callExpression(f.identifier("sideEffect"),[I[0]]),ge=we(re?[Q,ee,te,re]:[Q,ee,te]),ie={declarations:[{id:{...I[0],typeAnnotation:null},init:ge,type:"VariableDeclarator"},...I.slice(1).map(c=>({id:{...c,typeAnnotation:null},type:"VariableDeclarator"}))],kind:"var",type:"VariableDeclaration"};U?(h.push(f.exportNamedDeclaration(null,[f.exportSpecifier(I[0],f.identifier("default"))])),k(ie)):J(ie)}return a&&h.push(f.expressionStatement(f.callExpression(f.identifier("sideEffect"),[]))),y.body=[...Array.from(v.values(),({stmt:x})=>x),...y.body.filter((x,o)=>!r.has(o)),...h],V.set(s,C),ae(d,{comments:!1,sourceFileName:s,sourceMaps:S})}function P(p,s){if(!A.test(s.fileName))return;const u=[];for(const n of s.moduleIds){const r=V.get(n);r&&u.push(...r)}let d;try{d=se(p,{sourceType:"module"})}catch(n){throw new Error(`Failed to parse generated code for chunk ${s.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/visulima/packem
|
|
3
|
+
${n}`,{cause:n})}const{program:i}=d;if(i.body=Oe(i.body),i.body=Ae(i.body),i.body=i.body.flatMap(n=>{if(ke(n))return[];if(n.type==="ExpressionStatement")return[];const r=Me(n,u,e);if(r===!1)return[];if(r)return[r];if(n.type!=="VariableDeclaration")return[n];if(!Ce(n))return[];const[x,o,k]=n.declarations[0].init.elements,M=x.value,g=Y(M);K(g.decl,{enter(l){l.type!=="CommentBlock"&&(l.leadingComments?.length||delete l.loc)}});for(const[l,E]of n.declarations.entries()){const m={...E.id,typeAnnotation:g.bindings[l].typeAnnotation};R(g.bindings[l],m)}const U=g.primaryChildrenCount??g.children.length,W=g.primaryParamsCount??g.params.length,T=g.primaryDepsCount??g.deps.length;for(let l=0;l<U;l++){const E=k.elements[l];Object.assign(g.children[l],{loc:E.loc})}const J=o.params;for(let l=0;l<W;l++){const E=J[l].name;for(const m of g.params[l].typeParams)m.name=E}const I=o.body.elements;for(let l=0;l<T;l++){const E=g.deps[l];let m=I[l];m&&m.type==="UnaryExpression"&&m.operator==="void"?m={...f.identifier("undefined"),end:m.end,loc:m.loc,start:m.start}:G(m)&&(m.name="__Infer"),E.replace?E.replace(m):Object.assign(E,m)}g.decl.type==="TSModuleDeclaration"&&g.resolvedModuleId&&(g.decl.id.value=z+g.resolvedModuleId);const O=[];if(g.overloads)for(const l of g.overloads){K(l.decl,{enter(E){E.type!=="CommentBlock"&&delete E.loc}}),"id"in l.decl&&l.decl.id&&R(l.decl.id,{...g.bindings[0]});for(const[E,m]of l.children.entries()){const D=k.elements[l.childrenOffset+E];D&&Object.assign(m,{loc:D.loc})}for(const[E,m]of l.params.entries()){const D=J[l.paramsOffset+E];if(D)for(const Q of m.typeParams)Q.name=D.name}for(const[E,m]of l.deps.entries()){let D=I[l.depsOffset+E];D&&(D.type==="UnaryExpression"&&D.operator==="void"?D={...f.identifier("undefined"),end:D.end,loc:D.loc,start:D.start}:G(D)&&(D.name="__Infer"),m.replace?m.replace(D):Object.assign(m,D))}O.push(l.decl)}return[Re(n,g.decl),...O]}).filter(n=>!!n),i.body.length===0)return"export { };";const y=i.body.some(n=>n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration"||n.type==="ExportAllDeclaration"),C=i.body.some(n=>n.type==="TSModuleDeclaration"&&n.id.type==="StringLiteral");!y&&C&&i.body.push({declaration:null,source:null,specifiers:[],type:"ExportNamedDeclaration"});const h=new Set,v=new Set;for(const n of s.moduleIds){const r=j.get(n);r&&(r.forEach(x=>{const o=x.type+x.value;v.has(o)||(v.add(o),h.add(x))}),j.delete(n))}return h.size>0&&(i.body[0].leadingComments||=[],i.body[0].leadingComments.unshift(...h)),ae(d,{comments:!0,sourceFileName:s.fileName,sourceMaps:S})}function L(p,s){return s in p?p[s]++:p[s]=0}function q(p){const s=t++;return w.set(s,p),s}function Y(p){return w.get(p)}function me(p){const s=[];K(p,{leave(d){"typeParameters"in d&&d.typeParameters?.type==="TSTypeParameterDeclaration"&&s.push(...d.typeParameters.params)}});const u=new Map;for(const d of s){const{name:i}=d,y=u.get(i);y?y.push(d):u.set(i,[d])}return Array.from(u.entries(),([d,i])=>({name:d,typeParams:i}))}function ye(p){const s=[];return K(p,{enter(u){u.type==="TSInferType"&&u.typeParameter&&s.push(u.typeParameter.name)}}),s}function he(p,s,u,d){const i=new Set,y=new Set,C=[];let h=new Set;function v(r){return r.type==="Identifier"&&h.has(r.name)}return _(v,"b"),b(v,"isInferred"),K(p,{enter(r){if(r.type==="TSConditionalType"){const x=ye(r.extendsType);C.push(x)}},leave(r,x){if(r.type==="TSConditionalType")C.pop();else if(x?.type==="TSConditionalType"){const o=x.trueType===r;h=new Set((o?C:C.slice(0,-1)).flat())}else h=new Set;if(r.type==="ExportNamedDeclaration")for(const o of r.specifiers)o.type==="ExportSpecifier"&&n(o.local);else if(r.type==="TSInterfaceDeclaration"&&r.extends)for(const o of r.extends||[])n(F(o.expression));else if(r.type==="ClassDeclaration"){if(r.superClass&&n(r.superClass),r.implements)for(const o of r.implements)o.type!=="ClassImplements"&&n(F(o.expression))}else if($(r,["ObjectMethod","ObjectProperty","ClassProperty","TSPropertySignature","TSDeclareMethod"]))r.computed&&pe(r.key)&&n(r.key),"value"in r&&pe(r.value)&&n(r.value);else switch(r.type){case"TSImportType":{y.add(r);const o=r.argument,k=r.qualifier,M=xe(r,k,o,s,d);n(M);break}case"TSTypeQuery":{if(y.has(r.exprName))return;if(r.exprName.type==="TSImportType")break;n(F(r.exprName));break}case"TSTypeReference":{n(F(r.typeName));break}}x&&!i.has(r)&&de(r,x)&&u.add(r)}}),[...i];function n(r){ue(r)||v(r)||i.add(r)}_(n,"P")}function xe(p,s,u,d,i){const y=u.value.replaceAll(/\W/g,"_"),C=`_$${Se(u.value)?u.value:`${y}${L(i,y)}`}`;let h=f.identifier(C);if(d.has(u.value)?h=d.get(u.value).local:d.set(u.value,{local:h,stmt:f.importDeclaration([f.importNamespaceSpecifier(h)],u)}),s){const n=X(s);R(n,f.tsQualifiedName(h,{...n})),h=s}let v=p;return p.typeParameters?(R(p,f.tsTypeReference(h,p.typeParameters)),v=h):R(p,h),{...F(h),replace(n){R(v,n)}}}},"createFakeJsPlugin");function de(e,a){return!!(e.type==="Identifier"||$(a,["TSPropertySignature","TSMethodSignature"])&&a.key===e)}_(de,"Ie");b(de,"isChildSymbol");const Ne=/\/\s*<reference\s+(?:path|types)=/,fe=b((e,a=!1)=>e.filter(S=>Ne.test(S.value)!==a),"collectReferenceDirectives"),Ce=b(e=>f.isVariableDeclaration(e)&&e.declarations.length>0&&f.isVariableDeclarator(e.declarations[0])&&_e(e.declarations[0].init),"isRuntimeBindingVariableDeclaration"),_e=b(e=>f.isArrayExpression(e)&&je(e.elements),"isRuntimeBindingArrayExpression"),we=b(e=>f.arrayExpression(e),"runtimeBindingArrayExpression"),je=b(e=>{const[a,S,t,w]=e;return a?.type==="NumericLiteral"&&S?.type==="ArrowFunctionExpression"&&t?.type==="ArrayExpression"&&(!w||w.type==="CallExpression")},"isRuntimeBindingArrayElements"),G=b(e=>Z(e,"infer"),"isInfer"),ue=b(e=>Z(e,"this")||e.type==="ThisExpression"||e.type==="MemberExpression"&&ue(e.object),"isThisExpression"),F=b(e=>{if(e.type==="Identifier")return e;const a=F(e.left);return Object.assign(e,f.memberExpression(a,e.right))},"TSEntityNameToRuntime"),X=b(e=>e.type==="Identifier"?e:X(e.left),"getIdFromTSEntityName"),pe=b(e=>$(e,["Identifier","MemberExpression"]),"isReferenceId"),ke=b(e=>e.type==="ImportDeclaration"&&e.specifiers.length===1&&e.specifiers.every(a=>a.type==="ImportSpecifier"&&a.imported.type==="Identifier"&&["__export","__reExport"].includes(a.local.name)),"isHelperImport"),Me=b((e,a,S)=>{if(e.type==="ExportNamedDeclaration"&&!e.declaration&&!e.source&&e.specifiers.length===0&&!e.attributes?.length)return!1;if(e.type==="ImportDeclaration"&&e.specifiers.length)for(const t of e.specifiers)G(t.local)&&(t.local.name="__Infer");if($(e,["ImportDeclaration","ExportAllDeclaration","ExportNamedDeclaration"])){if(e.type==="ExportNamedDeclaration"&&a.length>0)for(const t of e.specifiers){const w=H(t.exported);a.includes(w)&&(t.type==="ExportSpecifier"?t.exportKind="type":e.exportKind="type")}if(e.source?.value&&A.test(e.source.value))return e.source.value=ce(e.source.value,"js"),e;if(S&&e.type==="ExportNamedDeclaration"&&!e.source&&e.specifiers.length===1&&e.specifiers[0].type==="ExportSpecifier"&&H(e.specifiers[0].exported)==="default")return{expression:e.specifiers[0].local,type:"TSExportAssignment"}}},"patchImportExport"),Oe=b(e=>{const a=new Set;for(const[t,w]of e.entries()){const j=S(w);if(!j)continue;const[V,B]=j;B.properties.length!==0&&(e[t]={body:{body:[{declaration:null,source:null,specifiers:B.properties.filter(P=>P.type==="ObjectProperty").map(P=>{const L=P.value.body,q=P.key;return f.exportSpecifier(L,q)}),type:"ExportNamedDeclaration"}],type:"TSModuleBlock"},declare:!0,id:V,kind:"namespace",type:"TSModuleDeclaration"})}return e.filter(t=>!a.has(t));function S(t){if(t.type!=="VariableDeclaration"||t.declarations.length!==1||t.declarations[0].id.type!=="Identifier"||t.declarations[0].init?.type!=="CallExpression"||t.declarations[0].init.callee.type!=="Identifier"||t.declarations[0].init.callee.name!=="__export"||t.declarations[0].init.arguments.length!==1||t.declarations[0].init.arguments[0].type!=="ObjectExpression")return!1;const w=t.declarations[0].id,j=t.declarations[0].init.arguments[0];return[w,j]}},"patchTsNamespace"),Ae=b(e=>{const a=new Map;for(const[S,t]of e.entries())if(t.type==="ImportDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ImportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&t.specifiers[0].local.name.endsWith("_exports"))a.set(t.specifiers[0].local.name,t.specifiers[0].local.name);else if(t.type==="ExpressionStatement"&&t.expression.type==="CallExpression"&&Z(t.expression.callee,"__reExport")){const w=t.expression.arguments;a.set(w[0].name,w[1].name)}else t.type==="VariableDeclaration"&&t.declarations.length===1&&t.declarations[0].init?.type==="MemberExpression"&&t.declarations[0].init.object.type==="Identifier"&&a.has(t.declarations[0].init.object.name)?e[S]={id:{name:t.declarations[0].id.name,type:"Identifier"},type:"TSTypeAliasDeclaration",typeAnnotation:{type:"TSTypeReference",typeName:{left:{name:a.get(t.declarations[0].init.object.name),type:"Identifier"},right:{name:t.declarations[0].init.property.name,type:"Identifier"},type:"TSQualifiedName"}}}:t.type==="ExportNamedDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ExportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&a.has(t.specifiers[0].local.name)&&(t.specifiers[0].local.name=a.get(t.specifiers[0].local.name));return e},"patchReExport"),Pe=b((e,a,S)=>{if(e.type==="ImportDeclaration"||e.type==="ExportNamedDeclaration"&&!e.declaration){for(const t of e.specifiers)("exportKind"in t&&t.exportKind==="type"||"exportKind"in e&&e.exportKind==="type")&&S.push(H(t.exported)),t.type==="ImportSpecifier"?t.importKind="value":t.type==="ExportSpecifier"&&(t.exportKind="value");return e.type==="ImportDeclaration"?e.importKind="value":e.type==="ExportNamedDeclaration"&&(e.exportKind="value"),!0}return e.type==="ExportAllDeclaration"?(e.exportKind="value",!0):e.type==="TSImportEqualsDeclaration"?(e.moduleReference.type==="TSExternalModuleReference"&&a({source:e.moduleReference.expression,specifiers:[{local:e.id,type:"ImportDefaultSpecifier"}],type:"ImportDeclaration"}),!0):e.type==="TSExportAssignment"&&e.expression.type==="Identifier"?(a({specifiers:[{exported:{name:"default",type:"Identifier"},local:e.expression,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):e.type==="ExportDefaultDeclaration"&&e.declaration.type==="Identifier"?(a({specifiers:[{exported:f.identifier("default"),local:e.declaration,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):!1},"rewriteImportExport"),R=b((e,a)=>{for(const S of Object.keys(e))delete e[S];return Object.assign(e,a),e},"overwriteNode"),Re=b((e,a)=>{a.leadingComments||=[];const S=e.leadingComments?.filter(t=>t.value.startsWith("#"));return S&&a.leadingComments.unshift(...S),a.leadingComments=fe(a.leadingComments,!0),a},"inheritNodeComments");export{Qe as default};
|
package/package.json
CHANGED