rolldown-plugin-dts 0.24.0-beta.1 → 0.24.0-beta.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/index.mjs +123 -35
- package/package.json +11 -14
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { importerId, include } from "rolldown/filter";
|
|
|
7
7
|
import { generate } from "@babel/generator";
|
|
8
8
|
import { isIdentifierName } from "@babel/helper-validator-identifier";
|
|
9
9
|
import { parse } from "@babel/parser";
|
|
10
|
-
import * as t from "@babel/types";
|
|
11
10
|
import { isDeclarationType, isIdentifierOf, isTypeOf, resolveString, walkAST } from "ast-kit";
|
|
12
11
|
import { fork, spawn } from "node:child_process";
|
|
13
12
|
import { existsSync } from "node:fs";
|
|
@@ -141,11 +140,17 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
141
140
|
else if ("id" in decl && decl.id) {
|
|
142
141
|
let binding = decl.id;
|
|
143
142
|
if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
|
|
144
|
-
binding = sideEffect ?
|
|
143
|
+
binding = sideEffect ? {
|
|
144
|
+
type: "Identifier",
|
|
145
|
+
name: `_${getIdentifierIndex(identifierMap, "")}`
|
|
146
|
+
} : binding;
|
|
145
147
|
if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
|
|
146
148
|
bindings.push(binding);
|
|
147
149
|
} else {
|
|
148
|
-
const binding =
|
|
150
|
+
const binding = {
|
|
151
|
+
type: "Identifier",
|
|
152
|
+
name: "export_default"
|
|
153
|
+
};
|
|
149
154
|
bindings.push(binding);
|
|
150
155
|
decl.id = binding;
|
|
151
156
|
}
|
|
@@ -154,23 +159,48 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
154
159
|
const deps = collectDependencies(decl, namespaceStmts, childrenSet, identifierMap);
|
|
155
160
|
const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
|
|
156
161
|
if (decl !== stmt) decl.leadingComments = stmt.leadingComments;
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
162
|
+
const declarationIdNode = {
|
|
163
|
+
type: "NumericLiteral",
|
|
164
|
+
value: registerDeclaration({
|
|
165
|
+
decl,
|
|
166
|
+
deps,
|
|
167
|
+
bindings,
|
|
168
|
+
params,
|
|
169
|
+
children
|
|
170
|
+
})
|
|
171
|
+
};
|
|
172
|
+
const depsBody = {
|
|
173
|
+
type: "ArrayExpression",
|
|
174
|
+
elements: deps
|
|
175
|
+
};
|
|
176
|
+
const depsNode = {
|
|
177
|
+
type: "ArrowFunctionExpression",
|
|
178
|
+
params: params.map(({ name }) => ({
|
|
179
|
+
type: "Identifier",
|
|
180
|
+
name
|
|
181
|
+
})),
|
|
182
|
+
body: depsBody,
|
|
183
|
+
async: false,
|
|
184
|
+
expression: true
|
|
185
|
+
};
|
|
186
|
+
const childrenNode = {
|
|
187
|
+
type: "ArrayExpression",
|
|
188
|
+
elements: children.map((node) => ({
|
|
189
|
+
type: "StringLiteral",
|
|
190
|
+
value: "",
|
|
191
|
+
start: node.start,
|
|
192
|
+
end: node.end,
|
|
193
|
+
loc: node.loc
|
|
194
|
+
}))
|
|
195
|
+
};
|
|
196
|
+
const sideEffectNode = sideEffect && {
|
|
197
|
+
type: "CallExpression",
|
|
198
|
+
callee: {
|
|
199
|
+
type: "Identifier",
|
|
200
|
+
name: "sideEffect"
|
|
201
|
+
},
|
|
202
|
+
arguments: [bindings[0]]
|
|
203
|
+
};
|
|
174
204
|
const runtimeArrayNode = runtimeBindingArrayExpression([
|
|
175
205
|
declarationIdNode,
|
|
176
206
|
depsNode,
|
|
@@ -196,11 +226,34 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
196
226
|
}))]
|
|
197
227
|
};
|
|
198
228
|
if (isDefaultExport) {
|
|
199
|
-
appendStmts.push(
|
|
229
|
+
appendStmts.push({
|
|
230
|
+
type: "ExportNamedDeclaration",
|
|
231
|
+
declaration: null,
|
|
232
|
+
specifiers: [{
|
|
233
|
+
type: "ExportSpecifier",
|
|
234
|
+
local: bindings[0],
|
|
235
|
+
exported: {
|
|
236
|
+
type: "Identifier",
|
|
237
|
+
name: "default"
|
|
238
|
+
}
|
|
239
|
+
}],
|
|
240
|
+
source: null,
|
|
241
|
+
attributes: null
|
|
242
|
+
});
|
|
200
243
|
setStmt(runtimeAssignment);
|
|
201
244
|
} else setDecl(runtimeAssignment);
|
|
202
245
|
}
|
|
203
|
-
if (sideEffects) appendStmts.push(
|
|
246
|
+
if (sideEffects) appendStmts.push({
|
|
247
|
+
type: "ExpressionStatement",
|
|
248
|
+
expression: {
|
|
249
|
+
type: "CallExpression",
|
|
250
|
+
callee: {
|
|
251
|
+
type: "Identifier",
|
|
252
|
+
name: "sideEffect"
|
|
253
|
+
},
|
|
254
|
+
arguments: []
|
|
255
|
+
}
|
|
256
|
+
});
|
|
204
257
|
program.body = [
|
|
205
258
|
...Array.from(namespaceStmts.values()).map(({ stmt }) => stmt),
|
|
206
259
|
...program.body,
|
|
@@ -264,7 +317,8 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
264
317
|
for (const [i, originalDep] of declaration.deps.entries()) {
|
|
265
318
|
let transformedDep = transformedDeps[i];
|
|
266
319
|
if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void") transformedDep = {
|
|
267
|
-
|
|
320
|
+
type: "Identifier",
|
|
321
|
+
name: "undefined",
|
|
268
322
|
loc: transformedDep.loc,
|
|
269
323
|
start: transformedDep.start,
|
|
270
324
|
end: transformedDep.end
|
|
@@ -324,7 +378,10 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
324
378
|
function collectParams(node) {
|
|
325
379
|
const typeParams = [];
|
|
326
380
|
walkAST(node, { leave(node) {
|
|
327
|
-
if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => typeof name === "string" ?
|
|
381
|
+
if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => typeof name === "string" ? {
|
|
382
|
+
type: "Identifier",
|
|
383
|
+
name
|
|
384
|
+
} : name));
|
|
328
385
|
} });
|
|
329
386
|
const paramMap = /* @__PURE__ */ new Map();
|
|
330
387
|
for (const typeParam of typeParams) {
|
|
@@ -404,22 +461,40 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
404
461
|
}
|
|
405
462
|
function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
|
|
406
463
|
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
407
|
-
|
|
408
|
-
|
|
464
|
+
let local = {
|
|
465
|
+
type: "Identifier",
|
|
466
|
+
name: `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`
|
|
467
|
+
};
|
|
409
468
|
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
410
469
|
else namespaceStmts.set(source.value, {
|
|
411
|
-
stmt:
|
|
470
|
+
stmt: {
|
|
471
|
+
type: "ImportDeclaration",
|
|
472
|
+
specifiers: [{
|
|
473
|
+
type: "ImportNamespaceSpecifier",
|
|
474
|
+
local
|
|
475
|
+
}],
|
|
476
|
+
source,
|
|
477
|
+
attributes: null
|
|
478
|
+
},
|
|
412
479
|
local
|
|
413
480
|
});
|
|
414
481
|
if (imported) {
|
|
415
482
|
const importedLeft = getIdFromTSEntityName(imported);
|
|
416
483
|
if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
|
|
417
|
-
overwriteNode(importedLeft,
|
|
484
|
+
overwriteNode(importedLeft, {
|
|
485
|
+
type: "TSQualifiedName",
|
|
486
|
+
left: local,
|
|
487
|
+
right: { ...importedLeft }
|
|
488
|
+
});
|
|
418
489
|
local = imported;
|
|
419
490
|
}
|
|
420
491
|
let replacement = node;
|
|
421
492
|
if (node.typeArguments) {
|
|
422
|
-
overwriteNode(node,
|
|
493
|
+
overwriteNode(node, {
|
|
494
|
+
type: "TSTypeReference",
|
|
495
|
+
typeName: local,
|
|
496
|
+
typeArguments: node.typeArguments
|
|
497
|
+
});
|
|
423
498
|
replacement = local;
|
|
424
499
|
} else overwriteNode(node, local);
|
|
425
500
|
return {
|
|
@@ -466,7 +541,10 @@ function isRuntimeBindingArrayElements(elements) {
|
|
|
466
541
|
return declarationId?.type === "NumericLiteral" && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
|
|
467
542
|
}
|
|
468
543
|
function runtimeBindingArrayExpression(elements) {
|
|
469
|
-
return
|
|
544
|
+
return {
|
|
545
|
+
type: "ArrayExpression",
|
|
546
|
+
elements
|
|
547
|
+
};
|
|
470
548
|
}
|
|
471
549
|
function isThisExpression(node) {
|
|
472
550
|
return isIdentifierOf(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
|
|
@@ -477,7 +555,12 @@ function isInfer(node) {
|
|
|
477
555
|
function TSEntityNameToRuntime(node) {
|
|
478
556
|
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
479
557
|
const left = TSEntityNameToRuntime(node.left);
|
|
480
|
-
return Object.assign(node,
|
|
558
|
+
return Object.assign(node, {
|
|
559
|
+
type: "MemberExpression",
|
|
560
|
+
object: left,
|
|
561
|
+
property: node.right,
|
|
562
|
+
computed: false
|
|
563
|
+
});
|
|
481
564
|
}
|
|
482
565
|
function getIdFromTSEntityName(node) {
|
|
483
566
|
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
@@ -537,9 +620,11 @@ function patchTsNamespace(nodes) {
|
|
|
537
620
|
body: [{
|
|
538
621
|
type: "ExportNamedDeclaration",
|
|
539
622
|
specifiers: exports.properties.filter((property) => property.type === "ObjectProperty").map((property) => {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
623
|
+
return {
|
|
624
|
+
type: "ExportSpecifier",
|
|
625
|
+
local: property.value.body,
|
|
626
|
+
exported: property.key
|
|
627
|
+
};
|
|
543
628
|
}),
|
|
544
629
|
source: null,
|
|
545
630
|
declaration: null
|
|
@@ -628,7 +713,10 @@ function rewriteImportExport(node, set, typeOnlyIds) {
|
|
|
628
713
|
specifiers: [{
|
|
629
714
|
type: "ExportSpecifier",
|
|
630
715
|
local: node.declaration,
|
|
631
|
-
exported:
|
|
716
|
+
exported: {
|
|
717
|
+
type: "Identifier",
|
|
718
|
+
name: "default"
|
|
719
|
+
}
|
|
632
720
|
}]
|
|
633
721
|
});
|
|
634
722
|
return true;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.24.0-beta.
|
|
4
|
+
"version": "0.24.0-beta.2",
|
|
5
5
|
"description": "A Rolldown plugin to generate and bundle dts files.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -62,25 +62,25 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@babel/generator": "8.0.0-rc.
|
|
66
|
-
"@babel/helper-validator-identifier": "8.0.0-rc.
|
|
67
|
-
"@babel/parser": "8.0.0-rc.
|
|
68
|
-
"@babel/types": "8.0.0-rc.3",
|
|
65
|
+
"@babel/generator": "8.0.0-rc.4",
|
|
66
|
+
"@babel/helper-validator-identifier": "8.0.0-rc.4",
|
|
67
|
+
"@babel/parser": "8.0.0-rc.4",
|
|
69
68
|
"ast-kit": "^3.0.0-beta.1",
|
|
70
69
|
"birpc": "^4.0.0",
|
|
71
70
|
"dts-resolver": "^2.1.3",
|
|
72
|
-
"get-tsconfig": "^5.0.0-beta.
|
|
71
|
+
"get-tsconfig": "^5.0.0-beta.5",
|
|
73
72
|
"obug": "^2.1.1",
|
|
74
73
|
"picomatch": "^4.0.4"
|
|
75
74
|
},
|
|
76
75
|
"devDependencies": {
|
|
76
|
+
"@babel/types": "^8.0.0-rc.4",
|
|
77
77
|
"@jridgewell/source-map": "^0.3.11",
|
|
78
|
-
"@sxzz/eslint-config": "^
|
|
78
|
+
"@sxzz/eslint-config": "^8.0.0",
|
|
79
79
|
"@sxzz/prettier-config": "^2.3.1",
|
|
80
80
|
"@sxzz/test-utils": "^0.5.18",
|
|
81
81
|
"@types/node": "^25.6.0",
|
|
82
82
|
"@types/picomatch": "^4.0.3",
|
|
83
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
83
|
+
"@typescript/native-preview": "7.0.0-dev.20260430.1",
|
|
84
84
|
"@volar/typescript": "^2.4.28",
|
|
85
85
|
"@vue/language-core": "^3.2.7",
|
|
86
86
|
"arktype": "^2.2.0",
|
|
@@ -88,20 +88,17 @@
|
|
|
88
88
|
"diff": "^9.0.0",
|
|
89
89
|
"eslint": "^10.2.1",
|
|
90
90
|
"prettier": "^3.8.3",
|
|
91
|
-
"rolldown": "^1.0.0-rc.
|
|
91
|
+
"rolldown": "^1.0.0-rc.18",
|
|
92
92
|
"rolldown-plugin-require-cjs": "^0.4.0",
|
|
93
93
|
"rollup-plugin-dts": "^6.4.1",
|
|
94
94
|
"tinyglobby": "^0.2.16",
|
|
95
|
-
"tsdown": "^0.22.0-beta.
|
|
95
|
+
"tsdown": "^0.22.0-beta.2",
|
|
96
96
|
"tsnapi": "^0.3.2",
|
|
97
97
|
"typescript": "^6.0.3",
|
|
98
98
|
"vitest": "^4.1.5",
|
|
99
99
|
"vue": "^3.5.33",
|
|
100
100
|
"vue-tsc": "^3.2.7",
|
|
101
|
-
"zod": "^4.
|
|
102
|
-
},
|
|
103
|
-
"resolutions": {
|
|
104
|
-
"rolldown": "^1.0.0-rc.17"
|
|
101
|
+
"zod": "^4.4.1"
|
|
105
102
|
},
|
|
106
103
|
"prettier": "@sxzz/prettier-config",
|
|
107
104
|
"scripts": {
|