rolldown-plugin-dts 0.26.0 → 0.27.0
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/{context-_3g_7Eca.d.mts → context-CcXGRVeM.d.mts} +0 -1
- package/dist/{index-DFO9SbW-.d.mts → index-Pfhuikcq.d.mts} +1 -2
- package/dist/index.d.mts +149 -193
- package/dist/index.mjs +212 -312
- package/dist/internal.d.mts +0 -1
- package/dist/{tsc-DBLgyoBn.mjs → tsc-CgJ-ct_1.mjs} +12 -4
- package/dist/tsc-context.d.mts +1 -1
- package/dist/tsc-worker.d.mts +11 -7
- package/dist/tsc-worker.mjs +15 -5
- package/dist/tsc.d.mts +1 -1
- package/dist/tsc.mjs +1 -1
- package/package.json +17 -20
package/dist/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@ import { a as RE_JSON, c as RE_TS, d as filename_js_to_dts, f as filename_to_dts
|
|
|
2
2
|
import { createContext, globalContext, invalidateContextFile } from "./tsc-context.mjs";
|
|
3
3
|
import { createDebug } from "obug";
|
|
4
4
|
import { importerId, include } from "rolldown/filter";
|
|
5
|
-
import {
|
|
6
|
-
import { isIdentifierName } from "
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { b, is } from "yuku-ast";
|
|
6
|
+
import { isIdentifierName } from "yuku-ast/identifier";
|
|
7
|
+
import { nameOf } from "yuku-ast/utils";
|
|
8
|
+
import { print } from "yuku-codegen";
|
|
9
|
+
import { parse, walk } from "yuku-parser";
|
|
9
10
|
import { fork, spawn } from "node:child_process";
|
|
10
11
|
import { existsSync } from "node:fs";
|
|
11
12
|
import { access, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
@@ -97,39 +98,36 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
97
98
|
let file;
|
|
98
99
|
try {
|
|
99
100
|
file = parse(code, {
|
|
100
|
-
|
|
101
|
+
lang: "dts",
|
|
101
102
|
sourceType: "module",
|
|
102
|
-
|
|
103
|
-
createParenthesizedExpressions: true
|
|
103
|
+
attachComments: true
|
|
104
104
|
});
|
|
105
105
|
} catch (error) {
|
|
106
106
|
throw new Error(`Failed to parse ${id}. 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/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
|
|
107
107
|
}
|
|
108
|
-
const { program
|
|
108
|
+
const { program } = file;
|
|
109
109
|
moduleExportsMap.set(id, await collectModuleExports(this, program.body, id));
|
|
110
110
|
const identifierMap = Object.create(null);
|
|
111
111
|
if (!warnedCjsDtsInputs.has(id) && program.body.some(isCjsDtsInputSyntax)) {
|
|
112
112
|
warnedCjsDtsInputs.add(id);
|
|
113
|
-
this.warn(
|
|
114
|
-
}
|
|
115
|
-
if (comments) {
|
|
116
|
-
const directives = collectReferenceDirectives(comments);
|
|
117
|
-
commentsMap.set(id, directives);
|
|
113
|
+
this.warn(`${id} uses CommonJS dts syntax. ${RE_NODE_MODULES.test(id) ? `CommonJS dts modules cannot be bundled by rolldown-plugin-dts. Please mark this module as external in your Rolldown config.` : `rolldown-plugin-dts does not support bundling CommonJS dts input.`}`);
|
|
118
114
|
}
|
|
115
|
+
const directives = collectReferenceDirectives(file.comments);
|
|
116
|
+
if (directives.length) commentsMap.set(id, directives);
|
|
119
117
|
const appendStmts = [];
|
|
120
118
|
const namespaceStmts = /* @__PURE__ */ new Map();
|
|
121
119
|
for (const [i, stmt] of program.body.entries()) {
|
|
122
120
|
const setStmt = (stmt) => program.body[i] = stmt;
|
|
123
121
|
if (rewriteImportExport(stmt, setStmt)) continue;
|
|
124
122
|
const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
|
|
125
|
-
if (sideEffect && stmt.
|
|
123
|
+
if (sideEffect && stmt.type === "TSModuleDeclaration" && is.StringLiteral(stmt.id) && stmt.id.value[0] === ".") this.warn(`\`declare module ${JSON.stringify(stmt.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${id}.`);
|
|
126
124
|
if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
|
|
127
125
|
const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
|
|
128
|
-
const isExportDecl =
|
|
126
|
+
const isExportDecl = is.oneOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && !!stmt.declaration;
|
|
129
127
|
const decl = isExportDecl ? stmt.declaration : stmt;
|
|
130
128
|
const setDecl = isExportDecl ? (decl) => stmt.declaration = decl : setStmt;
|
|
131
|
-
if (decl.type !== "TSDeclareFunction" && !
|
|
132
|
-
if (
|
|
129
|
+
if (decl.type !== "TSDeclareFunction" && !is.Declaration(decl)) continue;
|
|
130
|
+
if (is.oneOf(decl, [
|
|
133
131
|
"TSEnumDeclaration",
|
|
134
132
|
"ClassDeclaration",
|
|
135
133
|
"FunctionDeclaration",
|
|
@@ -142,17 +140,11 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
142
140
|
else if ("id" in decl && decl.id) {
|
|
143
141
|
let binding = decl.id;
|
|
144
142
|
if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
|
|
145
|
-
binding =
|
|
146
|
-
type: "Identifier",
|
|
147
|
-
name: `_${getIdentifierIndex(identifierMap, "")}`
|
|
148
|
-
} : binding;
|
|
143
|
+
if (sideEffect) binding = b.identifier(`_${getIdentifierIndex(identifierMap, "")}`);
|
|
149
144
|
if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
|
|
150
145
|
bindings.push(binding);
|
|
151
146
|
} else {
|
|
152
|
-
const binding =
|
|
153
|
-
type: "Identifier",
|
|
154
|
-
name: "export_default"
|
|
155
|
-
};
|
|
147
|
+
const binding = b.identifier("export_default");
|
|
156
148
|
bindings.push(binding);
|
|
157
149
|
decl.id = binding;
|
|
158
150
|
}
|
|
@@ -160,115 +152,58 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
160
152
|
const childrenSet = /* @__PURE__ */ new Set();
|
|
161
153
|
const deps = await collectDependencies(this, decl, id, namespaceStmts, childrenSet, identifierMap);
|
|
162
154
|
const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
|
|
163
|
-
if (decl !== stmt) decl.
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
};
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
type: "Identifier",
|
|
182
|
-
name
|
|
183
|
-
})),
|
|
184
|
-
body: depsBody,
|
|
185
|
-
async: false,
|
|
186
|
-
expression: true
|
|
187
|
-
};
|
|
188
|
-
const childrenNode = {
|
|
189
|
-
type: "ArrayExpression",
|
|
190
|
-
elements: children.map((node) => ({
|
|
191
|
-
type: "StringLiteral",
|
|
192
|
-
value: "",
|
|
193
|
-
start: node.start,
|
|
194
|
-
end: node.end,
|
|
195
|
-
loc: node.loc
|
|
196
|
-
}))
|
|
197
|
-
};
|
|
198
|
-
const sideEffectNode = sideEffect && {
|
|
199
|
-
type: "CallExpression",
|
|
200
|
-
callee: {
|
|
201
|
-
type: "Identifier",
|
|
202
|
-
name: "sideEffect"
|
|
203
|
-
},
|
|
204
|
-
arguments: [bindings[0]]
|
|
205
|
-
};
|
|
155
|
+
if (decl !== stmt) decl.comments = stmt.comments;
|
|
156
|
+
const declarationId = registerDeclaration({
|
|
157
|
+
decl,
|
|
158
|
+
deps,
|
|
159
|
+
bindings,
|
|
160
|
+
params,
|
|
161
|
+
children
|
|
162
|
+
});
|
|
163
|
+
const declarationIdNode = b.numericLiteral(declarationId);
|
|
164
|
+
const depsBody = b.arrayExpression(deps);
|
|
165
|
+
const depsNode = b.arrowFunctionExpression(params.map(({ name }) => b.identifier(name)), depsBody);
|
|
166
|
+
const childrenNode = b.arrayExpression(children.map((node) => {
|
|
167
|
+
const placeholder = b.stringLiteral("");
|
|
168
|
+
placeholder.start = node.start;
|
|
169
|
+
placeholder.end = node.end;
|
|
170
|
+
return placeholder;
|
|
171
|
+
}));
|
|
172
|
+
const sideEffectNode = sideEffect && b.callExpression(b.identifier("sideEffect"), [bindings[0]]);
|
|
206
173
|
const runtimeArrayNode = runtimeBindingArrayExpression([
|
|
207
174
|
declarationIdNode,
|
|
208
175
|
depsNode,
|
|
209
176
|
childrenNode,
|
|
210
177
|
...sideEffectNode ? [sideEffectNode] : []
|
|
211
178
|
]);
|
|
212
|
-
const runtimeAssignment = {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
typeAnnotation: null
|
|
220
|
-
},
|
|
221
|
-
init: runtimeArrayNode
|
|
222
|
-
}, ...bindings.slice(1).map((binding) => ({
|
|
223
|
-
type: "VariableDeclarator",
|
|
224
|
-
id: {
|
|
225
|
-
...binding,
|
|
226
|
-
typeAnnotation: null
|
|
227
|
-
}
|
|
228
|
-
}))]
|
|
229
|
-
};
|
|
179
|
+
const runtimeAssignment = b.variableDeclaration("var", [b.variableDeclarator({
|
|
180
|
+
...bindings[0],
|
|
181
|
+
typeAnnotation: null
|
|
182
|
+
}, runtimeArrayNode), ...bindings.slice(1).map((binding) => b.variableDeclarator({
|
|
183
|
+
...binding,
|
|
184
|
+
typeAnnotation: null
|
|
185
|
+
}))]);
|
|
230
186
|
if (isDefaultExport) {
|
|
231
|
-
appendStmts.push(
|
|
232
|
-
type: "ExportNamedDeclaration",
|
|
233
|
-
declaration: null,
|
|
234
|
-
specifiers: [{
|
|
235
|
-
type: "ExportSpecifier",
|
|
236
|
-
local: bindings[0],
|
|
237
|
-
exported: {
|
|
238
|
-
type: "Identifier",
|
|
239
|
-
name: "default"
|
|
240
|
-
}
|
|
241
|
-
}],
|
|
242
|
-
source: null,
|
|
243
|
-
attributes: null
|
|
244
|
-
});
|
|
187
|
+
appendStmts.push(b.exportNamedDeclaration(null, [b.exportSpecifier(bindings[0], b.identifier("default"))]));
|
|
245
188
|
setStmt(runtimeAssignment);
|
|
246
189
|
} else setDecl(runtimeAssignment);
|
|
247
190
|
}
|
|
248
|
-
if (sideEffects) appendStmts.push(
|
|
249
|
-
type: "ExpressionStatement",
|
|
250
|
-
expression: {
|
|
251
|
-
type: "CallExpression",
|
|
252
|
-
callee: {
|
|
253
|
-
type: "Identifier",
|
|
254
|
-
name: "sideEffect"
|
|
255
|
-
},
|
|
256
|
-
arguments: []
|
|
257
|
-
}
|
|
258
|
-
});
|
|
191
|
+
if (sideEffects) appendStmts.push(b.expressionStatement(b.callExpression(b.identifier("sideEffect"), [])));
|
|
259
192
|
program.body = [
|
|
260
193
|
...Array.from(namespaceStmts.values()).map(({ stmt }) => stmt),
|
|
261
194
|
...program.body,
|
|
262
195
|
...appendStmts
|
|
263
196
|
];
|
|
264
|
-
const result =
|
|
197
|
+
const result = print(program, {
|
|
265
198
|
comments: false,
|
|
266
|
-
sourceMaps:
|
|
267
|
-
|
|
199
|
+
...sourcemap && { sourceMaps: {
|
|
200
|
+
source: code,
|
|
201
|
+
sourceFileName: id
|
|
202
|
+
} }
|
|
268
203
|
});
|
|
269
204
|
return {
|
|
270
205
|
code: result.code,
|
|
271
|
-
map: result.map
|
|
206
|
+
map: result.map ?? null
|
|
272
207
|
};
|
|
273
208
|
}
|
|
274
209
|
function renderChunk(code, chunk) {
|
|
@@ -276,7 +211,11 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
276
211
|
const exportInfo = collectChunkExportInfo(chunk, moduleExportsMap);
|
|
277
212
|
let file;
|
|
278
213
|
try {
|
|
279
|
-
file = parse(code, {
|
|
214
|
+
file = parse(code, {
|
|
215
|
+
lang: "ts",
|
|
216
|
+
sourceType: "module",
|
|
217
|
+
attachComments: true
|
|
218
|
+
});
|
|
280
219
|
} catch (error) {
|
|
281
220
|
throw new Error(`Failed to parse generated code for chunk ${chunk.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
|
|
282
221
|
}
|
|
@@ -293,9 +232,9 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
293
232
|
const [declarationIdNode, depsFn, children] = node.declarations[0].init.elements;
|
|
294
233
|
const declarationId = declarationIdNode.value;
|
|
295
234
|
const declaration = getDeclaration(declarationId);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
235
|
+
if (sourcemap) walk(declaration.decl, { enter(node) {
|
|
236
|
+
node.start = void 0;
|
|
237
|
+
node.end = void 0;
|
|
299
238
|
} });
|
|
300
239
|
for (const [i, decl] of node.declarations.entries()) {
|
|
301
240
|
const transformedBinding = {
|
|
@@ -304,7 +243,10 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
304
243
|
};
|
|
305
244
|
overwriteNode(declaration.bindings[i], transformedBinding);
|
|
306
245
|
}
|
|
307
|
-
for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], {
|
|
246
|
+
if (sourcemap) for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], {
|
|
247
|
+
start: child.start,
|
|
248
|
+
end: child.end
|
|
249
|
+
});
|
|
308
250
|
const transformedParams = depsFn.params;
|
|
309
251
|
for (const [i, transformedParam] of transformedParams.entries()) {
|
|
310
252
|
const transformedName = transformedParam.name;
|
|
@@ -313,20 +255,21 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
313
255
|
const transformedDeps = depsFn.body.elements;
|
|
314
256
|
for (const [i, originalDep] of declaration.deps.entries()) {
|
|
315
257
|
let transformedDep = transformedDeps[i];
|
|
316
|
-
if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void")
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
};
|
|
323
|
-
else if (isInfer(transformedDep)) transformedDep.name = "__Infer";
|
|
258
|
+
if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void") {
|
|
259
|
+
const undefinedDep = b.identifier("undefined");
|
|
260
|
+
undefinedDep.start = transformedDep.start;
|
|
261
|
+
undefinedDep.end = transformedDep.end;
|
|
262
|
+
transformedDep = undefinedDep;
|
|
263
|
+
} else if (isInfer(transformedDep)) transformedDep.name = "__Infer";
|
|
324
264
|
if (originalDep.replace) originalDep.replace(transformedDep);
|
|
325
265
|
else Object.assign(originalDep, transformedDep);
|
|
326
266
|
}
|
|
327
267
|
return inheritNodeComments(node, declaration.decl);
|
|
328
268
|
}).filter((node) => !!node);
|
|
329
|
-
if (program.body.length === 0) return
|
|
269
|
+
if (program.body.length === 0) return {
|
|
270
|
+
code: "export { };",
|
|
271
|
+
map: null
|
|
272
|
+
};
|
|
330
273
|
const comments = /* @__PURE__ */ new Set();
|
|
331
274
|
const commentsValue = /* @__PURE__ */ new Set();
|
|
332
275
|
for (const id of chunk.moduleIds) {
|
|
@@ -342,16 +285,24 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
342
285
|
}
|
|
343
286
|
}
|
|
344
287
|
if (comments.size) {
|
|
345
|
-
program.body[0].
|
|
346
|
-
program.body[0].
|
|
288
|
+
program.body[0].comments ||= [];
|
|
289
|
+
program.body[0].comments.unshift(...Array.from(comments, (c) => ({
|
|
290
|
+
type: c.type,
|
|
291
|
+
value: c.value,
|
|
292
|
+
position: "before",
|
|
293
|
+
sameLine: false
|
|
294
|
+
})));
|
|
347
295
|
}
|
|
348
|
-
const result =
|
|
349
|
-
|
|
350
|
-
|
|
296
|
+
const result = print(program, {
|
|
297
|
+
comments: true,
|
|
298
|
+
...sourcemap && { sourceMaps: {
|
|
299
|
+
source: code,
|
|
300
|
+
sourceFileName: chunk.fileName
|
|
301
|
+
} }
|
|
351
302
|
});
|
|
352
303
|
return {
|
|
353
304
|
code: result.code,
|
|
354
|
-
map: result.map
|
|
305
|
+
map: result.map ?? null
|
|
355
306
|
};
|
|
356
307
|
}
|
|
357
308
|
function registerDeclaration(info) {
|
|
@@ -400,7 +351,7 @@ function collectPatternNames(node) {
|
|
|
400
351
|
return [];
|
|
401
352
|
}
|
|
402
353
|
function isTypeOnlyExport(node, specifier) {
|
|
403
|
-
return node.exportKind === "type" ||
|
|
354
|
+
return node.exportKind === "type" || specifier.exportKind === "type";
|
|
404
355
|
}
|
|
405
356
|
async function collectExportInfo(context, node, id, info) {
|
|
406
357
|
if (node.type === "ExportNamedDeclaration") {
|
|
@@ -411,20 +362,15 @@ async function collectExportInfo(context, node, id, info) {
|
|
|
411
362
|
const source = await resolveExportSource(context, node.source, id);
|
|
412
363
|
for (const specifier of node.specifiers) {
|
|
413
364
|
const typeOnly = isTypeOnlyExport(node, specifier);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
else info.exports.set(exported, typeOnly || info.typeOnlyLocals.has(local));
|
|
424
|
-
} else {
|
|
425
|
-
const exported = resolveString(specifier.exported);
|
|
426
|
-
info.exports.set(exported, typeOnly);
|
|
427
|
-
}
|
|
365
|
+
const exported = nameOf(specifier.exported);
|
|
366
|
+
const local = nameOf(specifier.local);
|
|
367
|
+
if (source) info.reExports.push({
|
|
368
|
+
source,
|
|
369
|
+
local,
|
|
370
|
+
exported,
|
|
371
|
+
typeOnly
|
|
372
|
+
});
|
|
373
|
+
else info.exports.set(exported, typeOnly || info.typeOnlyLocals.has(local));
|
|
428
374
|
}
|
|
429
375
|
return;
|
|
430
376
|
}
|
|
@@ -432,11 +378,17 @@ async function collectExportInfo(context, node, id, info) {
|
|
|
432
378
|
info.exports.set("default", false);
|
|
433
379
|
return;
|
|
434
380
|
}
|
|
435
|
-
if (node.type === "ExportAllDeclaration")
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
381
|
+
if (node.type === "ExportAllDeclaration") {
|
|
382
|
+
if (node.exported) {
|
|
383
|
+
info.exports.set(nameOf(node.exported), node.exportKind === "type");
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
info.exportAlls.push({
|
|
387
|
+
source: await resolveExportSource(context, node.source, id),
|
|
388
|
+
rawSource: node.source.value,
|
|
389
|
+
typeOnly: node.exportKind === "type"
|
|
390
|
+
});
|
|
391
|
+
}
|
|
440
392
|
}
|
|
441
393
|
async function resolveExportSource(context, source, importer) {
|
|
442
394
|
if (!source) return;
|
|
@@ -508,11 +460,8 @@ function setExportTypeOnly(exports, name, typeOnly) {
|
|
|
508
460
|
*/
|
|
509
461
|
function collectParams(node) {
|
|
510
462
|
const typeParams = [];
|
|
511
|
-
|
|
512
|
-
if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) =>
|
|
513
|
-
type: "Identifier",
|
|
514
|
-
name
|
|
515
|
-
} : name));
|
|
463
|
+
walk(node, { leave(node) {
|
|
464
|
+
if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => name));
|
|
516
465
|
} });
|
|
517
466
|
const paramMap = /* @__PURE__ */ new Map();
|
|
518
467
|
for (const typeParam of typeParams) {
|
|
@@ -530,20 +479,28 @@ async function collectDependencies(context, node, importer, namespaceStmts, chil
|
|
|
530
479
|
const deps = /* @__PURE__ */ new Set();
|
|
531
480
|
const seen = /* @__PURE__ */ new Set();
|
|
532
481
|
const preserveImportTypeCache = /* @__PURE__ */ new Map();
|
|
482
|
+
const importSources = /* @__PURE__ */ new Set();
|
|
483
|
+
walk(node, { TSImportType(node) {
|
|
484
|
+
importSources.add(node.source.value);
|
|
485
|
+
} });
|
|
486
|
+
if (importSources.size) await Promise.all(Array.from(importSources, async (source) => {
|
|
487
|
+
const resolved = await context.resolve(source, importer);
|
|
488
|
+
preserveImportTypeCache.set(source, !resolved || !!resolved.external);
|
|
489
|
+
}));
|
|
533
490
|
const inferredStack = [];
|
|
534
491
|
let currentInferred = /* @__PURE__ */ new Set();
|
|
535
492
|
function isInferred(node) {
|
|
536
493
|
return node.type === "Identifier" && currentInferred.has(node.name);
|
|
537
494
|
}
|
|
538
|
-
|
|
495
|
+
walk(node, {
|
|
539
496
|
enter(node) {
|
|
540
497
|
if (node.type === "TSConditionalType") {
|
|
541
498
|
const inferred = collectInferredNames(node.extendsType);
|
|
542
499
|
inferredStack.push(inferred);
|
|
543
500
|
}
|
|
544
|
-
return Promise.resolve();
|
|
545
501
|
},
|
|
546
|
-
|
|
502
|
+
leave(node, path) {
|
|
503
|
+
const { parent } = path;
|
|
547
504
|
if (node.type === "TSConditionalType") inferredStack.pop();
|
|
548
505
|
else if (parent?.type === "TSConditionalType") {
|
|
549
506
|
const trueBranch = parent.trueType === node;
|
|
@@ -554,16 +511,14 @@ async function collectDependencies(context, node, importer, namespaceStmts, chil
|
|
|
554
511
|
} else if (node.type === "TSInterfaceDeclaration" && node.extends) for (const heritage of node.extends || []) addDependency(heritage.expression);
|
|
555
512
|
else if (node.type === "ClassDeclaration") {
|
|
556
513
|
if (node.superClass) addDependency(node.superClass);
|
|
557
|
-
if (node.implements) for (const implement of node.implements)
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
"
|
|
563
|
-
"
|
|
564
|
-
"ClassProperty",
|
|
514
|
+
if (node.implements) for (const implement of node.implements) addDependency(implement.expression);
|
|
515
|
+
} else if (is.oneOf(node, [
|
|
516
|
+
"Property",
|
|
517
|
+
"PropertyDefinition",
|
|
518
|
+
"TSAbstractPropertyDefinition",
|
|
519
|
+
"MethodDefinition",
|
|
520
|
+
"TSAbstractMethodDefinition",
|
|
565
521
|
"TSPropertySignature",
|
|
566
|
-
"TSDeclareMethod",
|
|
567
522
|
"TSMethodSignature"
|
|
568
523
|
])) {
|
|
569
524
|
if (node.computed && isReferenceId(node.key)) addDependency(node.key);
|
|
@@ -580,7 +535,7 @@ async function collectDependencies(context, node, importer, namespaceStmts, chil
|
|
|
580
535
|
case "TSImportType": {
|
|
581
536
|
seen.add(node);
|
|
582
537
|
const { source, qualifier } = node;
|
|
583
|
-
const dep =
|
|
538
|
+
const dep = importNamespace(node, qualifier, source, namespaceStmts, identifierMap, preserveImportTypeCache);
|
|
584
539
|
if (dep) addDependency(dep);
|
|
585
540
|
break;
|
|
586
541
|
}
|
|
@@ -594,49 +549,25 @@ async function collectDependencies(context, node, importer, namespaceStmts, chil
|
|
|
594
549
|
deps.add(node);
|
|
595
550
|
}
|
|
596
551
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
if (preserve === void 0) {
|
|
600
|
-
const resolved = await context.resolve(source.value, importer);
|
|
601
|
-
preserve = !resolved || !!resolved.external;
|
|
602
|
-
preserveCache.set(source.value, preserve);
|
|
603
|
-
}
|
|
604
|
-
if (preserve) return;
|
|
552
|
+
function importNamespace(node, imported, source, namespaceStmts, identifierMap, preserveCache) {
|
|
553
|
+
if (preserveCache.get(source.value) ?? true) return;
|
|
605
554
|
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
name: `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`
|
|
609
|
-
};
|
|
555
|
+
const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
|
|
556
|
+
let local = b.identifier(localName);
|
|
610
557
|
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
611
558
|
else namespaceStmts.set(source.value, {
|
|
612
|
-
stmt:
|
|
613
|
-
type: "ImportDeclaration",
|
|
614
|
-
specifiers: [{
|
|
615
|
-
type: "ImportNamespaceSpecifier",
|
|
616
|
-
local
|
|
617
|
-
}],
|
|
618
|
-
source,
|
|
619
|
-
attributes: null
|
|
620
|
-
},
|
|
559
|
+
stmt: b.importDeclaration([b.importNamespaceSpecifier(local)], source),
|
|
621
560
|
local
|
|
622
561
|
});
|
|
623
562
|
if (imported) {
|
|
624
563
|
const importedLeft = getIdFromTSEntityName(imported);
|
|
625
564
|
if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
|
|
626
|
-
overwriteNode(importedLeft, {
|
|
627
|
-
type: "TSQualifiedName",
|
|
628
|
-
left: local,
|
|
629
|
-
right: { ...importedLeft }
|
|
630
|
-
});
|
|
565
|
+
overwriteNode(importedLeft, b.tsQualifiedName(local, { ...importedLeft }));
|
|
631
566
|
local = imported;
|
|
632
567
|
}
|
|
633
568
|
let replacement = node;
|
|
634
569
|
if (node.typeArguments) {
|
|
635
|
-
overwriteNode(node,
|
|
636
|
-
type: "TSTypeReference",
|
|
637
|
-
typeName: local,
|
|
638
|
-
typeArguments: node.typeArguments
|
|
639
|
-
});
|
|
570
|
+
overwriteNode(node, b.tsTypeReference(local, node.typeArguments));
|
|
640
571
|
replacement = local;
|
|
641
572
|
} else overwriteNode(node, local);
|
|
642
573
|
return {
|
|
@@ -648,12 +579,12 @@ async function importNamespace(context, importer, node, imported, source, namesp
|
|
|
648
579
|
}
|
|
649
580
|
function isChildSymbol(node, parent) {
|
|
650
581
|
if (node.type === "Identifier") return true;
|
|
651
|
-
if (
|
|
582
|
+
if (is.oneOf(parent, ["TSPropertySignature", "TSMethodSignature"]) && parent.key === node) return true;
|
|
652
583
|
return false;
|
|
653
584
|
}
|
|
654
585
|
function collectInferredNames(node) {
|
|
655
586
|
const inferred = [];
|
|
656
|
-
|
|
587
|
+
walk(node, { enter(node) {
|
|
657
588
|
if (node.type === "TSInferType" && node.typeParameter) inferred.push(node.typeParameter.name.name);
|
|
658
589
|
} });
|
|
659
590
|
return inferred;
|
|
@@ -662,6 +593,10 @@ const REFERENCE_RE = /\/\s*<reference\s+(?:path|types)=/;
|
|
|
662
593
|
function collectReferenceDirectives(comment, negative = false) {
|
|
663
594
|
return comment.filter((c) => REFERENCE_RE.test(c.value) !== negative);
|
|
664
595
|
}
|
|
596
|
+
const SOURCE_MAP_PRAGMA_RE = /^#\s*source(?:Mapping)?URL=/;
|
|
597
|
+
function isSourceMapPragma(comment) {
|
|
598
|
+
return SOURCE_MAP_PRAGMA_RE.test(comment.value);
|
|
599
|
+
}
|
|
665
600
|
function isCjsDtsInputSyntax(node) {
|
|
666
601
|
return node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration" && node.moduleReference.type === "TSExternalModuleReference";
|
|
667
602
|
}
|
|
@@ -682,19 +617,16 @@ function isRuntimeBindingArrayExpression(node) {
|
|
|
682
617
|
*/
|
|
683
618
|
function isRuntimeBindingArrayElements(elements) {
|
|
684
619
|
const [declarationId, deps, children, effect] = elements;
|
|
685
|
-
return declarationId
|
|
620
|
+
return is.NumericLiteral(declarationId) && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
|
|
686
621
|
}
|
|
687
622
|
function runtimeBindingArrayExpression(elements) {
|
|
688
|
-
return
|
|
689
|
-
type: "ArrayExpression",
|
|
690
|
-
elements
|
|
691
|
-
};
|
|
623
|
+
return b.arrayExpression([...elements]);
|
|
692
624
|
}
|
|
693
625
|
function isThisExpression(node) {
|
|
694
|
-
return
|
|
626
|
+
return is.Identifier(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
|
|
695
627
|
}
|
|
696
628
|
function isInfer(node) {
|
|
697
|
-
return
|
|
629
|
+
return is.Identifier(node, "infer");
|
|
698
630
|
}
|
|
699
631
|
function TSEntityNameToRuntime(node) {
|
|
700
632
|
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
@@ -711,7 +643,7 @@ function getIdFromTSEntityName(node) {
|
|
|
711
643
|
return getIdFromTSEntityName(node.left);
|
|
712
644
|
}
|
|
713
645
|
function isReferenceId(node) {
|
|
714
|
-
return
|
|
646
|
+
return is.oneOf(node, ["Identifier", "MemberExpression"]);
|
|
715
647
|
}
|
|
716
648
|
function isHelperImport(node) {
|
|
717
649
|
return node.type === "ImportDeclaration" && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__exportAll", "__reExport"].includes(spec.local.name));
|
|
@@ -724,7 +656,7 @@ function patchImportExport(node, exportInfo, cjsDefault) {
|
|
|
724
656
|
if (node.type === "ImportDeclaration" && node.specifiers.length) {
|
|
725
657
|
for (const specifier of node.specifiers) if (isInfer(specifier.local)) specifier.local.name = "__Infer";
|
|
726
658
|
}
|
|
727
|
-
if (
|
|
659
|
+
if (is.oneOf(node, [
|
|
728
660
|
"ImportDeclaration",
|
|
729
661
|
"ExportAllDeclaration",
|
|
730
662
|
"ExportNamedDeclaration"
|
|
@@ -732,7 +664,7 @@ function patchImportExport(node, exportInfo, cjsDefault) {
|
|
|
732
664
|
if (node.type === "ExportAllDeclaration" && node.source && exportInfo.typeOnlyExportAllSources.has(node.source.value)) node.exportKind = "type";
|
|
733
665
|
if (node.type === "ExportNamedDeclaration" && exportInfo.typeOnlyNames.size) {
|
|
734
666
|
for (const spec of node.specifiers) {
|
|
735
|
-
const name =
|
|
667
|
+
const name = nameOf(spec.exported);
|
|
736
668
|
if (exportInfo.typeOnlyNames.has(name)) if (spec.type === "ExportSpecifier") spec.exportKind = "type";
|
|
737
669
|
else node.exportKind = "type";
|
|
738
670
|
}
|
|
@@ -742,10 +674,10 @@ function patchImportExport(node, exportInfo, cjsDefault) {
|
|
|
742
674
|
node.source.value = filename_dts_to(node.source.value, "js");
|
|
743
675
|
return node;
|
|
744
676
|
}
|
|
745
|
-
if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" &&
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}
|
|
677
|
+
if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && nameOf(node.specifiers[0].exported) === "default") {
|
|
678
|
+
const defaultExport = node.specifiers[0];
|
|
679
|
+
return b.tsExportAssignment(defaultExport.local);
|
|
680
|
+
}
|
|
749
681
|
}
|
|
750
682
|
}
|
|
751
683
|
function normalizeTypeOnlyExport(node) {
|
|
@@ -764,27 +696,15 @@ function patchTsNamespace(nodes) {
|
|
|
764
696
|
if (!result) continue;
|
|
765
697
|
const [binding, exports] = result;
|
|
766
698
|
if (!exports.properties.length) continue;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
699
|
+
const namespaceExport = b.exportNamedDeclaration(null, exports.properties.filter((property) => property.type === "Property").map((property) => {
|
|
700
|
+
const local = property.value.body;
|
|
701
|
+
const exported = property.key;
|
|
702
|
+
return b.exportSpecifier(local, exported);
|
|
703
|
+
}));
|
|
704
|
+
nodes[i] = b.tsModuleDeclaration(binding, b.tsModuleBlock([namespaceExport]), {
|
|
770
705
|
kind: "namespace",
|
|
771
|
-
declare: true
|
|
772
|
-
|
|
773
|
-
type: "TSModuleBlock",
|
|
774
|
-
body: [{
|
|
775
|
-
type: "ExportNamedDeclaration",
|
|
776
|
-
specifiers: exports.properties.filter((property) => property.type === "ObjectProperty").map((property) => {
|
|
777
|
-
return {
|
|
778
|
-
type: "ExportSpecifier",
|
|
779
|
-
local: property.value.body,
|
|
780
|
-
exported: property.key
|
|
781
|
-
};
|
|
782
|
-
}),
|
|
783
|
-
source: null,
|
|
784
|
-
declaration: null
|
|
785
|
-
}]
|
|
786
|
-
}
|
|
787
|
-
};
|
|
706
|
+
declare: true
|
|
707
|
+
});
|
|
788
708
|
}
|
|
789
709
|
return nodes.filter((node) => !removed.has(node));
|
|
790
710
|
}
|
|
@@ -798,30 +718,10 @@ function getExportAllNamespace(node) {
|
|
|
798
718
|
function patchReExport(nodes) {
|
|
799
719
|
const exportsNames = /* @__PURE__ */ new Map();
|
|
800
720
|
for (const [i, node] of nodes.entries()) if (node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers[0].type === "ImportSpecifier" && node.specifiers[0].local.type === "Identifier" && node.specifiers[0].local.name.endsWith("_exports")) exportsNames.set(node.specifiers[0].local.name, node.specifiers[0].local.name);
|
|
801
|
-
else if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" &&
|
|
721
|
+
else if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && is.Identifier(node.expression.callee, "__reExport")) {
|
|
802
722
|
const args = node.expression.arguments;
|
|
803
723
|
exportsNames.set(args[0].name, args[1].name);
|
|
804
|
-
} else if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].init?.type === "MemberExpression" && node.declarations[0].init.object.type === "Identifier" && exportsNames.has(node.declarations[0].init.object.name)) nodes[i] =
|
|
805
|
-
type: "TSTypeAliasDeclaration",
|
|
806
|
-
id: {
|
|
807
|
-
type: "Identifier",
|
|
808
|
-
name: node.declarations[0].id.name
|
|
809
|
-
},
|
|
810
|
-
typeAnnotation: {
|
|
811
|
-
type: "TSTypeReference",
|
|
812
|
-
typeName: {
|
|
813
|
-
type: "TSQualifiedName",
|
|
814
|
-
left: {
|
|
815
|
-
type: "Identifier",
|
|
816
|
-
name: exportsNames.get(node.declarations[0].init.object.name)
|
|
817
|
-
},
|
|
818
|
-
right: {
|
|
819
|
-
type: "Identifier",
|
|
820
|
-
name: node.declarations[0].init.property.name
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
};
|
|
724
|
+
} else if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].init?.type === "MemberExpression" && node.declarations[0].init.object.type === "Identifier" && exportsNames.has(node.declarations[0].init.object.name)) nodes[i] = b.tsTypeAliasDeclaration(b.identifier(node.declarations[0].id.name), b.tsTypeReference(b.tsQualifiedName(b.identifier(exportsNames.get(node.declarations[0].init.object.name)), b.identifier(node.declarations[0].init.property.name))));
|
|
825
725
|
else if (node.type === "ExportNamedDeclaration" && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && node.specifiers[0].local.type === "Identifier" && exportsNames.has(node.specifiers[0].local.name)) node.specifiers[0].local.name = exportsNames.get(node.specifiers[0].local.name);
|
|
826
726
|
return nodes;
|
|
827
727
|
}
|
|
@@ -836,54 +736,27 @@ function rewriteImportExport(node, set) {
|
|
|
836
736
|
node.exportKind = "value";
|
|
837
737
|
return true;
|
|
838
738
|
} else if (node.type === "TSImportEqualsDeclaration") {
|
|
839
|
-
if (node.moduleReference.type === "TSExternalModuleReference") set(
|
|
840
|
-
type: "ImportDeclaration",
|
|
841
|
-
specifiers: [{
|
|
842
|
-
type: "ImportDefaultSpecifier",
|
|
843
|
-
local: node.id
|
|
844
|
-
}],
|
|
845
|
-
source: node.moduleReference.expression
|
|
846
|
-
});
|
|
739
|
+
if (node.moduleReference.type === "TSExternalModuleReference") set(b.importDeclaration([b.importDefaultSpecifier(node.id)], node.moduleReference.expression));
|
|
847
740
|
return true;
|
|
848
741
|
} else if (node.type === "TSExportAssignment" && node.expression.type === "Identifier") {
|
|
849
|
-
set(
|
|
850
|
-
type: "ExportNamedDeclaration",
|
|
851
|
-
specifiers: [{
|
|
852
|
-
type: "ExportSpecifier",
|
|
853
|
-
local: node.expression,
|
|
854
|
-
exported: {
|
|
855
|
-
type: "Identifier",
|
|
856
|
-
name: "default"
|
|
857
|
-
}
|
|
858
|
-
}]
|
|
859
|
-
});
|
|
742
|
+
set(b.exportNamedDeclaration(null, [b.exportSpecifier(node.expression, b.identifier("default"))]));
|
|
860
743
|
return true;
|
|
861
744
|
} else if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "Identifier") {
|
|
862
|
-
set(
|
|
863
|
-
type: "ExportNamedDeclaration",
|
|
864
|
-
specifiers: [{
|
|
865
|
-
type: "ExportSpecifier",
|
|
866
|
-
local: node.declaration,
|
|
867
|
-
exported: {
|
|
868
|
-
type: "Identifier",
|
|
869
|
-
name: "default"
|
|
870
|
-
}
|
|
871
|
-
}]
|
|
872
|
-
});
|
|
745
|
+
set(b.exportNamedDeclaration(null, [b.exportSpecifier(node.declaration, b.identifier("default"))]));
|
|
873
746
|
return true;
|
|
874
747
|
}
|
|
875
748
|
return false;
|
|
876
749
|
}
|
|
877
750
|
function overwriteNode(node, newNode) {
|
|
878
|
-
for (const key of Object.keys(node))
|
|
751
|
+
for (const key of Object.keys(node)) Reflect.deleteProperty(node, key);
|
|
879
752
|
Object.assign(node, newNode);
|
|
880
753
|
return node;
|
|
881
754
|
}
|
|
882
755
|
function inheritNodeComments(oldNode, newNode) {
|
|
883
|
-
newNode.
|
|
884
|
-
const
|
|
885
|
-
if (
|
|
886
|
-
newNode.
|
|
756
|
+
newNode.comments ||= [];
|
|
757
|
+
const pragmas = oldNode.comments?.filter((comment) => comment.position === "before" && comment.value.startsWith("#") && !isSourceMapPragma(comment));
|
|
758
|
+
if (pragmas) newNode.comments.unshift(...pragmas);
|
|
759
|
+
newNode.comments = newNode.comments.filter((comment) => !REFERENCE_RE.test(comment.value) && !isSourceMapPragma(comment));
|
|
887
760
|
return newNode;
|
|
888
761
|
}
|
|
889
762
|
function getIdentifierIndex(identifierMap, name) {
|
|
@@ -963,8 +836,7 @@ function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental
|
|
|
963
836
|
* ])
|
|
964
837
|
*/
|
|
965
838
|
const inputAliasMap = /* @__PURE__ */ new Map();
|
|
966
|
-
let
|
|
967
|
-
let rpc;
|
|
839
|
+
let tscWorker;
|
|
968
840
|
let tscModule;
|
|
969
841
|
let tscContext;
|
|
970
842
|
let tsgoContext;
|
|
@@ -973,13 +845,8 @@ function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental
|
|
|
973
845
|
name: "rolldown-plugin-dts:generate",
|
|
974
846
|
async buildStart(options) {
|
|
975
847
|
if (tsgo) tsgoContext = await runTsgo(rootDir, tsconfig, sourcemap, tsgo.path);
|
|
976
|
-
else if (!oxc) if (parallel)
|
|
977
|
-
|
|
978
|
-
rpc = (await import("birpc")).createBirpc({}, {
|
|
979
|
-
post: (data) => childProcess.send(data),
|
|
980
|
-
on: (fn) => childProcess.on("message", fn)
|
|
981
|
-
});
|
|
982
|
-
} else {
|
|
848
|
+
else if (!oxc) if (parallel) tscWorker = createTscWorker();
|
|
849
|
+
else {
|
|
983
850
|
tscModule = await import("./tsc.mjs");
|
|
984
851
|
if (newContext) tscContext = createContext();
|
|
985
852
|
}
|
|
@@ -1116,7 +983,7 @@ function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental
|
|
|
1116
983
|
context: tscContext
|
|
1117
984
|
};
|
|
1118
985
|
let result;
|
|
1119
|
-
if (parallel) result = await
|
|
986
|
+
if (parallel) result = await tscWorker.emit(options);
|
|
1120
987
|
else result = tscModule.tscEmit(options);
|
|
1121
988
|
if (result.error) return this.error(result.error);
|
|
1122
989
|
dtsCode = result.code;
|
|
@@ -1150,7 +1017,8 @@ export { __json_default_export as default }`;
|
|
|
1150
1017
|
for (const fileName of Object.keys(bundle)) if (bundle[fileName].type === "chunk" && !RE_DTS.test(fileName) && !RE_DTS_MAP.test(fileName)) delete bundle[fileName];
|
|
1151
1018
|
} : void 0,
|
|
1152
1019
|
async buildEnd() {
|
|
1153
|
-
|
|
1020
|
+
tscWorker?.kill();
|
|
1021
|
+
tscWorker = void 0;
|
|
1154
1022
|
await tsgoContext?.dispose();
|
|
1155
1023
|
tsgoContext = void 0;
|
|
1156
1024
|
if (newContext) tscContext = void 0;
|
|
@@ -1160,12 +1028,44 @@ export { __json_default_export as default }`;
|
|
|
1160
1028
|
}
|
|
1161
1029
|
};
|
|
1162
1030
|
}
|
|
1031
|
+
function createTscWorker() {
|
|
1032
|
+
const childProcess = fork(new URL(WORKER_URL, import.meta.url), {
|
|
1033
|
+
stdio: "inherit",
|
|
1034
|
+
serialization: "advanced"
|
|
1035
|
+
});
|
|
1036
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1037
|
+
let nextId = 0;
|
|
1038
|
+
childProcess.on("message", (response) => {
|
|
1039
|
+
const handler = pending.get(response.id);
|
|
1040
|
+
if (!handler) return;
|
|
1041
|
+
pending.delete(response.id);
|
|
1042
|
+
if (response.error) handler.reject(response.error);
|
|
1043
|
+
else handler.resolve(response.result);
|
|
1044
|
+
});
|
|
1045
|
+
childProcess.on("exit", (code) => {
|
|
1046
|
+
for (const handler of pending.values()) handler.reject(/* @__PURE__ */ new Error(`tsc worker exited with code ${code}`));
|
|
1047
|
+
pending.clear();
|
|
1048
|
+
});
|
|
1049
|
+
return {
|
|
1050
|
+
emit: (options) => new Promise((resolve, reject) => {
|
|
1051
|
+
const id = nextId++;
|
|
1052
|
+
pending.set(id, {
|
|
1053
|
+
resolve,
|
|
1054
|
+
reject
|
|
1055
|
+
});
|
|
1056
|
+
childProcess.send({
|
|
1057
|
+
id,
|
|
1058
|
+
options
|
|
1059
|
+
});
|
|
1060
|
+
}),
|
|
1061
|
+
kill: () => childProcess.kill()
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1163
1064
|
function collectJsonExportMap(code) {
|
|
1164
1065
|
const exportMap = /* @__PURE__ */ new Map();
|
|
1165
1066
|
const { program } = parse(code, {
|
|
1166
1067
|
sourceType: "module",
|
|
1167
|
-
|
|
1168
|
-
errorRecovery: true
|
|
1068
|
+
lang: "dts"
|
|
1169
1069
|
});
|
|
1170
1070
|
for (const decl of program.body) if (decl.type === "ExportNamedDeclaration") {
|
|
1171
1071
|
if (decl.declaration) {
|
|
@@ -1183,11 +1083,11 @@ function collectJsonExports(code) {
|
|
|
1183
1083
|
const exports = [];
|
|
1184
1084
|
const { program } = parse(code, {
|
|
1185
1085
|
sourceType: "module",
|
|
1186
|
-
|
|
1086
|
+
lang: "dts"
|
|
1187
1087
|
});
|
|
1188
1088
|
const members = program.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;
|
|
1189
1089
|
for (const member of members) if (member.key.type === "Identifier") exports.push(member.key.name);
|
|
1190
|
-
else if (member.key
|
|
1090
|
+
else if (is.StringLiteral(member.key)) exports.push(member.key.value);
|
|
1191
1091
|
return exports;
|
|
1192
1092
|
}
|
|
1193
1093
|
//#endregion
|