rolldown-plugin-dts 0.12.2 → 0.12.3
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.js +27 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -297,7 +297,6 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
297
297
|
const isDecl = isTypeOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && stmt.declaration;
|
|
298
298
|
const decl = isDecl ? stmt.declaration : stmt;
|
|
299
299
|
const setDecl = isDecl ? (node) => stmt.declaration = node : setStmt;
|
|
300
|
-
if (decl.type === "VariableDeclaration" && decl.declarations.length !== 1) throw new Error("Only one declaration is supported");
|
|
301
300
|
if (decl.type !== "TSDeclareFunction" && !isDeclarationType(decl)) continue;
|
|
302
301
|
if (isTypeOf(decl, [
|
|
303
302
|
"TSEnumDeclaration",
|
|
@@ -307,12 +306,17 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
307
306
|
"TSModuleDeclaration",
|
|
308
307
|
"VariableDeclaration"
|
|
309
308
|
])) decl.declare = true;
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
309
|
+
const bindings = [];
|
|
310
|
+
if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl$1) => decl$1.id));
|
|
311
|
+
else if ("id" in decl && decl.id) {
|
|
312
|
+
let binding = decl.id;
|
|
313
|
+
binding = sideEffect ? t.identifier(`_${identifierIdx++}`) : binding;
|
|
314
|
+
bindings.push(binding);
|
|
315
|
+
} else {
|
|
316
|
+
const binding = t.identifier("export_default");
|
|
317
|
+
bindings.push(binding);
|
|
313
318
|
decl.id = binding;
|
|
314
319
|
}
|
|
315
|
-
binding = sideEffect ? t.identifier(`_${identifierIdx++}`) : binding;
|
|
316
320
|
const deps = collectDependencies(decl, namespaceStmts);
|
|
317
321
|
const elements = [
|
|
318
322
|
t.numericLiteral(0),
|
|
@@ -328,7 +332,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
328
332
|
const symbolId = registerSymbol({
|
|
329
333
|
decl,
|
|
330
334
|
deps,
|
|
331
|
-
|
|
335
|
+
bindings
|
|
332
336
|
});
|
|
333
337
|
elements[0] = t.numericLiteral(symbolId);
|
|
334
338
|
const runtimeAssignment = {
|
|
@@ -337,14 +341,20 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
337
341
|
declarations: [{
|
|
338
342
|
type: "VariableDeclarator",
|
|
339
343
|
id: {
|
|
340
|
-
...
|
|
344
|
+
...bindings[0],
|
|
341
345
|
typeAnnotation: null
|
|
342
346
|
},
|
|
343
347
|
init: runtime
|
|
344
|
-
}
|
|
348
|
+
}, ...bindings.slice(1).map((binding) => ({
|
|
349
|
+
type: "VariableDeclarator",
|
|
350
|
+
id: {
|
|
351
|
+
...binding,
|
|
352
|
+
typeAnnotation: null
|
|
353
|
+
}
|
|
354
|
+
}))]
|
|
345
355
|
};
|
|
346
356
|
if (isDefaultExport) {
|
|
347
|
-
appendStmts.push(t.exportNamedDeclaration(null, [t.exportSpecifier(
|
|
357
|
+
appendStmts.push(t.exportNamedDeclaration(null, [t.exportSpecifier(bindings[0], t.identifier("default"))]));
|
|
348
358
|
setStmt(runtimeAssignment);
|
|
349
359
|
} else setDecl(runtimeAssignment);
|
|
350
360
|
}
|
|
@@ -367,18 +377,20 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
|
|
|
367
377
|
program.body = patchTsNamespace(program.body);
|
|
368
378
|
program.body = program.body.map((node) => {
|
|
369
379
|
if (patchImportSource(node)) return node;
|
|
370
|
-
if (node.type !== "VariableDeclaration"
|
|
380
|
+
if (node.type !== "VariableDeclaration") return node;
|
|
371
381
|
const [decl] = node.declarations;
|
|
372
382
|
if (decl.init?.type !== "ArrayExpression" || !decl.init.elements[0]) return null;
|
|
373
383
|
const [symbolIdNode, ...depsFns] = decl.init.elements;
|
|
374
384
|
if (symbolIdNode?.type !== "NumericLiteral") return null;
|
|
375
385
|
const symbolId = symbolIdNode.value;
|
|
376
386
|
const original = getSymbol(symbolId);
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
387
|
+
for (const [i, decl$1] of node.declarations.entries()) {
|
|
388
|
+
const transformedBinding = {
|
|
389
|
+
...decl$1.id,
|
|
390
|
+
typeAnnotation: original.bindings[i].typeAnnotation
|
|
391
|
+
};
|
|
392
|
+
overwriteNode(original.bindings[i], transformedBinding);
|
|
393
|
+
}
|
|
382
394
|
const transformedDeps = depsFns.filter((node$1) => node$1?.type === "ArrowFunctionExpression").map((node$1) => node$1.body);
|
|
383
395
|
if (original.deps.length) for (let i = 0; i < original.deps.length; i++) {
|
|
384
396
|
const originalDep = original.deps[i];
|