@voidzero-dev/vite-plus-core 0.2.4 → 0.2.6
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/LICENSE +36 -120
- package/dist/rolldown/cli.d.mts +1 -1
- package/dist/rolldown/cli.mjs +11 -8
- package/dist/rolldown/config.d.mts +22 -10
- package/dist/rolldown/config.mjs +2 -2
- package/dist/rolldown/experimental-index.d.mts +164 -155
- package/dist/rolldown/experimental-index.mjs +23 -14
- package/dist/rolldown/experimental-runtime-types.d.ts +111 -41
- package/dist/rolldown/filter-index.d.mts +6 -5
- package/dist/rolldown/get-log-filter.d.mts +2 -2
- package/dist/rolldown/index.d.mts +4 -4
- package/dist/rolldown/index.mjs +10 -4
- package/dist/rolldown/parallel-plugin-worker.d.mts +1 -1
- package/dist/rolldown/parallel-plugin-worker.mjs +2 -2
- package/dist/rolldown/parallel-plugin.d.mts +3 -4
- package/dist/rolldown/parse-ast-index.d.mts +19 -20
- package/dist/rolldown/parse-ast-index.mjs +2 -2
- package/dist/rolldown/plugins-index.d.mts +27 -28
- package/dist/rolldown/plugins-index.mjs +2 -2
- package/dist/rolldown/shared/{binding-B1q9aYT-.d.mts → binding-Dbbi0RbO.d.mts} +49 -25
- package/dist/rolldown/shared/{binding-BmkJW3Wy.mjs → binding-Dby9rwGk.mjs} +26 -26
- package/dist/rolldown/shared/{bindingify-input-options-Cmm60vfj.mjs → bindingify-input-options-DVQ4K-zY.mjs} +11 -13
- package/dist/rolldown/shared/{constructors-2i1T9YcF.d.mts → constructors-CSWbNgBZ.d.mts} +9 -10
- package/dist/rolldown/shared/{constructors-CE6zZSUt.mjs → constructors-CuGa75s-.mjs} +1 -1
- package/dist/rolldown/shared/define-config-B-IDOhDz.d.mts +4003 -0
- package/dist/rolldown/shared/dist-DX3cAjHx.mjs +154 -0
- package/dist/rolldown/shared/{error-BlQ0-ek7.mjs → error-DFGNOCle.mjs} +1 -1
- package/dist/rolldown/shared/get-log-filter-AjBknEEO.d.mts +34 -0
- package/dist/rolldown/shared/{load-config-CVVMWSlg.mjs → load-config-R0z2olkB.mjs} +19 -2
- package/dist/rolldown/shared/{logging-BSNejiLS.d.mts → logging-xuHO4mAy.d.mts} +6 -6
- package/dist/rolldown/shared/{logs-aMKUxRpj.mjs → logs-ZGEh6uhb.mjs} +6 -1
- package/dist/rolldown/shared/{normalize-string-or-regex-BYkbbGqQ.mjs → normalize-string-or-regex-SiXbePVH.mjs} +2 -2
- package/dist/rolldown/shared/{parse-Dphnedsw.mjs → parse-D5dkElpf.mjs} +2 -2
- package/dist/rolldown/shared/{prompt-Bgj-uEyc.mjs → prompt-pZFoa1TT.mjs} +59 -17
- package/dist/rolldown/shared/{resolve-tsconfig-CdIAR1Eb.mjs → resolve-tsconfig-2TXRF_zr.mjs} +2 -2
- package/dist/rolldown/shared/{rolldown-Bnp916iM.mjs → rolldown-BnV7isAX.mjs} +1 -1
- package/dist/rolldown/shared/{rolldown-build-Cs2iVJuw.mjs → rolldown-build-BGXNOfvH.mjs} +33 -13
- package/dist/rolldown/shared/transform-Cs2bUDRH.d.mts +148 -0
- package/dist/rolldown/shared/{watch-ECGr-_QS.mjs → watch-DVucf-VG.mjs} +5 -5
- package/dist/rolldown/utils-index.d.mts +29 -30
- package/dist/rolldown/utils-index.mjs +9 -9
- package/dist/tsdown/{build-B_nvJe4A-CvbtVBxy.js → build-oq13wECG-Bymq3jT5.js} +210 -1229
- package/dist/tsdown/debug-BntVTkRq-BGIoAiTa.js +159 -0
- package/dist/tsdown/{detect-B97OSl92-BJPZyIKJ.js → detect-DGhJGEqb-S-tkSzpt.js} +13 -2
- package/dist/tsdown/dist-CxIM8o7n.js +2613 -0
- package/dist/tsdown/dist-DCMiHFrJ.js +1061 -0
- package/dist/tsdown/index-types.d.ts +2106 -1895
- package/dist/tsdown/index.js +7 -4
- package/dist/tsdown/internal-C7ewSPAZ.js +3 -0
- package/dist/tsdown/load-tsc-BKULZsrs-BFmeD6Bu.js +18 -0
- package/dist/tsdown/{main-BlTcyuFi.js → main-BdzlWPt6.js} +214 -9
- package/dist/tsdown/npm_entry_picomatch.cjs +44 -15
- package/dist/tsdown/{resolver-DtsKFXi2-B8Z3WwZh.js → resolver-cwLsPb2o-oj1hqxK6.js} +4 -3
- package/dist/tsdown/run.js +4 -4
- package/dist/tsdown/{src-CISfE_A0.js → src-BV-UJr_R.js} +5 -5
- package/dist/tsdown/target-CNxIDvSz-eoHNdJNs.js +576 -0
- package/dist/tsdown/{tsc-context-CX_GXdyS.js → tsc-context-CA76SkkZ.js} +2 -2
- package/dist/tsdown/{tsc-CdZE7QwS.js → tsc-zcbB6ZVY.js} +58 -117
- package/dist/tsdown/tsdown-css.js +74 -23
- package/dist/tsdown/tsdown-exe.js +129 -876
- package/dist/vite/client/client.mjs +5 -5
- package/dist/vite/node/chunks/build.js +204 -94
- package/dist/vite/node/chunks/dist2.js +1 -1
- package/dist/vite/node/chunks/lib.js +1 -1
- package/dist/vite/node/chunks/moduleRunnerTransport.d.ts +25 -26
- package/dist/vite/node/chunks/node.js +552 -104
- package/dist/vite/node/chunks/postcss-import.js +11 -11
- package/dist/vite/node/cli.js +3 -4
- package/dist/vite/node/index.d.ts +1284 -1285
- package/dist/vite/node/index.js +1 -2
- package/dist/vite/node/module-runner.d.ts +76 -77
- package/dist/vite/node/module-runner.js +6 -7
- package/package.json +20 -18
- package/dist/rolldown/shared/define-config-BBz954-q.d.mts +0 -3901
- package/dist/rolldown/shared/get-log-filter-BpNVNJ5-.d.mts +0 -35
- package/dist/rolldown/shared/transform-CEmFsvJW.d.mts +0 -149
- package/dist/tsdown/debug-DLdR-9XB-DQZ6QLC0.js +0 -250
- package/dist/tsdown/dist-CZtGyfn3.js +0 -200
- package/dist/tsdown/dist-CqbVlnVq.js +0 -32057
- package/dist/tsdown/general-Cp4NiJNK-CbyrS9q1.js +0 -97
- package/dist/tsdown/internal-bfoxcI4F.js +0 -3
- package/dist/tsdown/npm_cjs_chunk_range.cjs +0 -474
- package/dist/tsdown/npm_cjs_chunk_semver.cjs +0 -357
- package/dist/tsdown/npm_entry_semver_functions_coerce.cjs +0 -52
- package/dist/tsdown/npm_entry_semver_functions_satisfies.cjs +0 -19
- package/dist/tsdown/npm_entry_semver_ranges_min-version.cjs +0 -46
- package/dist/tsdown/target-CqeSqtms-FAqYuGyB.js +0 -79
- package/dist/vite/node/chunks/logger.js +0 -361
|
@@ -0,0 +1,2613 @@
|
|
|
1
|
+
import { r as createDebug } from "./main-BdzlWPt6.js";
|
|
2
|
+
import { C as filename_to_dts, S as filename_js_to_dts, T as resolveTemplateFn, _ as RE_JSON, b as RE_TS, g as RE_JS, h as RE_DTS_MAP, m as RE_DTS, p as RE_CSS, v as RE_NODE_MODULES, w as replaceTemplateName, x as filename_dts_to, y as RE_ROLLDOWN_RUNTIME } from "./target-CNxIDvSz-eoHNdJNs.js";
|
|
3
|
+
import { n as ee, t as at } from "./dist-DCMiHFrJ.js";
|
|
4
|
+
import { n as globalContext, r as invalidateContextFile, t as createContext } from "./tsc-context-CA76SkkZ.js";
|
|
5
|
+
import { t as requireTS } from "./load-tsc-BKULZsrs-BFmeD6Bu.js";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { styleText } from "node:util";
|
|
9
|
+
import { fork, spawn } from "node:child_process";
|
|
10
|
+
import path, { dirname, extname } from "node:path";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
import { access, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
13
|
+
import { importerId, include } from "@voidzero-dev/vite-plus-core/rolldown/filter";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { ResolverFactory, isolatedDeclarationSync } from "@voidzero-dev/vite-plus-core/rolldown/experimental";
|
|
16
|
+
import { print } from "yuku-codegen";
|
|
17
|
+
import { parse as parse$1 } from "yuku-parser";
|
|
18
|
+
//#region ../../node_modules/.pnpm/yuku-ast@0.7.0/node_modules/yuku-ast/dist/index.js
|
|
19
|
+
const ALIAS_GROUPS = {
|
|
20
|
+
Expression: [
|
|
21
|
+
"Identifier",
|
|
22
|
+
"Literal",
|
|
23
|
+
"ThisExpression",
|
|
24
|
+
"Super",
|
|
25
|
+
"ArrayExpression",
|
|
26
|
+
"ObjectExpression",
|
|
27
|
+
"FunctionExpression",
|
|
28
|
+
"ArrowFunctionExpression",
|
|
29
|
+
"ClassExpression",
|
|
30
|
+
"TaggedTemplateExpression",
|
|
31
|
+
"TemplateLiteral",
|
|
32
|
+
"MemberExpression",
|
|
33
|
+
"CallExpression",
|
|
34
|
+
"NewExpression",
|
|
35
|
+
"ChainExpression",
|
|
36
|
+
"SequenceExpression",
|
|
37
|
+
"ParenthesizedExpression",
|
|
38
|
+
"BinaryExpression",
|
|
39
|
+
"LogicalExpression",
|
|
40
|
+
"ConditionalExpression",
|
|
41
|
+
"UnaryExpression",
|
|
42
|
+
"UpdateExpression",
|
|
43
|
+
"AssignmentExpression",
|
|
44
|
+
"YieldExpression",
|
|
45
|
+
"AwaitExpression",
|
|
46
|
+
"ImportExpression",
|
|
47
|
+
"MetaProperty",
|
|
48
|
+
"TSAsExpression",
|
|
49
|
+
"TSSatisfiesExpression",
|
|
50
|
+
"TSTypeAssertion",
|
|
51
|
+
"TSNonNullExpression",
|
|
52
|
+
"TSInstantiationExpression",
|
|
53
|
+
"JSXElement",
|
|
54
|
+
"JSXFragment"
|
|
55
|
+
],
|
|
56
|
+
Statement: [
|
|
57
|
+
"ExpressionStatement",
|
|
58
|
+
"BlockStatement",
|
|
59
|
+
"EmptyStatement",
|
|
60
|
+
"DebuggerStatement",
|
|
61
|
+
"ReturnStatement",
|
|
62
|
+
"LabeledStatement",
|
|
63
|
+
"BreakStatement",
|
|
64
|
+
"ContinueStatement",
|
|
65
|
+
"IfStatement",
|
|
66
|
+
"SwitchStatement",
|
|
67
|
+
"ThrowStatement",
|
|
68
|
+
"TryStatement",
|
|
69
|
+
"WhileStatement",
|
|
70
|
+
"DoWhileStatement",
|
|
71
|
+
"ForStatement",
|
|
72
|
+
"ForInStatement",
|
|
73
|
+
"ForOfStatement",
|
|
74
|
+
"WithStatement",
|
|
75
|
+
"FunctionDeclaration",
|
|
76
|
+
"ClassDeclaration",
|
|
77
|
+
"VariableDeclaration",
|
|
78
|
+
"TSDeclareFunction",
|
|
79
|
+
"TSTypeAliasDeclaration",
|
|
80
|
+
"TSInterfaceDeclaration",
|
|
81
|
+
"TSEnumDeclaration",
|
|
82
|
+
"TSModuleDeclaration",
|
|
83
|
+
"TSImportEqualsDeclaration"
|
|
84
|
+
],
|
|
85
|
+
Declaration: [
|
|
86
|
+
"FunctionDeclaration",
|
|
87
|
+
"ClassDeclaration",
|
|
88
|
+
"VariableDeclaration",
|
|
89
|
+
"TSDeclareFunction",
|
|
90
|
+
"TSTypeAliasDeclaration",
|
|
91
|
+
"TSInterfaceDeclaration",
|
|
92
|
+
"TSEnumDeclaration",
|
|
93
|
+
"TSModuleDeclaration",
|
|
94
|
+
"TSImportEqualsDeclaration"
|
|
95
|
+
],
|
|
96
|
+
ModuleDeclaration: [
|
|
97
|
+
"ImportDeclaration",
|
|
98
|
+
"ExportNamedDeclaration",
|
|
99
|
+
"ExportDefaultDeclaration",
|
|
100
|
+
"ExportAllDeclaration",
|
|
101
|
+
"TSExportAssignment",
|
|
102
|
+
"TSNamespaceExportDeclaration"
|
|
103
|
+
],
|
|
104
|
+
Function: [
|
|
105
|
+
"FunctionDeclaration",
|
|
106
|
+
"FunctionExpression",
|
|
107
|
+
"TSDeclareFunction",
|
|
108
|
+
"TSEmptyBodyFunctionExpression",
|
|
109
|
+
"ArrowFunctionExpression"
|
|
110
|
+
],
|
|
111
|
+
Class: ["ClassDeclaration", "ClassExpression"],
|
|
112
|
+
Method: ["MethodDefinition", "TSAbstractMethodDefinition"],
|
|
113
|
+
Loop: [
|
|
114
|
+
"DoWhileStatement",
|
|
115
|
+
"ForInStatement",
|
|
116
|
+
"ForOfStatement",
|
|
117
|
+
"ForStatement",
|
|
118
|
+
"WhileStatement"
|
|
119
|
+
],
|
|
120
|
+
Pattern: [
|
|
121
|
+
"ArrayPattern",
|
|
122
|
+
"ObjectPattern",
|
|
123
|
+
"AssignmentPattern",
|
|
124
|
+
"RestElement"
|
|
125
|
+
],
|
|
126
|
+
JSX: [
|
|
127
|
+
"JSXAttribute",
|
|
128
|
+
"JSXClosingElement",
|
|
129
|
+
"JSXClosingFragment",
|
|
130
|
+
"JSXElement",
|
|
131
|
+
"JSXEmptyExpression",
|
|
132
|
+
"JSXExpressionContainer",
|
|
133
|
+
"JSXFragment",
|
|
134
|
+
"JSXIdentifier",
|
|
135
|
+
"JSXMemberExpression",
|
|
136
|
+
"JSXNamespacedName",
|
|
137
|
+
"JSXOpeningElement",
|
|
138
|
+
"JSXOpeningFragment",
|
|
139
|
+
"JSXSpreadAttribute",
|
|
140
|
+
"JSXSpreadChild",
|
|
141
|
+
"JSXText"
|
|
142
|
+
],
|
|
143
|
+
TSType: [
|
|
144
|
+
"TSAnyKeyword",
|
|
145
|
+
"TSUnknownKeyword",
|
|
146
|
+
"TSNeverKeyword",
|
|
147
|
+
"TSVoidKeyword",
|
|
148
|
+
"TSNullKeyword",
|
|
149
|
+
"TSUndefinedKeyword",
|
|
150
|
+
"TSStringKeyword",
|
|
151
|
+
"TSNumberKeyword",
|
|
152
|
+
"TSBigIntKeyword",
|
|
153
|
+
"TSBooleanKeyword",
|
|
154
|
+
"TSSymbolKeyword",
|
|
155
|
+
"TSObjectKeyword",
|
|
156
|
+
"TSIntrinsicKeyword",
|
|
157
|
+
"TSThisType",
|
|
158
|
+
"TSTypeReference",
|
|
159
|
+
"TSTypeQuery",
|
|
160
|
+
"TSImportType",
|
|
161
|
+
"TSLiteralType",
|
|
162
|
+
"TSTemplateLiteralType",
|
|
163
|
+
"TSArrayType",
|
|
164
|
+
"TSIndexedAccessType",
|
|
165
|
+
"TSTupleType",
|
|
166
|
+
"TSNamedTupleMember",
|
|
167
|
+
"TSJSDocNullableType",
|
|
168
|
+
"TSJSDocNonNullableType",
|
|
169
|
+
"TSJSDocUnknownType",
|
|
170
|
+
"TSUnionType",
|
|
171
|
+
"TSIntersectionType",
|
|
172
|
+
"TSConditionalType",
|
|
173
|
+
"TSInferType",
|
|
174
|
+
"TSTypeOperator",
|
|
175
|
+
"TSParenthesizedType",
|
|
176
|
+
"TSFunctionType",
|
|
177
|
+
"TSConstructorType",
|
|
178
|
+
"TSTypePredicate",
|
|
179
|
+
"TSTypeLiteral",
|
|
180
|
+
"TSMappedType"
|
|
181
|
+
]
|
|
182
|
+
};
|
|
183
|
+
Object.keys(ALIAS_GROUPS);
|
|
184
|
+
const KEYS = Object.create(null);
|
|
185
|
+
function ck(type, keys) {
|
|
186
|
+
const prev = KEYS[type];
|
|
187
|
+
if (prev === void 0) KEYS[type] = keys;
|
|
188
|
+
else for (const k of keys) if (!prev.includes(k)) prev.push(k);
|
|
189
|
+
}
|
|
190
|
+
ck("SequenceExpression", ["expressions"]);
|
|
191
|
+
ck("ParenthesizedExpression", ["expression"]);
|
|
192
|
+
ck("ArrowFunctionExpression", [
|
|
193
|
+
"typeParameters",
|
|
194
|
+
"params",
|
|
195
|
+
"returnType",
|
|
196
|
+
"body"
|
|
197
|
+
]);
|
|
198
|
+
ck("FunctionDeclaration", [
|
|
199
|
+
"id",
|
|
200
|
+
"typeParameters",
|
|
201
|
+
"params",
|
|
202
|
+
"returnType",
|
|
203
|
+
"body"
|
|
204
|
+
]);
|
|
205
|
+
ck("FunctionExpression", [
|
|
206
|
+
"id",
|
|
207
|
+
"typeParameters",
|
|
208
|
+
"params",
|
|
209
|
+
"returnType",
|
|
210
|
+
"body"
|
|
211
|
+
]);
|
|
212
|
+
ck("TSDeclareFunction", [
|
|
213
|
+
"id",
|
|
214
|
+
"typeParameters",
|
|
215
|
+
"params",
|
|
216
|
+
"returnType",
|
|
217
|
+
"body"
|
|
218
|
+
]);
|
|
219
|
+
ck("TSEmptyBodyFunctionExpression", [
|
|
220
|
+
"id",
|
|
221
|
+
"typeParameters",
|
|
222
|
+
"params",
|
|
223
|
+
"returnType",
|
|
224
|
+
"body"
|
|
225
|
+
]);
|
|
226
|
+
ck("BlockStatement", ["body"]);
|
|
227
|
+
ck("BlockStatement", ["body"]);
|
|
228
|
+
ck("BinaryExpression", ["left", "right"]);
|
|
229
|
+
ck("LogicalExpression", ["left", "right"]);
|
|
230
|
+
ck("ConditionalExpression", [
|
|
231
|
+
"test",
|
|
232
|
+
"consequent",
|
|
233
|
+
"alternate"
|
|
234
|
+
]);
|
|
235
|
+
ck("UnaryExpression", ["argument"]);
|
|
236
|
+
ck("UpdateExpression", ["argument"]);
|
|
237
|
+
ck("AssignmentExpression", ["left", "right"]);
|
|
238
|
+
ck("ArrayExpression", ["elements"]);
|
|
239
|
+
ck("ObjectExpression", ["properties"]);
|
|
240
|
+
ck("SpreadElement", ["argument"]);
|
|
241
|
+
ck("Property", ["key", "value"]);
|
|
242
|
+
ck("MemberExpression", ["object", "property"]);
|
|
243
|
+
ck("CallExpression", [
|
|
244
|
+
"callee",
|
|
245
|
+
"typeArguments",
|
|
246
|
+
"arguments"
|
|
247
|
+
]);
|
|
248
|
+
ck("ChainExpression", ["expression"]);
|
|
249
|
+
ck("TaggedTemplateExpression", [
|
|
250
|
+
"tag",
|
|
251
|
+
"typeArguments",
|
|
252
|
+
"quasi"
|
|
253
|
+
]);
|
|
254
|
+
ck("NewExpression", [
|
|
255
|
+
"callee",
|
|
256
|
+
"typeArguments",
|
|
257
|
+
"arguments"
|
|
258
|
+
]);
|
|
259
|
+
ck("AwaitExpression", ["argument"]);
|
|
260
|
+
ck("YieldExpression", ["argument"]);
|
|
261
|
+
ck("MetaProperty", ["meta", "property"]);
|
|
262
|
+
ck("Decorator", ["expression"]);
|
|
263
|
+
ck("ClassDeclaration", [
|
|
264
|
+
"decorators",
|
|
265
|
+
"id",
|
|
266
|
+
"typeParameters",
|
|
267
|
+
"superClass",
|
|
268
|
+
"superTypeArguments",
|
|
269
|
+
"implements",
|
|
270
|
+
"body"
|
|
271
|
+
]);
|
|
272
|
+
ck("ClassExpression", [
|
|
273
|
+
"decorators",
|
|
274
|
+
"id",
|
|
275
|
+
"typeParameters",
|
|
276
|
+
"superClass",
|
|
277
|
+
"superTypeArguments",
|
|
278
|
+
"implements",
|
|
279
|
+
"body"
|
|
280
|
+
]);
|
|
281
|
+
ck("ClassBody", ["body"]);
|
|
282
|
+
ck("MethodDefinition", [
|
|
283
|
+
"decorators",
|
|
284
|
+
"key",
|
|
285
|
+
"value"
|
|
286
|
+
]);
|
|
287
|
+
ck("TSAbstractMethodDefinition", [
|
|
288
|
+
"decorators",
|
|
289
|
+
"key",
|
|
290
|
+
"value"
|
|
291
|
+
]);
|
|
292
|
+
ck("PropertyDefinition", [
|
|
293
|
+
"decorators",
|
|
294
|
+
"key",
|
|
295
|
+
"typeAnnotation",
|
|
296
|
+
"value"
|
|
297
|
+
]);
|
|
298
|
+
ck("AccessorProperty", [
|
|
299
|
+
"decorators",
|
|
300
|
+
"key",
|
|
301
|
+
"typeAnnotation",
|
|
302
|
+
"value"
|
|
303
|
+
]);
|
|
304
|
+
ck("TSAbstractPropertyDefinition", [
|
|
305
|
+
"decorators",
|
|
306
|
+
"key",
|
|
307
|
+
"typeAnnotation",
|
|
308
|
+
"value"
|
|
309
|
+
]);
|
|
310
|
+
ck("TSAbstractAccessorProperty", [
|
|
311
|
+
"decorators",
|
|
312
|
+
"key",
|
|
313
|
+
"typeAnnotation",
|
|
314
|
+
"value"
|
|
315
|
+
]);
|
|
316
|
+
ck("StaticBlock", ["body"]);
|
|
317
|
+
ck("Super", []);
|
|
318
|
+
ck("Literal", []);
|
|
319
|
+
ck("Literal", []);
|
|
320
|
+
ck("Literal", []);
|
|
321
|
+
ck("Literal", []);
|
|
322
|
+
ck("Literal", []);
|
|
323
|
+
ck("ThisExpression", []);
|
|
324
|
+
ck("Literal", []);
|
|
325
|
+
ck("TemplateLiteral", ["quasis", "expressions"]);
|
|
326
|
+
ck("TemplateElement", []);
|
|
327
|
+
ck("Identifier", []);
|
|
328
|
+
ck("PrivateIdentifier", []);
|
|
329
|
+
ck("Identifier", ["decorators", "typeAnnotation"]);
|
|
330
|
+
ck("Identifier", []);
|
|
331
|
+
ck("Identifier", []);
|
|
332
|
+
ck("ExpressionStatement", ["expression"]);
|
|
333
|
+
ck("IfStatement", [
|
|
334
|
+
"test",
|
|
335
|
+
"consequent",
|
|
336
|
+
"alternate"
|
|
337
|
+
]);
|
|
338
|
+
ck("SwitchStatement", ["discriminant", "cases"]);
|
|
339
|
+
ck("SwitchCase", ["test", "consequent"]);
|
|
340
|
+
ck("ForStatement", [
|
|
341
|
+
"init",
|
|
342
|
+
"test",
|
|
343
|
+
"update",
|
|
344
|
+
"body"
|
|
345
|
+
]);
|
|
346
|
+
ck("ForInStatement", [
|
|
347
|
+
"left",
|
|
348
|
+
"right",
|
|
349
|
+
"body"
|
|
350
|
+
]);
|
|
351
|
+
ck("ForOfStatement", [
|
|
352
|
+
"left",
|
|
353
|
+
"right",
|
|
354
|
+
"body"
|
|
355
|
+
]);
|
|
356
|
+
ck("WhileStatement", ["test", "body"]);
|
|
357
|
+
ck("DoWhileStatement", ["body", "test"]);
|
|
358
|
+
ck("BreakStatement", ["label"]);
|
|
359
|
+
ck("ContinueStatement", ["label"]);
|
|
360
|
+
ck("LabeledStatement", ["label", "body"]);
|
|
361
|
+
ck("WithStatement", ["object", "body"]);
|
|
362
|
+
ck("ReturnStatement", ["argument"]);
|
|
363
|
+
ck("ThrowStatement", ["argument"]);
|
|
364
|
+
ck("TryStatement", [
|
|
365
|
+
"block",
|
|
366
|
+
"handler",
|
|
367
|
+
"finalizer"
|
|
368
|
+
]);
|
|
369
|
+
ck("CatchClause", ["param", "body"]);
|
|
370
|
+
ck("DebuggerStatement", []);
|
|
371
|
+
ck("EmptyStatement", []);
|
|
372
|
+
ck("VariableDeclaration", ["declarations"]);
|
|
373
|
+
ck("VariableDeclarator", ["id", "init"]);
|
|
374
|
+
ck("ExpressionStatement", ["expression"]);
|
|
375
|
+
ck("AssignmentPattern", [
|
|
376
|
+
"decorators",
|
|
377
|
+
"left",
|
|
378
|
+
"typeAnnotation",
|
|
379
|
+
"right"
|
|
380
|
+
]);
|
|
381
|
+
ck("RestElement", [
|
|
382
|
+
"decorators",
|
|
383
|
+
"argument",
|
|
384
|
+
"typeAnnotation"
|
|
385
|
+
]);
|
|
386
|
+
ck("ArrayPattern", [
|
|
387
|
+
"decorators",
|
|
388
|
+
"elements",
|
|
389
|
+
"typeAnnotation"
|
|
390
|
+
]);
|
|
391
|
+
ck("ObjectPattern", [
|
|
392
|
+
"decorators",
|
|
393
|
+
"properties",
|
|
394
|
+
"typeAnnotation"
|
|
395
|
+
]);
|
|
396
|
+
ck("Property", ["key", "value"]);
|
|
397
|
+
ck("Program", ["hashbang", "body"]);
|
|
398
|
+
ck("ImportExpression", ["source", "options"]);
|
|
399
|
+
ck("ImportDeclaration", [
|
|
400
|
+
"specifiers",
|
|
401
|
+
"source",
|
|
402
|
+
"attributes"
|
|
403
|
+
]);
|
|
404
|
+
ck("ImportSpecifier", ["imported", "local"]);
|
|
405
|
+
ck("ImportDefaultSpecifier", ["local"]);
|
|
406
|
+
ck("ImportNamespaceSpecifier", ["local"]);
|
|
407
|
+
ck("ImportAttribute", ["key", "value"]);
|
|
408
|
+
ck("ExportNamedDeclaration", [
|
|
409
|
+
"declaration",
|
|
410
|
+
"specifiers",
|
|
411
|
+
"source",
|
|
412
|
+
"attributes"
|
|
413
|
+
]);
|
|
414
|
+
ck("ExportDefaultDeclaration", ["declaration"]);
|
|
415
|
+
ck("ExportAllDeclaration", [
|
|
416
|
+
"exported",
|
|
417
|
+
"source",
|
|
418
|
+
"attributes"
|
|
419
|
+
]);
|
|
420
|
+
ck("ExportSpecifier", ["local", "exported"]);
|
|
421
|
+
ck("TSTypeAnnotation", ["typeAnnotation"]);
|
|
422
|
+
ck("TSAnyKeyword", []);
|
|
423
|
+
ck("TSUnknownKeyword", []);
|
|
424
|
+
ck("TSNeverKeyword", []);
|
|
425
|
+
ck("TSVoidKeyword", []);
|
|
426
|
+
ck("TSNullKeyword", []);
|
|
427
|
+
ck("TSUndefinedKeyword", []);
|
|
428
|
+
ck("TSStringKeyword", []);
|
|
429
|
+
ck("TSNumberKeyword", []);
|
|
430
|
+
ck("TSBigIntKeyword", []);
|
|
431
|
+
ck("TSBooleanKeyword", []);
|
|
432
|
+
ck("TSSymbolKeyword", []);
|
|
433
|
+
ck("TSObjectKeyword", []);
|
|
434
|
+
ck("TSIntrinsicKeyword", []);
|
|
435
|
+
ck("TSThisType", []);
|
|
436
|
+
ck("TSTypeReference", ["typeName", "typeArguments"]);
|
|
437
|
+
ck("TSQualifiedName", ["left", "right"]);
|
|
438
|
+
ck("TSTypeQuery", ["exprName", "typeArguments"]);
|
|
439
|
+
ck("TSImportType", [
|
|
440
|
+
"source",
|
|
441
|
+
"options",
|
|
442
|
+
"qualifier",
|
|
443
|
+
"typeArguments"
|
|
444
|
+
]);
|
|
445
|
+
ck("TSTypeParameter", [
|
|
446
|
+
"name",
|
|
447
|
+
"constraint",
|
|
448
|
+
"default"
|
|
449
|
+
]);
|
|
450
|
+
ck("TSTypeParameterDeclaration", ["params"]);
|
|
451
|
+
ck("TSTypeParameterInstantiation", ["params"]);
|
|
452
|
+
ck("TSLiteralType", ["literal"]);
|
|
453
|
+
ck("TSTemplateLiteralType", ["quasis", "types"]);
|
|
454
|
+
ck("TSArrayType", ["elementType"]);
|
|
455
|
+
ck("TSIndexedAccessType", ["objectType", "indexType"]);
|
|
456
|
+
ck("TSTupleType", ["elementTypes"]);
|
|
457
|
+
ck("TSNamedTupleMember", ["label", "elementType"]);
|
|
458
|
+
ck("TSOptionalType", ["typeAnnotation"]);
|
|
459
|
+
ck("TSRestType", ["typeAnnotation"]);
|
|
460
|
+
ck("TSJSDocNullableType", ["typeAnnotation"]);
|
|
461
|
+
ck("TSJSDocNonNullableType", ["typeAnnotation"]);
|
|
462
|
+
ck("TSJSDocUnknownType", []);
|
|
463
|
+
ck("TSUnionType", ["types"]);
|
|
464
|
+
ck("TSIntersectionType", ["types"]);
|
|
465
|
+
ck("TSConditionalType", [
|
|
466
|
+
"checkType",
|
|
467
|
+
"extendsType",
|
|
468
|
+
"trueType",
|
|
469
|
+
"falseType"
|
|
470
|
+
]);
|
|
471
|
+
ck("TSInferType", ["typeParameter"]);
|
|
472
|
+
ck("TSTypeOperator", ["typeAnnotation"]);
|
|
473
|
+
ck("TSParenthesizedType", ["typeAnnotation"]);
|
|
474
|
+
ck("TSFunctionType", [
|
|
475
|
+
"typeParameters",
|
|
476
|
+
"params",
|
|
477
|
+
"returnType"
|
|
478
|
+
]);
|
|
479
|
+
ck("TSConstructorType", [
|
|
480
|
+
"typeParameters",
|
|
481
|
+
"params",
|
|
482
|
+
"returnType"
|
|
483
|
+
]);
|
|
484
|
+
ck("TSTypePredicate", ["parameterName", "typeAnnotation"]);
|
|
485
|
+
ck("TSTypeLiteral", ["members"]);
|
|
486
|
+
ck("TSMappedType", [
|
|
487
|
+
"key",
|
|
488
|
+
"constraint",
|
|
489
|
+
"nameType",
|
|
490
|
+
"typeAnnotation"
|
|
491
|
+
]);
|
|
492
|
+
ck("TSPropertySignature", ["key", "typeAnnotation"]);
|
|
493
|
+
ck("TSMethodSignature", [
|
|
494
|
+
"key",
|
|
495
|
+
"typeParameters",
|
|
496
|
+
"params",
|
|
497
|
+
"returnType"
|
|
498
|
+
]);
|
|
499
|
+
ck("TSCallSignatureDeclaration", [
|
|
500
|
+
"typeParameters",
|
|
501
|
+
"params",
|
|
502
|
+
"returnType"
|
|
503
|
+
]);
|
|
504
|
+
ck("TSConstructSignatureDeclaration", [
|
|
505
|
+
"typeParameters",
|
|
506
|
+
"params",
|
|
507
|
+
"returnType"
|
|
508
|
+
]);
|
|
509
|
+
ck("TSIndexSignature", ["parameters", "typeAnnotation"]);
|
|
510
|
+
ck("TSTypeAliasDeclaration", [
|
|
511
|
+
"id",
|
|
512
|
+
"typeParameters",
|
|
513
|
+
"typeAnnotation"
|
|
514
|
+
]);
|
|
515
|
+
ck("TSInterfaceDeclaration", [
|
|
516
|
+
"id",
|
|
517
|
+
"typeParameters",
|
|
518
|
+
"extends",
|
|
519
|
+
"body"
|
|
520
|
+
]);
|
|
521
|
+
ck("TSInterfaceBody", ["body"]);
|
|
522
|
+
ck("TSInterfaceHeritage", ["expression", "typeArguments"]);
|
|
523
|
+
ck("TSClassImplements", ["expression", "typeArguments"]);
|
|
524
|
+
ck("TSEnumDeclaration", ["id", "body"]);
|
|
525
|
+
ck("TSEnumBody", ["members"]);
|
|
526
|
+
ck("TSEnumMember", ["id", "initializer"]);
|
|
527
|
+
ck("TSModuleDeclaration", ["id", "body"]);
|
|
528
|
+
ck("TSModuleBlock", ["body"]);
|
|
529
|
+
ck("TSModuleDeclaration", ["id", "body"]);
|
|
530
|
+
ck("TSParameterProperty", ["decorators", "parameter"]);
|
|
531
|
+
ck("Identifier", ["typeAnnotation"]);
|
|
532
|
+
ck("TSAsExpression", ["expression", "typeAnnotation"]);
|
|
533
|
+
ck("TSSatisfiesExpression", ["expression", "typeAnnotation"]);
|
|
534
|
+
ck("TSTypeAssertion", ["typeAnnotation", "expression"]);
|
|
535
|
+
ck("TSNonNullExpression", ["expression"]);
|
|
536
|
+
ck("TSInstantiationExpression", ["expression", "typeArguments"]);
|
|
537
|
+
ck("TSExportAssignment", ["expression"]);
|
|
538
|
+
ck("TSNamespaceExportDeclaration", ["id"]);
|
|
539
|
+
ck("TSImportEqualsDeclaration", ["id", "moduleReference"]);
|
|
540
|
+
ck("TSExternalModuleReference", ["expression"]);
|
|
541
|
+
ck("JSXElement", [
|
|
542
|
+
"openingElement",
|
|
543
|
+
"children",
|
|
544
|
+
"closingElement"
|
|
545
|
+
]);
|
|
546
|
+
ck("JSXOpeningElement", [
|
|
547
|
+
"name",
|
|
548
|
+
"typeArguments",
|
|
549
|
+
"attributes"
|
|
550
|
+
]);
|
|
551
|
+
ck("JSXClosingElement", ["name"]);
|
|
552
|
+
ck("JSXFragment", [
|
|
553
|
+
"openingFragment",
|
|
554
|
+
"children",
|
|
555
|
+
"closingFragment"
|
|
556
|
+
]);
|
|
557
|
+
ck("JSXOpeningFragment", []);
|
|
558
|
+
ck("JSXClosingFragment", []);
|
|
559
|
+
ck("JSXIdentifier", []);
|
|
560
|
+
ck("JSXNamespacedName", ["namespace", "name"]);
|
|
561
|
+
ck("JSXMemberExpression", ["object", "property"]);
|
|
562
|
+
ck("JSXAttribute", ["name", "value"]);
|
|
563
|
+
ck("JSXSpreadAttribute", ["argument"]);
|
|
564
|
+
ck("JSXExpressionContainer", ["expression"]);
|
|
565
|
+
ck("JSXEmptyExpression", []);
|
|
566
|
+
ck("JSXText", []);
|
|
567
|
+
ck("JSXSpreadChild", ["expression"]);
|
|
568
|
+
ck("Hashbang", []);
|
|
569
|
+
const CHILD_KEYS = KEYS;
|
|
570
|
+
const NODE_TYPES = [.../* @__PURE__ */ new Set([
|
|
571
|
+
"SequenceExpression",
|
|
572
|
+
"ParenthesizedExpression",
|
|
573
|
+
"ArrowFunctionExpression",
|
|
574
|
+
"FunctionDeclaration",
|
|
575
|
+
"FunctionExpression",
|
|
576
|
+
"TSDeclareFunction",
|
|
577
|
+
"TSEmptyBodyFunctionExpression",
|
|
578
|
+
"BlockStatement",
|
|
579
|
+
"BlockStatement",
|
|
580
|
+
"BinaryExpression",
|
|
581
|
+
"LogicalExpression",
|
|
582
|
+
"ConditionalExpression",
|
|
583
|
+
"UnaryExpression",
|
|
584
|
+
"UpdateExpression",
|
|
585
|
+
"AssignmentExpression",
|
|
586
|
+
"ArrayExpression",
|
|
587
|
+
"ObjectExpression",
|
|
588
|
+
"SpreadElement",
|
|
589
|
+
"Property",
|
|
590
|
+
"MemberExpression",
|
|
591
|
+
"CallExpression",
|
|
592
|
+
"ChainExpression",
|
|
593
|
+
"TaggedTemplateExpression",
|
|
594
|
+
"NewExpression",
|
|
595
|
+
"AwaitExpression",
|
|
596
|
+
"YieldExpression",
|
|
597
|
+
"MetaProperty",
|
|
598
|
+
"Decorator",
|
|
599
|
+
"ClassDeclaration",
|
|
600
|
+
"ClassExpression",
|
|
601
|
+
"ClassBody",
|
|
602
|
+
"MethodDefinition",
|
|
603
|
+
"TSAbstractMethodDefinition",
|
|
604
|
+
"PropertyDefinition",
|
|
605
|
+
"AccessorProperty",
|
|
606
|
+
"TSAbstractPropertyDefinition",
|
|
607
|
+
"TSAbstractAccessorProperty",
|
|
608
|
+
"StaticBlock",
|
|
609
|
+
"Super",
|
|
610
|
+
"Literal",
|
|
611
|
+
"Literal",
|
|
612
|
+
"Literal",
|
|
613
|
+
"Literal",
|
|
614
|
+
"Literal",
|
|
615
|
+
"ThisExpression",
|
|
616
|
+
"Literal",
|
|
617
|
+
"TemplateLiteral",
|
|
618
|
+
"TemplateElement",
|
|
619
|
+
"Identifier",
|
|
620
|
+
"PrivateIdentifier",
|
|
621
|
+
"Identifier",
|
|
622
|
+
"Identifier",
|
|
623
|
+
"Identifier",
|
|
624
|
+
"ExpressionStatement",
|
|
625
|
+
"IfStatement",
|
|
626
|
+
"SwitchStatement",
|
|
627
|
+
"SwitchCase",
|
|
628
|
+
"ForStatement",
|
|
629
|
+
"ForInStatement",
|
|
630
|
+
"ForOfStatement",
|
|
631
|
+
"WhileStatement",
|
|
632
|
+
"DoWhileStatement",
|
|
633
|
+
"BreakStatement",
|
|
634
|
+
"ContinueStatement",
|
|
635
|
+
"LabeledStatement",
|
|
636
|
+
"WithStatement",
|
|
637
|
+
"ReturnStatement",
|
|
638
|
+
"ThrowStatement",
|
|
639
|
+
"TryStatement",
|
|
640
|
+
"CatchClause",
|
|
641
|
+
"DebuggerStatement",
|
|
642
|
+
"EmptyStatement",
|
|
643
|
+
"VariableDeclaration",
|
|
644
|
+
"VariableDeclarator",
|
|
645
|
+
"ExpressionStatement",
|
|
646
|
+
"AssignmentPattern",
|
|
647
|
+
"RestElement",
|
|
648
|
+
"ArrayPattern",
|
|
649
|
+
"ObjectPattern",
|
|
650
|
+
"Property",
|
|
651
|
+
"Program",
|
|
652
|
+
"ImportExpression",
|
|
653
|
+
"ImportDeclaration",
|
|
654
|
+
"ImportSpecifier",
|
|
655
|
+
"ImportDefaultSpecifier",
|
|
656
|
+
"ImportNamespaceSpecifier",
|
|
657
|
+
"ImportAttribute",
|
|
658
|
+
"ExportNamedDeclaration",
|
|
659
|
+
"ExportDefaultDeclaration",
|
|
660
|
+
"ExportAllDeclaration",
|
|
661
|
+
"ExportSpecifier",
|
|
662
|
+
"TSTypeAnnotation",
|
|
663
|
+
"TSAnyKeyword",
|
|
664
|
+
"TSUnknownKeyword",
|
|
665
|
+
"TSNeverKeyword",
|
|
666
|
+
"TSVoidKeyword",
|
|
667
|
+
"TSNullKeyword",
|
|
668
|
+
"TSUndefinedKeyword",
|
|
669
|
+
"TSStringKeyword",
|
|
670
|
+
"TSNumberKeyword",
|
|
671
|
+
"TSBigIntKeyword",
|
|
672
|
+
"TSBooleanKeyword",
|
|
673
|
+
"TSSymbolKeyword",
|
|
674
|
+
"TSObjectKeyword",
|
|
675
|
+
"TSIntrinsicKeyword",
|
|
676
|
+
"TSThisType",
|
|
677
|
+
"TSTypeReference",
|
|
678
|
+
"TSQualifiedName",
|
|
679
|
+
"TSTypeQuery",
|
|
680
|
+
"TSImportType",
|
|
681
|
+
"TSTypeParameter",
|
|
682
|
+
"TSTypeParameterDeclaration",
|
|
683
|
+
"TSTypeParameterInstantiation",
|
|
684
|
+
"TSLiteralType",
|
|
685
|
+
"TSTemplateLiteralType",
|
|
686
|
+
"TSArrayType",
|
|
687
|
+
"TSIndexedAccessType",
|
|
688
|
+
"TSTupleType",
|
|
689
|
+
"TSNamedTupleMember",
|
|
690
|
+
"TSOptionalType",
|
|
691
|
+
"TSRestType",
|
|
692
|
+
"TSJSDocNullableType",
|
|
693
|
+
"TSJSDocNonNullableType",
|
|
694
|
+
"TSJSDocUnknownType",
|
|
695
|
+
"TSUnionType",
|
|
696
|
+
"TSIntersectionType",
|
|
697
|
+
"TSConditionalType",
|
|
698
|
+
"TSInferType",
|
|
699
|
+
"TSTypeOperator",
|
|
700
|
+
"TSParenthesizedType",
|
|
701
|
+
"TSFunctionType",
|
|
702
|
+
"TSConstructorType",
|
|
703
|
+
"TSTypePredicate",
|
|
704
|
+
"TSTypeLiteral",
|
|
705
|
+
"TSMappedType",
|
|
706
|
+
"TSPropertySignature",
|
|
707
|
+
"TSMethodSignature",
|
|
708
|
+
"TSCallSignatureDeclaration",
|
|
709
|
+
"TSConstructSignatureDeclaration",
|
|
710
|
+
"TSIndexSignature",
|
|
711
|
+
"TSTypeAliasDeclaration",
|
|
712
|
+
"TSInterfaceDeclaration",
|
|
713
|
+
"TSInterfaceBody",
|
|
714
|
+
"TSInterfaceHeritage",
|
|
715
|
+
"TSClassImplements",
|
|
716
|
+
"TSEnumDeclaration",
|
|
717
|
+
"TSEnumBody",
|
|
718
|
+
"TSEnumMember",
|
|
719
|
+
"TSModuleDeclaration",
|
|
720
|
+
"TSModuleBlock",
|
|
721
|
+
"TSModuleDeclaration",
|
|
722
|
+
"TSParameterProperty",
|
|
723
|
+
"Identifier",
|
|
724
|
+
"TSAsExpression",
|
|
725
|
+
"TSSatisfiesExpression",
|
|
726
|
+
"TSTypeAssertion",
|
|
727
|
+
"TSNonNullExpression",
|
|
728
|
+
"TSInstantiationExpression",
|
|
729
|
+
"TSExportAssignment",
|
|
730
|
+
"TSNamespaceExportDeclaration",
|
|
731
|
+
"TSImportEqualsDeclaration",
|
|
732
|
+
"TSExternalModuleReference",
|
|
733
|
+
"JSXElement",
|
|
734
|
+
"JSXOpeningElement",
|
|
735
|
+
"JSXClosingElement",
|
|
736
|
+
"JSXFragment",
|
|
737
|
+
"JSXOpeningFragment",
|
|
738
|
+
"JSXClosingFragment",
|
|
739
|
+
"JSXIdentifier",
|
|
740
|
+
"JSXNamespacedName",
|
|
741
|
+
"JSXMemberExpression",
|
|
742
|
+
"JSXAttribute",
|
|
743
|
+
"JSXSpreadAttribute",
|
|
744
|
+
"JSXExpressionContainer",
|
|
745
|
+
"JSXEmptyExpression",
|
|
746
|
+
"JSXText",
|
|
747
|
+
"JSXSpreadChild",
|
|
748
|
+
"Hashbang"
|
|
749
|
+
])];
|
|
750
|
+
/**
|
|
751
|
+
* One constructor per node type, its fields derived from the node type
|
|
752
|
+
* itself. `start` and `end` default to 0, which `ctx.replace` treats
|
|
753
|
+
* as span-less and fills from the replaced node.
|
|
754
|
+
*
|
|
755
|
+
* @example
|
|
756
|
+
* b.Identifier({ name: "x" })
|
|
757
|
+
* b.ExpressionStatement({ expression: b.Identifier({ name: "x" }) })
|
|
758
|
+
*/
|
|
759
|
+
const b = Object.fromEntries(NODE_TYPES.map((type) => [type, (fields) => ({
|
|
760
|
+
type,
|
|
761
|
+
start: 0,
|
|
762
|
+
end: 0,
|
|
763
|
+
...fields
|
|
764
|
+
})]));
|
|
765
|
+
/**
|
|
766
|
+
* The walk context: one reused object exposing the current position and
|
|
767
|
+
* the tree mutation operations. Valid only during the visit that
|
|
768
|
+
* receives it, do not store it. Underscore members are engine state.
|
|
769
|
+
*/
|
|
770
|
+
var WalkContext = class {
|
|
771
|
+
_ancestors = [];
|
|
772
|
+
_node = null;
|
|
773
|
+
_key = null;
|
|
774
|
+
_list = null;
|
|
775
|
+
_frame = null;
|
|
776
|
+
_skip = false;
|
|
777
|
+
_stopped = false;
|
|
778
|
+
_removed = false;
|
|
779
|
+
_replacement = null;
|
|
780
|
+
/** State threaded through the walk, the third `walk` argument. */
|
|
781
|
+
state;
|
|
782
|
+
/** The node being visited. */
|
|
783
|
+
get node() {
|
|
784
|
+
return this._node;
|
|
785
|
+
}
|
|
786
|
+
/** The node holding {@link node}, or null at the walk root. */
|
|
787
|
+
get parent() {
|
|
788
|
+
const a = this._ancestors;
|
|
789
|
+
return a.length === 0 ? null : a[a.length - 1];
|
|
790
|
+
}
|
|
791
|
+
/** The field on {@link parent} holding {@link node}, or null at the root. */
|
|
792
|
+
get key() {
|
|
793
|
+
return this._key;
|
|
794
|
+
}
|
|
795
|
+
/** Index within an array field, or null in a plain field. */
|
|
796
|
+
get index() {
|
|
797
|
+
return this._list === null ? null : this._frame.i;
|
|
798
|
+
}
|
|
799
|
+
/** Ancestors from the walk root down to {@link parent}. */
|
|
800
|
+
ancestors() {
|
|
801
|
+
return [...this._ancestors];
|
|
802
|
+
}
|
|
803
|
+
/** Do not descend into the current node's children. */
|
|
804
|
+
skip() {
|
|
805
|
+
this._skip = true;
|
|
806
|
+
}
|
|
807
|
+
/** Stop the walk entirely. */
|
|
808
|
+
stop() {
|
|
809
|
+
this._stopped = true;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Replace the current node. The walk continues into the replacement's
|
|
813
|
+
* children and `leave` fires for the replacement's type. A synthetic
|
|
814
|
+
* node with `start === 0 && end === 0` inherits the original span,
|
|
815
|
+
* for source maps. Throws at the walk root.
|
|
816
|
+
*/
|
|
817
|
+
replace(node) {
|
|
818
|
+
if (node === null || typeof node !== "object" || typeof node.type !== "string") throw new TypeError("replace: expected an AST node");
|
|
819
|
+
if (this.parent === null) throw new TypeError("replace: cannot replace the walk root");
|
|
820
|
+
if (node.start === 0 && node.end === 0) {
|
|
821
|
+
node.start = this.node.start;
|
|
822
|
+
node.end = this.node.end;
|
|
823
|
+
}
|
|
824
|
+
this._replacement = node;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Remove the current node from its parent: spliced from array fields,
|
|
828
|
+
* nulled in plain fields. Children are not walked and `leave` does
|
|
829
|
+
* not fire. Throws at the walk root.
|
|
830
|
+
*/
|
|
831
|
+
remove() {
|
|
832
|
+
if (this.parent === null) throw new TypeError("remove: cannot remove the walk root");
|
|
833
|
+
this._removed = true;
|
|
834
|
+
}
|
|
835
|
+
/** Insert a sibling before the current node, not visited. Array fields only. */
|
|
836
|
+
insertBefore(node) {
|
|
837
|
+
this.#insert(node, 0);
|
|
838
|
+
this._frame.i++;
|
|
839
|
+
}
|
|
840
|
+
/** Insert a sibling after the current node, visited by the walk. Array fields only. */
|
|
841
|
+
insertAfter(node) {
|
|
842
|
+
this.#insert(node, 1);
|
|
843
|
+
}
|
|
844
|
+
#insert(node, offset) {
|
|
845
|
+
if (this._list === null) throw new TypeError("insertBefore/insertAfter require a node in an array field");
|
|
846
|
+
this._list.splice(this._frame.i + offset, 0, node);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
const IDENTIFIER_NAME = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
|
|
850
|
+
/**
|
|
851
|
+
* True if `name` is a valid ECMAScript `IdentifierName`, the grammar an
|
|
852
|
+
* identifier token must satisfy. Validates a raw string, not a node.
|
|
853
|
+
* Reserved words are syntactically identifier names, so
|
|
854
|
+
* `isIdentifierName("class")` is true, see {@link isValidIdentifier}.
|
|
855
|
+
*/
|
|
856
|
+
function isIdentifierName(name) {
|
|
857
|
+
return IDENTIFIER_NAME.test(name);
|
|
858
|
+
}
|
|
859
|
+
function aliasGuard(name) {
|
|
860
|
+
const set = new Set(ALIAS_GROUPS[name]);
|
|
861
|
+
return (node) => node != null && set.has(node.type);
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Type guards, one per concrete node `type` plus alias and shape
|
|
865
|
+
* guards. Every guard accepts `null` and `undefined` and narrows.
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* is.CallExpression(node)
|
|
869
|
+
* is.Identifier(node, "require")
|
|
870
|
+
* is.Expression(node)
|
|
871
|
+
* is.StringLiteral(node)
|
|
872
|
+
*/
|
|
873
|
+
const is = {
|
|
874
|
+
...Object.fromEntries(NODE_TYPES.map((type) => [type, (node) => node != null && node.type === type])),
|
|
875
|
+
oneOf: (node, types) => node != null && types.some((type) => type === node.type),
|
|
876
|
+
Identifier: (node, name) => node?.type === "Identifier" && (name === void 0 || node.name === name),
|
|
877
|
+
Expression: aliasGuard("Expression"),
|
|
878
|
+
Statement: aliasGuard("Statement"),
|
|
879
|
+
Declaration: aliasGuard("Declaration"),
|
|
880
|
+
ModuleDeclaration: aliasGuard("ModuleDeclaration"),
|
|
881
|
+
Function: aliasGuard("Function"),
|
|
882
|
+
Class: aliasGuard("Class"),
|
|
883
|
+
Method: aliasGuard("Method"),
|
|
884
|
+
Loop: aliasGuard("Loop"),
|
|
885
|
+
Pattern: aliasGuard("Pattern"),
|
|
886
|
+
JSX: aliasGuard("JSX"),
|
|
887
|
+
TSType: aliasGuard("TSType"),
|
|
888
|
+
StringLiteral: (node) => node?.type === "Literal" && typeof node.value === "string",
|
|
889
|
+
NumericLiteral: (node) => node?.type === "Literal" && typeof node.value === "number",
|
|
890
|
+
BooleanLiteral: (node) => node?.type === "Literal" && typeof node.value === "boolean",
|
|
891
|
+
NullLiteral: (node) => node?.type === "Literal" && node.raw === "null",
|
|
892
|
+
BigIntLiteral: (node) => node?.type === "Literal" && "bigint" in node,
|
|
893
|
+
RegExpLiteral: (node) => node?.type === "Literal" && "regex" in node,
|
|
894
|
+
ComputedMemberExpression: (node) => node?.type === "MemberExpression" && node.computed,
|
|
895
|
+
StaticMemberExpression: (node) => node?.type === "MemberExpression" && !node.computed && node.property.type === "Identifier",
|
|
896
|
+
PrivateFieldExpression: (node) => node?.type === "MemberExpression" && node.property.type === "PrivateIdentifier",
|
|
897
|
+
Directive: (node) => node?.type === "ExpressionStatement" && node.directive != null
|
|
898
|
+
};
|
|
899
|
+
function createDispatch(visitors) {
|
|
900
|
+
let enter = null;
|
|
901
|
+
let leave = null;
|
|
902
|
+
const concrete$1 = /* @__PURE__ */ new Map();
|
|
903
|
+
const add = (type, handler) => {
|
|
904
|
+
const hooks = typeof handler === "function" ? { enter: handler } : handler;
|
|
905
|
+
let entry = concrete$1.get(type);
|
|
906
|
+
if (entry === void 0) {
|
|
907
|
+
entry = {
|
|
908
|
+
enter: [],
|
|
909
|
+
leave: []
|
|
910
|
+
};
|
|
911
|
+
concrete$1.set(type, entry);
|
|
912
|
+
}
|
|
913
|
+
if (hooks.enter) entry.enter.push(hooks.enter);
|
|
914
|
+
if (hooks.leave) entry.leave.unshift(hooks.leave);
|
|
915
|
+
};
|
|
916
|
+
for (const [name, value] of Object.entries(visitors)) {
|
|
917
|
+
if (value == null) continue;
|
|
918
|
+
if (name === "enter") enter = value;
|
|
919
|
+
else if (name === "leave") leave = value;
|
|
920
|
+
else if (name in ALIAS_GROUPS) for (const type of ALIAS_GROUPS[name]) add(type, value);
|
|
921
|
+
}
|
|
922
|
+
for (const [name, value] of Object.entries(visitors)) {
|
|
923
|
+
if (value == null || name === "enter" || name === "leave" || name in ALIAS_GROUPS) continue;
|
|
924
|
+
add(name, value);
|
|
925
|
+
}
|
|
926
|
+
return {
|
|
927
|
+
enter,
|
|
928
|
+
leave,
|
|
929
|
+
typed: (type) => concrete$1.get(type)
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Walk an AST depth-first, dispatching to typed visitors and mutating
|
|
934
|
+
* in place. Traversal order is driven by tables generated from the
|
|
935
|
+
* parser's AST definition, so it can never drift. Returns the root.
|
|
936
|
+
*/
|
|
937
|
+
function walk(root, visitors, state) {
|
|
938
|
+
_walk(root, visitors, state, new WalkContext());
|
|
939
|
+
return root;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* The async counterpart of {@link walk}: identical traversal order and
|
|
943
|
+
* mutation semantics, with every handler awaited before the walk moves
|
|
944
|
+
* on. Resolves to the root.
|
|
945
|
+
*/
|
|
946
|
+
async function walkAsync(root, visitors, state) {
|
|
947
|
+
await _walkAsync(root, visitors, state, new WalkContext());
|
|
948
|
+
return root;
|
|
949
|
+
}
|
|
950
|
+
function position(ctx, node, key, list, frame) {
|
|
951
|
+
ctx._node = node;
|
|
952
|
+
ctx._key = key;
|
|
953
|
+
ctx._list = list;
|
|
954
|
+
ctx._frame = frame;
|
|
955
|
+
}
|
|
956
|
+
function applyReplace(ctx, parent, key, list, frame) {
|
|
957
|
+
const next = ctx._replacement;
|
|
958
|
+
ctx._replacement = null;
|
|
959
|
+
if (list !== null) list[frame.i] = next;
|
|
960
|
+
else parent[key] = next;
|
|
961
|
+
return next;
|
|
962
|
+
}
|
|
963
|
+
function applyRemove(ctx, parent, key, list, frame) {
|
|
964
|
+
ctx._removed = false;
|
|
965
|
+
if (list !== null) {
|
|
966
|
+
list.splice(frame.i, 1);
|
|
967
|
+
frame.i--;
|
|
968
|
+
} else parent[key] = null;
|
|
969
|
+
}
|
|
970
|
+
function _walk(root, visitors, state, ctx) {
|
|
971
|
+
const d = createDispatch(visitors);
|
|
972
|
+
ctx.state = state;
|
|
973
|
+
const ancestors = ctx._ancestors;
|
|
974
|
+
(function visit(node, key, list, frame) {
|
|
975
|
+
let typed = d.typed(node.type);
|
|
976
|
+
const parent = ctx.parent;
|
|
977
|
+
position(ctx, node, key, list, frame);
|
|
978
|
+
if (d.enter !== null) {
|
|
979
|
+
d.enter(node, ctx);
|
|
980
|
+
if (ctx._stopped) return false;
|
|
981
|
+
}
|
|
982
|
+
if (typed !== void 0) for (const handler of typed.enter) {
|
|
983
|
+
handler(node, ctx);
|
|
984
|
+
if (ctx._stopped) return false;
|
|
985
|
+
}
|
|
986
|
+
if (ctx._removed) {
|
|
987
|
+
applyRemove(ctx, parent, key, list, frame);
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
if (ctx._replacement !== null) {
|
|
991
|
+
node = applyReplace(ctx, parent, key, list, frame);
|
|
992
|
+
typed = d.typed(node.type);
|
|
993
|
+
}
|
|
994
|
+
const skipped = ctx._skip;
|
|
995
|
+
ctx._skip = false;
|
|
996
|
+
if (!skipped) {
|
|
997
|
+
const keys = CHILD_KEYS[node.type];
|
|
998
|
+
if (keys !== void 0 && keys.length > 0) {
|
|
999
|
+
ancestors.push(node);
|
|
1000
|
+
for (let k = 0; k < keys.length; k++) {
|
|
1001
|
+
const key2 = keys[k];
|
|
1002
|
+
const value = node[key2];
|
|
1003
|
+
if (value === null || value === void 0 || typeof value !== "object") continue;
|
|
1004
|
+
if (Array.isArray(value)) {
|
|
1005
|
+
const childFrame = { i: 0 };
|
|
1006
|
+
for (; childFrame.i < value.length; childFrame.i++) {
|
|
1007
|
+
const item = value[childFrame.i];
|
|
1008
|
+
if (item !== null && !visit(item, key2, value, childFrame)) return false;
|
|
1009
|
+
}
|
|
1010
|
+
} else if (!visit(value, key2, null, null)) return false;
|
|
1011
|
+
}
|
|
1012
|
+
ancestors.pop();
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
position(ctx, node, key, list, frame);
|
|
1016
|
+
if (typed !== void 0) for (const handler of typed.leave) {
|
|
1017
|
+
handler(node, ctx);
|
|
1018
|
+
if (ctx._stopped) return false;
|
|
1019
|
+
}
|
|
1020
|
+
if (d.leave !== null) {
|
|
1021
|
+
d.leave(node, ctx);
|
|
1022
|
+
if (ctx._stopped) return false;
|
|
1023
|
+
}
|
|
1024
|
+
if (ctx._removed) applyRemove(ctx, parent, key, list, frame);
|
|
1025
|
+
else if (ctx._replacement !== null) applyReplace(ctx, parent, key, list, frame);
|
|
1026
|
+
return true;
|
|
1027
|
+
})(root, null, null, null);
|
|
1028
|
+
}
|
|
1029
|
+
async function _walkAsync(root, visitors, state, ctx) {
|
|
1030
|
+
const d = createDispatch(visitors);
|
|
1031
|
+
ctx.state = state;
|
|
1032
|
+
const ancestors = ctx._ancestors;
|
|
1033
|
+
await (async function visit(node, key, list, frame) {
|
|
1034
|
+
let typed = d.typed(node.type);
|
|
1035
|
+
const parent = ctx.parent;
|
|
1036
|
+
position(ctx, node, key, list, frame);
|
|
1037
|
+
if (d.enter !== null) {
|
|
1038
|
+
await d.enter(node, ctx);
|
|
1039
|
+
if (ctx._stopped) return false;
|
|
1040
|
+
}
|
|
1041
|
+
if (typed !== void 0) for (const handler of typed.enter) {
|
|
1042
|
+
await handler(node, ctx);
|
|
1043
|
+
if (ctx._stopped) return false;
|
|
1044
|
+
}
|
|
1045
|
+
if (ctx._removed) {
|
|
1046
|
+
applyRemove(ctx, parent, key, list, frame);
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
if (ctx._replacement !== null) {
|
|
1050
|
+
node = applyReplace(ctx, parent, key, list, frame);
|
|
1051
|
+
typed = d.typed(node.type);
|
|
1052
|
+
}
|
|
1053
|
+
const skipped = ctx._skip;
|
|
1054
|
+
ctx._skip = false;
|
|
1055
|
+
if (!skipped) {
|
|
1056
|
+
const keys = CHILD_KEYS[node.type];
|
|
1057
|
+
if (keys !== void 0 && keys.length > 0) {
|
|
1058
|
+
ancestors.push(node);
|
|
1059
|
+
for (let k = 0; k < keys.length; k++) {
|
|
1060
|
+
const key2 = keys[k];
|
|
1061
|
+
const value = node[key2];
|
|
1062
|
+
if (value === null || value === void 0 || typeof value !== "object") continue;
|
|
1063
|
+
if (Array.isArray(value)) {
|
|
1064
|
+
const childFrame = { i: 0 };
|
|
1065
|
+
for (; childFrame.i < value.length; childFrame.i++) {
|
|
1066
|
+
const item = value[childFrame.i];
|
|
1067
|
+
if (item !== null && !await visit(item, key2, value, childFrame)) return false;
|
|
1068
|
+
}
|
|
1069
|
+
} else if (!await visit(value, key2, null, null)) return false;
|
|
1070
|
+
}
|
|
1071
|
+
ancestors.pop();
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
position(ctx, node, key, list, frame);
|
|
1075
|
+
if (typed !== void 0) for (const handler of typed.leave) {
|
|
1076
|
+
await handler(node, ctx);
|
|
1077
|
+
if (ctx._stopped) return false;
|
|
1078
|
+
}
|
|
1079
|
+
if (d.leave !== null) {
|
|
1080
|
+
await d.leave(node, ctx);
|
|
1081
|
+
if (ctx._stopped) return false;
|
|
1082
|
+
}
|
|
1083
|
+
if (ctx._removed) applyRemove(ctx, parent, key, list, frame);
|
|
1084
|
+
else if (ctx._replacement !== null) applyReplace(ctx, parent, key, list, frame);
|
|
1085
|
+
return true;
|
|
1086
|
+
})(root, null, null, null);
|
|
1087
|
+
}
|
|
1088
|
+
function nameOf(node) {
|
|
1089
|
+
if (node == null) return null;
|
|
1090
|
+
if (node.type === "Identifier") return node.name;
|
|
1091
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
//#endregion
|
|
1095
|
+
//#region ../../node_modules/.pnpm/dts-resolver@3.0.0_oxc-resolver@11.21.3/node_modules/dts-resolver/dist/index.mjs
|
|
1096
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
1097
|
+
function createResolver({ tsconfig, cwd = process.cwd(), resolveNodeModules = false, ResolverFactory } = {}) {
|
|
1098
|
+
ResolverFactory ||= __require("oxc-resolver").ResolverFactory;
|
|
1099
|
+
const resolver = new ResolverFactory({
|
|
1100
|
+
mainFields: [
|
|
1101
|
+
"types",
|
|
1102
|
+
"typings",
|
|
1103
|
+
"module",
|
|
1104
|
+
"main"
|
|
1105
|
+
],
|
|
1106
|
+
conditionNames: [
|
|
1107
|
+
"types",
|
|
1108
|
+
"typings",
|
|
1109
|
+
"import",
|
|
1110
|
+
"require"
|
|
1111
|
+
],
|
|
1112
|
+
extensions: [
|
|
1113
|
+
".d.ts",
|
|
1114
|
+
".d.mts",
|
|
1115
|
+
".d.cts",
|
|
1116
|
+
".ts",
|
|
1117
|
+
".mts",
|
|
1118
|
+
".cts",
|
|
1119
|
+
".tsx",
|
|
1120
|
+
".js",
|
|
1121
|
+
".mjs",
|
|
1122
|
+
".cjs",
|
|
1123
|
+
".jsx"
|
|
1124
|
+
],
|
|
1125
|
+
extensionAlias: {
|
|
1126
|
+
".js": [
|
|
1127
|
+
".d.ts",
|
|
1128
|
+
".ts",
|
|
1129
|
+
".tsx",
|
|
1130
|
+
".js",
|
|
1131
|
+
".jsx"
|
|
1132
|
+
],
|
|
1133
|
+
".jsx": [
|
|
1134
|
+
".d.ts",
|
|
1135
|
+
".ts",
|
|
1136
|
+
".tsx",
|
|
1137
|
+
".jsx",
|
|
1138
|
+
".js"
|
|
1139
|
+
],
|
|
1140
|
+
".mjs": [
|
|
1141
|
+
".d.mts",
|
|
1142
|
+
".mts",
|
|
1143
|
+
".mjs"
|
|
1144
|
+
],
|
|
1145
|
+
".cjs": [
|
|
1146
|
+
".d.cts",
|
|
1147
|
+
".cts",
|
|
1148
|
+
".cjs"
|
|
1149
|
+
],
|
|
1150
|
+
".ts": [
|
|
1151
|
+
".d.ts",
|
|
1152
|
+
".ts",
|
|
1153
|
+
".tsx",
|
|
1154
|
+
".js",
|
|
1155
|
+
".jsx"
|
|
1156
|
+
],
|
|
1157
|
+
".tsx": [
|
|
1158
|
+
".d.ts",
|
|
1159
|
+
".tsx",
|
|
1160
|
+
".ts",
|
|
1161
|
+
".js",
|
|
1162
|
+
".jsx"
|
|
1163
|
+
],
|
|
1164
|
+
".mts": [
|
|
1165
|
+
".d.mts",
|
|
1166
|
+
".mts",
|
|
1167
|
+
".mjs"
|
|
1168
|
+
],
|
|
1169
|
+
".cts": [
|
|
1170
|
+
".d.cts",
|
|
1171
|
+
".cts",
|
|
1172
|
+
".cjs"
|
|
1173
|
+
]
|
|
1174
|
+
},
|
|
1175
|
+
modules: resolveNodeModules ? ["node_modules", "node_modules/@types"] : [],
|
|
1176
|
+
tsconfig: tsconfig ? {
|
|
1177
|
+
configFile: tsconfig,
|
|
1178
|
+
references: "auto"
|
|
1179
|
+
} : void 0
|
|
1180
|
+
});
|
|
1181
|
+
return (id, importer) => {
|
|
1182
|
+
const directory = importer ? dirname(importer) : cwd;
|
|
1183
|
+
const resolution = resolver.sync(directory, id);
|
|
1184
|
+
if (!resolution.path) return null;
|
|
1185
|
+
const resolved = resolution.path;
|
|
1186
|
+
return ensureValue(resolved);
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
const ALLOW_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1190
|
+
".js",
|
|
1191
|
+
".cjs",
|
|
1192
|
+
".mjs",
|
|
1193
|
+
".jsx",
|
|
1194
|
+
".ts",
|
|
1195
|
+
".cts",
|
|
1196
|
+
".mts",
|
|
1197
|
+
".tsx",
|
|
1198
|
+
".json",
|
|
1199
|
+
".vue",
|
|
1200
|
+
".svelte",
|
|
1201
|
+
".astro"
|
|
1202
|
+
]);
|
|
1203
|
+
function ensureValue(value) {
|
|
1204
|
+
return value && ALLOW_EXTENSIONS.has(extname(value)) ? value.replaceAll("\\", "/") : null;
|
|
1205
|
+
}
|
|
1206
|
+
//#endregion
|
|
1207
|
+
//#region ../../node_modules/.pnpm/rolldown-plugin-dts@0.27.12_@typescript+native-preview@7.0.0-dev.20260605.1_oxc-resolve_d94a4da753642eee691447f5bf042e95/node_modules/rolldown-plugin-dts/dist/index.mjs
|
|
1208
|
+
function createDtsInputPlugin({ sideEffects }) {
|
|
1209
|
+
return {
|
|
1210
|
+
name: "rolldown-plugin-dts:dts-input",
|
|
1211
|
+
options: sideEffects === false ? (options) => {
|
|
1212
|
+
return {
|
|
1213
|
+
treeshake: options.treeshake === false ? false : {
|
|
1214
|
+
...options.treeshake === true ? {} : options.treeshake,
|
|
1215
|
+
moduleSideEffects: false
|
|
1216
|
+
},
|
|
1217
|
+
...options
|
|
1218
|
+
};
|
|
1219
|
+
} : void 0,
|
|
1220
|
+
outputOptions(options) {
|
|
1221
|
+
return {
|
|
1222
|
+
...options,
|
|
1223
|
+
entryFileNames(chunk) {
|
|
1224
|
+
const { entryFileNames } = options;
|
|
1225
|
+
if (entryFileNames) {
|
|
1226
|
+
const nameTemplate = resolveTemplateFn(entryFileNames, chunk);
|
|
1227
|
+
const renderedName = replaceTemplateName(nameTemplate, chunk.name);
|
|
1228
|
+
if (RE_DTS.test(renderedName)) return nameTemplate;
|
|
1229
|
+
const renderedNameWithD = replaceTemplateName(nameTemplate, `${chunk.name}.d`);
|
|
1230
|
+
if (RE_DTS.test(renderedNameWithD)) return renderedNameWithD;
|
|
1231
|
+
}
|
|
1232
|
+
if (RE_DTS.test(chunk.name)) return chunk.name;
|
|
1233
|
+
if (chunk.name.endsWith(".d")) return "[name].ts";
|
|
1234
|
+
return "[name].d.ts";
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
const require$1 = createRequire(import.meta.url);
|
|
1241
|
+
const debug$5 = createDebug("rolldown-plugin-dts:tsgo");
|
|
1242
|
+
function isTS70Installed() {
|
|
1243
|
+
try {
|
|
1244
|
+
const { versionMajorMinor } = require$1("typescript");
|
|
1245
|
+
return versionMajorMinor === "7.0";
|
|
1246
|
+
} catch {}
|
|
1247
|
+
return false;
|
|
1248
|
+
}
|
|
1249
|
+
const spawnAsync = (...args) => new Promise((resolve, reject) => {
|
|
1250
|
+
const child = spawn(...args);
|
|
1251
|
+
child.on("close", () => resolve());
|
|
1252
|
+
child.on("error", (error) => reject(error));
|
|
1253
|
+
});
|
|
1254
|
+
let tsgoPathCache;
|
|
1255
|
+
async function getTsgoPathFromNodeModules(logger) {
|
|
1256
|
+
if (tsgoPathCache) return tsgoPathCache;
|
|
1257
|
+
const pkgName = isTS70Installed() ? "typescript" : "@typescript/native-preview";
|
|
1258
|
+
const tsgoPkg = import.meta.resolve(`${pkgName}/package.json`);
|
|
1259
|
+
const { default: { version } } = await import(tsgoPkg, { with: { type: "json" } });
|
|
1260
|
+
logger.info(`Emit types with ${styleText("underline", `${pkgName}@${version}`)}`);
|
|
1261
|
+
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
|
|
1262
|
+
return tsgoPathCache = getExePath();
|
|
1263
|
+
}
|
|
1264
|
+
async function runTsgo(logger, rootDir, tsconfig, sourcemap, tsgoPath) {
|
|
1265
|
+
debug$5("[tsgo] rootDir", rootDir);
|
|
1266
|
+
let tsgo;
|
|
1267
|
+
if (tsgoPath) {
|
|
1268
|
+
tsgo = tsgoPath;
|
|
1269
|
+
debug$5("[tsgo] using custom path", tsgo);
|
|
1270
|
+
} else {
|
|
1271
|
+
tsgo = await getTsgoPathFromNodeModules(logger);
|
|
1272
|
+
debug$5("[tsgo] using tsgo from node_modules", tsgo);
|
|
1273
|
+
}
|
|
1274
|
+
const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
|
|
1275
|
+
debug$5("[tsgo] tsgoDist", tsgoDist);
|
|
1276
|
+
const args = [
|
|
1277
|
+
"--noEmit",
|
|
1278
|
+
"false",
|
|
1279
|
+
"--declaration",
|
|
1280
|
+
"--emitDeclarationOnly",
|
|
1281
|
+
"-p",
|
|
1282
|
+
tsconfig,
|
|
1283
|
+
"--outDir",
|
|
1284
|
+
tsgoDist,
|
|
1285
|
+
"--rootDir",
|
|
1286
|
+
rootDir,
|
|
1287
|
+
"--noCheck",
|
|
1288
|
+
...sourcemap ? ["--declarationMap"] : []
|
|
1289
|
+
];
|
|
1290
|
+
debug$5("[tsgo] args %o", args);
|
|
1291
|
+
await spawnAsync(tsgo, args, { stdio: "inherit" });
|
|
1292
|
+
return {
|
|
1293
|
+
path: tsgoDist,
|
|
1294
|
+
async dispose() {
|
|
1295
|
+
if (debug$5.enabled) debug$5("[tsgo] skip cleanup of tsgoDist", tsgoDist);
|
|
1296
|
+
else {
|
|
1297
|
+
debug$5("[tsgo] disposing tsgoDist", tsgoDist);
|
|
1298
|
+
await rm(tsgoDist, {
|
|
1299
|
+
recursive: true,
|
|
1300
|
+
force: true
|
|
1301
|
+
}).catch(() => {});
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
const debug$4 = createDebug("rolldown-plugin-dts:generate");
|
|
1307
|
+
const WORKER_URL = "./tsc-worker.mjs";
|
|
1308
|
+
const EMPTY_STUB = `export {}`;
|
|
1309
|
+
function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, volarContext, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }) {
|
|
1310
|
+
const entryIncludes = entry?.filter((p) => p[0] !== "!");
|
|
1311
|
+
const entryIgnores = entry?.filter((p) => p[0] === "!").map((p) => p.slice(1));
|
|
1312
|
+
const entryMatcher = entry ? (file) => entryIncludes.some((p) => path.matchesGlob(file, p)) && !entryIgnores.some((p) => path.matchesGlob(file, p)) : void 0;
|
|
1313
|
+
const dtsMap = /* @__PURE__ */ new Map();
|
|
1314
|
+
/**
|
|
1315
|
+
* A map of input id to output file name
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
*
|
|
1319
|
+
* inputAlias = new Map([
|
|
1320
|
+
* ['/absolute/path/to/src/source_file.ts', 'dist/foo/index'],
|
|
1321
|
+
* ])
|
|
1322
|
+
*/
|
|
1323
|
+
const inputAliasMap = /* @__PURE__ */ new Map();
|
|
1324
|
+
let tscWorker;
|
|
1325
|
+
let tscModule;
|
|
1326
|
+
let tscContext;
|
|
1327
|
+
let tsgoContext;
|
|
1328
|
+
const rootDir = tsconfig ? path.dirname(tsconfig) : cwd;
|
|
1329
|
+
return {
|
|
1330
|
+
name: "rolldown-plugin-dts:generate",
|
|
1331
|
+
async buildStart(options) {
|
|
1332
|
+
if (generator === "tsgo") tsgoContext = await runTsgo(logger, rootDir, tsconfig, sourcemap, tsgo.path);
|
|
1333
|
+
else if (generator === "tsc") if (parallel) tscWorker = createTscWorker();
|
|
1334
|
+
else {
|
|
1335
|
+
tscModule = await import("./tsc-zcbB6ZVY.js");
|
|
1336
|
+
if (newContext) tscContext = createContext();
|
|
1337
|
+
}
|
|
1338
|
+
if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
|
|
1339
|
+
debug$4("resolving input alias %s -> %s", name, id);
|
|
1340
|
+
let resolved = await this.resolve(id);
|
|
1341
|
+
if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
|
|
1342
|
+
const resolvedId = resolved?.id || id;
|
|
1343
|
+
debug$4("resolved input alias %s -> %s", id, resolvedId);
|
|
1344
|
+
inputAliasMap.set(resolvedId, name);
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
outputOptions(options) {
|
|
1348
|
+
return {
|
|
1349
|
+
...options,
|
|
1350
|
+
entryFileNames(chunk) {
|
|
1351
|
+
const { entryFileNames } = options;
|
|
1352
|
+
const nameTemplate = resolveTemplateFn(entryFileNames || "[name].js", chunk);
|
|
1353
|
+
if (chunk.name.endsWith(".d")) {
|
|
1354
|
+
if (RE_DTS.test(nameTemplate)) return replaceTemplateName(nameTemplate, chunk.name.slice(0, -2));
|
|
1355
|
+
if (RE_JS.test(nameTemplate)) return nameTemplate.replace(RE_JS, ".$1ts");
|
|
1356
|
+
}
|
|
1357
|
+
return nameTemplate;
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
},
|
|
1361
|
+
resolveId(id) {
|
|
1362
|
+
if (dtsMap.has(id)) {
|
|
1363
|
+
debug$4("resolve dts id %s", id);
|
|
1364
|
+
return { id };
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
transform: {
|
|
1368
|
+
order: "pre",
|
|
1369
|
+
filter: { id: {
|
|
1370
|
+
include: [
|
|
1371
|
+
RE_JS,
|
|
1372
|
+
RE_TS,
|
|
1373
|
+
RE_JSON,
|
|
1374
|
+
...volarContext.patterns
|
|
1375
|
+
],
|
|
1376
|
+
exclude: [
|
|
1377
|
+
RE_DTS,
|
|
1378
|
+
RE_NODE_MODULES,
|
|
1379
|
+
RE_ROLLDOWN_RUNTIME
|
|
1380
|
+
]
|
|
1381
|
+
} },
|
|
1382
|
+
handler(code, id) {
|
|
1383
|
+
const jsFile = RE_JS.test(id);
|
|
1384
|
+
if (!jsFile || emitJs) {
|
|
1385
|
+
const mod = this.getModuleInfo(id);
|
|
1386
|
+
const isEntry = entryMatcher ? entryMatcher(path.relative(cwd, id)) : !!mod?.isEntry;
|
|
1387
|
+
const dtsId = filename_to_dts(id, volarContext);
|
|
1388
|
+
dtsMap.set(dtsId, {
|
|
1389
|
+
code,
|
|
1390
|
+
id,
|
|
1391
|
+
isEntry,
|
|
1392
|
+
jsFile
|
|
1393
|
+
});
|
|
1394
|
+
debug$4("register dts source: %s", id);
|
|
1395
|
+
if (isEntry) {
|
|
1396
|
+
const name = inputAliasMap.get(id);
|
|
1397
|
+
this.emitFile({
|
|
1398
|
+
type: "chunk",
|
|
1399
|
+
id: dtsId,
|
|
1400
|
+
name: name ? `${name}.d` : void 0
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if (emitDtsOnly) {
|
|
1405
|
+
if (RE_JSON.test(id)) return "{}";
|
|
1406
|
+
return EMPTY_STUB;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
},
|
|
1410
|
+
load: {
|
|
1411
|
+
filter: { id: {
|
|
1412
|
+
include: [RE_DTS],
|
|
1413
|
+
exclude: [RE_NODE_MODULES]
|
|
1414
|
+
} },
|
|
1415
|
+
async handler(dtsId) {
|
|
1416
|
+
const module = dtsMap.get(dtsId);
|
|
1417
|
+
if (!module) return;
|
|
1418
|
+
const { code, id, jsFile } = module;
|
|
1419
|
+
if (jsFile && await access(dtsId).then(() => true).catch(() => false)) {
|
|
1420
|
+
debug$4("dts file already exists for %s, skipping generation", id);
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
let dtsCode;
|
|
1424
|
+
let map;
|
|
1425
|
+
debug$4("generate dts %s from %s", dtsId, id);
|
|
1426
|
+
if (generator === "tsgo") {
|
|
1427
|
+
if (volarContext.isVolarFile(id)) throw new Error(`tsgo does not support .${path.extname(id)} file.`);
|
|
1428
|
+
const dtsPath = path.resolve(tsgoContext.path, path.relative(path.resolve(rootDir), filename_to_dts(id, volarContext)));
|
|
1429
|
+
if (!existsSync(dtsPath)) {
|
|
1430
|
+
debug$4("[tsgo]", dtsPath, "is missing");
|
|
1431
|
+
throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
|
|
1432
|
+
}
|
|
1433
|
+
dtsCode = await readFile(dtsPath, "utf8");
|
|
1434
|
+
const mapPath = `${dtsPath}.map`;
|
|
1435
|
+
if (existsSync(mapPath)) {
|
|
1436
|
+
const mapRaw = await readFile(mapPath, "utf8");
|
|
1437
|
+
map = {
|
|
1438
|
+
...JSON.parse(mapRaw),
|
|
1439
|
+
sources: [id]
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
} else if (generator === "oxc" && !volarContext.isVolarFile(id)) {
|
|
1443
|
+
const result = isolatedDeclarationSync(id, code, oxc);
|
|
1444
|
+
if (result.errors.length) {
|
|
1445
|
+
const [error] = result.errors;
|
|
1446
|
+
return this.error({
|
|
1447
|
+
message: error.message,
|
|
1448
|
+
frame: error.codeframe || void 0
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
dtsCode = result.code;
|
|
1452
|
+
if (result.map) {
|
|
1453
|
+
map = result.map;
|
|
1454
|
+
map.sourcesContent = void 0;
|
|
1455
|
+
}
|
|
1456
|
+
} else {
|
|
1457
|
+
const options = {
|
|
1458
|
+
tsconfig,
|
|
1459
|
+
tsconfigRaw,
|
|
1460
|
+
build,
|
|
1461
|
+
incremental,
|
|
1462
|
+
cwd,
|
|
1463
|
+
entries: eager ? void 0 : Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id),
|
|
1464
|
+
id,
|
|
1465
|
+
sourcemap,
|
|
1466
|
+
volarContext,
|
|
1467
|
+
context: tscContext
|
|
1468
|
+
};
|
|
1469
|
+
let result;
|
|
1470
|
+
if (parallel) result = await tscWorker.emit(options);
|
|
1471
|
+
else result = tscModule.tscEmit(options);
|
|
1472
|
+
if (result.error) return this.error(result.error);
|
|
1473
|
+
dtsCode = result.code;
|
|
1474
|
+
map = result.map;
|
|
1475
|
+
if (dtsCode && RE_JSON.test(id)) if (dtsCode.includes("declare const _exports")) {
|
|
1476
|
+
if (dtsCode.includes("declare const _exports: {") && !dtsCode.includes("\n}[];")) {
|
|
1477
|
+
const exports = collectJsonExports(dtsCode);
|
|
1478
|
+
let i = 0;
|
|
1479
|
+
dtsCode += exports.map((e) => {
|
|
1480
|
+
const valid = `_${e.replaceAll(/[^\w$]/g, "_")}${i++}`;
|
|
1481
|
+
const jsonKey = JSON.stringify(e);
|
|
1482
|
+
return `declare let ${valid}: typeof _exports[${jsonKey}]\nexport { ${valid} as ${jsonKey} }`;
|
|
1483
|
+
}).join("\n");
|
|
1484
|
+
}
|
|
1485
|
+
} else {
|
|
1486
|
+
const exportMap = collectJsonExportMap(dtsCode);
|
|
1487
|
+
dtsCode += `
|
|
1488
|
+
declare namespace __json_default_export {
|
|
1489
|
+
export { ${Array.from(exportMap.entries()).map(([exported, local]) => exported === local ? exported : `${local} as ${exported}`).join(", ")} }
|
|
1490
|
+
}
|
|
1491
|
+
export { __json_default_export as default }`;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return {
|
|
1495
|
+
code: dtsCode || "",
|
|
1496
|
+
map
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
generateBundle: emitDtsOnly ? (options, bundle) => {
|
|
1501
|
+
for (const fileName of Object.keys(bundle)) if (bundle[fileName].type === "chunk" && !RE_DTS.test(fileName) && !RE_DTS_MAP.test(fileName)) delete bundle[fileName];
|
|
1502
|
+
} : void 0,
|
|
1503
|
+
async buildEnd() {
|
|
1504
|
+
tscWorker?.kill();
|
|
1505
|
+
tscWorker = void 0;
|
|
1506
|
+
await tsgoContext?.dispose();
|
|
1507
|
+
tsgoContext = void 0;
|
|
1508
|
+
if (newContext) tscContext = void 0;
|
|
1509
|
+
},
|
|
1510
|
+
watchChange(id) {
|
|
1511
|
+
if (tscModule) invalidateContextFile(tscContext || globalContext, id);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
function createTscWorker() {
|
|
1516
|
+
const childProcess = fork(new URL(WORKER_URL, import.meta.url), {
|
|
1517
|
+
stdio: "inherit",
|
|
1518
|
+
serialization: "advanced"
|
|
1519
|
+
});
|
|
1520
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1521
|
+
let nextId = 0;
|
|
1522
|
+
childProcess.on("message", (response) => {
|
|
1523
|
+
const handler = pending.get(response.id);
|
|
1524
|
+
if (!handler) return;
|
|
1525
|
+
pending.delete(response.id);
|
|
1526
|
+
if (response.error) handler.reject(response.error);
|
|
1527
|
+
else handler.resolve(response.result);
|
|
1528
|
+
});
|
|
1529
|
+
childProcess.on("exit", (code) => {
|
|
1530
|
+
for (const handler of pending.values()) handler.reject(/* @__PURE__ */ new Error(`tsc worker exited with code ${code}`));
|
|
1531
|
+
pending.clear();
|
|
1532
|
+
});
|
|
1533
|
+
return {
|
|
1534
|
+
emit: (options) => new Promise((resolve, reject) => {
|
|
1535
|
+
const id = nextId++;
|
|
1536
|
+
pending.set(id, {
|
|
1537
|
+
resolve,
|
|
1538
|
+
reject
|
|
1539
|
+
});
|
|
1540
|
+
childProcess.send({
|
|
1541
|
+
id,
|
|
1542
|
+
options
|
|
1543
|
+
});
|
|
1544
|
+
}),
|
|
1545
|
+
kill: () => childProcess.kill()
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
function collectJsonExportMap(code) {
|
|
1549
|
+
const exportMap = /* @__PURE__ */ new Map();
|
|
1550
|
+
const { program } = parse$1(code, {
|
|
1551
|
+
sourceType: "module",
|
|
1552
|
+
lang: "dts"
|
|
1553
|
+
});
|
|
1554
|
+
for (const decl of program.body) if (decl.type === "ExportNamedDeclaration") {
|
|
1555
|
+
if (decl.declaration) {
|
|
1556
|
+
if (decl.declaration.type === "VariableDeclaration") {
|
|
1557
|
+
for (const vdecl of decl.declaration.declarations) if (vdecl.id.type === "Identifier") exportMap.set(vdecl.id.name, vdecl.id.name);
|
|
1558
|
+
} else if (decl.declaration.type === "TSModuleDeclaration" && decl.declaration.id.type === "Identifier") exportMap.set(decl.declaration.id.name, decl.declaration.id.name);
|
|
1559
|
+
} else if (decl.specifiers.length) {
|
|
1560
|
+
for (const spec of decl.specifiers) if (spec.type === "ExportSpecifier" && spec.exported.type === "Identifier") exportMap.set(spec.exported.name, spec.local.type === "Identifier" ? spec.local.name : spec.exported.name);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
return exportMap;
|
|
1564
|
+
}
|
|
1565
|
+
/** `declare const _exports` mode */
|
|
1566
|
+
function collectJsonExports(code) {
|
|
1567
|
+
const exports = [];
|
|
1568
|
+
const { program } = parse$1(code, {
|
|
1569
|
+
sourceType: "module",
|
|
1570
|
+
lang: "dts"
|
|
1571
|
+
});
|
|
1572
|
+
const members = program.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;
|
|
1573
|
+
for (const member of members) if (member.key.type === "Identifier") exports.push(member.key.name);
|
|
1574
|
+
else if (is.StringLiteral(member.key)) exports.push(member.key.value);
|
|
1575
|
+
return exports;
|
|
1576
|
+
}
|
|
1577
|
+
function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
1578
|
+
let declarationIdx = 0;
|
|
1579
|
+
const declarationMap = /* @__PURE__ */ new Map();
|
|
1580
|
+
const commentsMap = /* @__PURE__ */ new Map();
|
|
1581
|
+
const moduleExportsMap = /* @__PURE__ */ new Map();
|
|
1582
|
+
const warnedCjsDtsInputs = /* @__PURE__ */ new Set();
|
|
1583
|
+
return {
|
|
1584
|
+
name: "rolldown-plugin-dts:fake-js",
|
|
1585
|
+
outputOptions(options) {
|
|
1586
|
+
if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
|
|
1587
|
+
const { chunkFileNames, entryFileNames } = options;
|
|
1588
|
+
return {
|
|
1589
|
+
...options,
|
|
1590
|
+
sourcemap: options.sourcemap || sourcemap,
|
|
1591
|
+
chunkFileNames(chunk) {
|
|
1592
|
+
const nameTemplate = resolveTemplateFn(chunk.isEntry ? entryFileNames || "[name].js" : chunkFileNames || "[name]-[hash].js", chunk);
|
|
1593
|
+
if (chunk.name.endsWith(".d")) {
|
|
1594
|
+
const renderedNameWithoutD = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name.slice(0, -2)));
|
|
1595
|
+
if (RE_DTS.test(renderedNameWithoutD)) return renderedNameWithoutD;
|
|
1596
|
+
const renderedName = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name));
|
|
1597
|
+
if (RE_DTS.test(renderedName)) return renderedName;
|
|
1598
|
+
}
|
|
1599
|
+
return nameTemplate;
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
},
|
|
1603
|
+
transform: {
|
|
1604
|
+
filter: { id: RE_DTS },
|
|
1605
|
+
handler: transform
|
|
1606
|
+
},
|
|
1607
|
+
renderChunk,
|
|
1608
|
+
generateBundle(options, bundle) {
|
|
1609
|
+
for (const chunk of Object.values(bundle)) {
|
|
1610
|
+
if (!RE_DTS_MAP.test(chunk.fileName)) continue;
|
|
1611
|
+
if (sourcemap) {
|
|
1612
|
+
if (chunk.type === "chunk" || typeof chunk.source !== "string") continue;
|
|
1613
|
+
const map = JSON.parse(chunk.source);
|
|
1614
|
+
map.sourcesContent = void 0;
|
|
1615
|
+
chunk.source = JSON.stringify(map);
|
|
1616
|
+
} else delete bundle[chunk.fileName];
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
async function transform(code, id) {
|
|
1621
|
+
let file;
|
|
1622
|
+
try {
|
|
1623
|
+
file = parse$1(code, {
|
|
1624
|
+
lang: "dts",
|
|
1625
|
+
sourceType: "module",
|
|
1626
|
+
attachComments: true
|
|
1627
|
+
});
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
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 });
|
|
1630
|
+
}
|
|
1631
|
+
const { program } = file;
|
|
1632
|
+
moduleExportsMap.set(id, await collectModuleExports(this, program.body, id));
|
|
1633
|
+
const identifierMap = Object.create(null);
|
|
1634
|
+
if (!warnedCjsDtsInputs.has(id) && program.body.some(isCjsDtsInputSyntax)) {
|
|
1635
|
+
warnedCjsDtsInputs.add(id);
|
|
1636
|
+
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.`}`);
|
|
1637
|
+
}
|
|
1638
|
+
const directives = collectReferenceDirectives(file.comments);
|
|
1639
|
+
if (directives.length) commentsMap.set(id, directives);
|
|
1640
|
+
const appendStmts = [];
|
|
1641
|
+
const namespaceStmts = /* @__PURE__ */ new Map();
|
|
1642
|
+
for (const [i, stmt] of program.body.entries()) {
|
|
1643
|
+
const setStmt = (stmt) => program.body[i] = stmt;
|
|
1644
|
+
if (rewriteImportExport(stmt, setStmt)) continue;
|
|
1645
|
+
const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
|
|
1646
|
+
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}.`);
|
|
1647
|
+
const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
|
|
1648
|
+
const isExportDecl = is.oneOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && !!stmt.declaration;
|
|
1649
|
+
const decl = isExportDecl ? stmt.declaration : stmt;
|
|
1650
|
+
const setDecl = isExportDecl ? (decl) => stmt.declaration = decl : setStmt;
|
|
1651
|
+
if (decl.type !== "TSDeclareFunction" && !is.Declaration(decl)) continue;
|
|
1652
|
+
if (is.oneOf(decl, [
|
|
1653
|
+
"TSEnumDeclaration",
|
|
1654
|
+
"ClassDeclaration",
|
|
1655
|
+
"FunctionDeclaration",
|
|
1656
|
+
"TSDeclareFunction",
|
|
1657
|
+
"TSModuleDeclaration",
|
|
1658
|
+
"VariableDeclaration"
|
|
1659
|
+
])) decl.declare = true;
|
|
1660
|
+
const bindings = [];
|
|
1661
|
+
if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl) => decl.id));
|
|
1662
|
+
else if ("id" in decl && decl.id) {
|
|
1663
|
+
let binding = decl.id;
|
|
1664
|
+
if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
|
|
1665
|
+
if (sideEffect) binding = b.Identifier({ name: `_${getIdentifierIndex(identifierMap, "")}` });
|
|
1666
|
+
if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
|
|
1667
|
+
bindings.push(binding);
|
|
1668
|
+
} else {
|
|
1669
|
+
const binding = b.Identifier({ name: "export_default" });
|
|
1670
|
+
bindings.push(binding);
|
|
1671
|
+
decl.id = binding;
|
|
1672
|
+
}
|
|
1673
|
+
const params = collectParams(decl);
|
|
1674
|
+
const childrenSet = /* @__PURE__ */ new Set();
|
|
1675
|
+
const deps = await collectDependencies(this, decl, id, namespaceStmts, childrenSet, identifierMap);
|
|
1676
|
+
const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
|
|
1677
|
+
if (decl !== stmt) decl.comments = stmt.comments;
|
|
1678
|
+
const declarationId = registerDeclaration({
|
|
1679
|
+
decl,
|
|
1680
|
+
deps,
|
|
1681
|
+
bindings,
|
|
1682
|
+
params,
|
|
1683
|
+
children
|
|
1684
|
+
});
|
|
1685
|
+
const declarationIdNode = b.Literal({
|
|
1686
|
+
value: declarationId,
|
|
1687
|
+
raw: String(declarationId)
|
|
1688
|
+
});
|
|
1689
|
+
const depsBody = b.ArrayExpression({ elements: deps });
|
|
1690
|
+
const depsNode = b.ArrowFunctionExpression({
|
|
1691
|
+
id: null,
|
|
1692
|
+
generator: false,
|
|
1693
|
+
async: false,
|
|
1694
|
+
params: params.map(({ name }) => b.Identifier({ name })),
|
|
1695
|
+
body: depsBody,
|
|
1696
|
+
expression: true
|
|
1697
|
+
});
|
|
1698
|
+
const childrenNode = b.ArrayExpression({ elements: children.map((node) => b.Literal({
|
|
1699
|
+
value: "",
|
|
1700
|
+
raw: "\"\"",
|
|
1701
|
+
start: node.start,
|
|
1702
|
+
end: node.end
|
|
1703
|
+
})) });
|
|
1704
|
+
const sideEffectNode = sideEffect && b.CallExpression({
|
|
1705
|
+
callee: b.Identifier({ name: "sideEffect" }),
|
|
1706
|
+
arguments: [bindings[0]],
|
|
1707
|
+
optional: false
|
|
1708
|
+
});
|
|
1709
|
+
const runtimeArrayNode = runtimeBindingArrayExpression([
|
|
1710
|
+
declarationIdNode,
|
|
1711
|
+
depsNode,
|
|
1712
|
+
childrenNode,
|
|
1713
|
+
...sideEffectNode ? [sideEffectNode] : []
|
|
1714
|
+
]);
|
|
1715
|
+
const runtimeAssignment = b.VariableDeclaration({
|
|
1716
|
+
kind: "var",
|
|
1717
|
+
declarations: [b.VariableDeclarator({
|
|
1718
|
+
id: b.ArrayPattern({ elements: bindings.map((binding) => ({
|
|
1719
|
+
...binding,
|
|
1720
|
+
typeAnnotation: null
|
|
1721
|
+
})) }),
|
|
1722
|
+
init: runtimeArrayNode
|
|
1723
|
+
})]
|
|
1724
|
+
});
|
|
1725
|
+
if (isDefaultExport) {
|
|
1726
|
+
appendStmts.push(b.ExportNamedDeclaration({
|
|
1727
|
+
declaration: null,
|
|
1728
|
+
specifiers: [b.ExportSpecifier({
|
|
1729
|
+
local: bindings[0],
|
|
1730
|
+
exported: b.Identifier({ name: "default" })
|
|
1731
|
+
})],
|
|
1732
|
+
source: null,
|
|
1733
|
+
attributes: []
|
|
1734
|
+
}));
|
|
1735
|
+
setStmt(runtimeAssignment);
|
|
1736
|
+
} else setDecl(runtimeAssignment);
|
|
1737
|
+
}
|
|
1738
|
+
if (sideEffects) appendStmts.push(b.ExpressionStatement({ expression: b.CallExpression({
|
|
1739
|
+
callee: b.Identifier({ name: "sideEffect" }),
|
|
1740
|
+
arguments: [],
|
|
1741
|
+
optional: false
|
|
1742
|
+
}) }));
|
|
1743
|
+
program.body = [
|
|
1744
|
+
...Array.from(namespaceStmts.values()).map(({ stmt }) => stmt),
|
|
1745
|
+
...program.body,
|
|
1746
|
+
...appendStmts
|
|
1747
|
+
];
|
|
1748
|
+
const result = print(program, {
|
|
1749
|
+
comments: false,
|
|
1750
|
+
...sourcemap && { sourceMaps: {
|
|
1751
|
+
source: code,
|
|
1752
|
+
sourceFileName: id
|
|
1753
|
+
} }
|
|
1754
|
+
});
|
|
1755
|
+
return {
|
|
1756
|
+
code: result.code,
|
|
1757
|
+
map: result.map ?? null
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
function renderChunk(code, chunk) {
|
|
1761
|
+
if (!RE_DTS.test(chunk.fileName)) return;
|
|
1762
|
+
const exportInfo = collectChunkExportInfo(chunk, moduleExportsMap);
|
|
1763
|
+
let file;
|
|
1764
|
+
try {
|
|
1765
|
+
file = parse$1(code, {
|
|
1766
|
+
lang: "ts",
|
|
1767
|
+
sourceType: "module",
|
|
1768
|
+
attachComments: true
|
|
1769
|
+
});
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
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 });
|
|
1772
|
+
}
|
|
1773
|
+
const { program } = file;
|
|
1774
|
+
program.body = patchTsNamespace(program.body);
|
|
1775
|
+
program.body = patchReExport(program.body);
|
|
1776
|
+
program.body = program.body.map((node) => {
|
|
1777
|
+
if (isHelperImport(node)) return null;
|
|
1778
|
+
if (node.type === "ExpressionStatement") return null;
|
|
1779
|
+
const newNode = patchImportExport(node, exportInfo, cjsDefault);
|
|
1780
|
+
if (newNode || newNode === false) return newNode;
|
|
1781
|
+
if (node.type !== "VariableDeclaration") return node;
|
|
1782
|
+
if (!isRuntimeBindingVariableDeclaration(node)) return null;
|
|
1783
|
+
const decl = node.declarations[0];
|
|
1784
|
+
const [declarationIdNode, depsFn, children] = decl.init.elements;
|
|
1785
|
+
const declarationId = declarationIdNode.value;
|
|
1786
|
+
const declaration = getDeclaration(declarationId);
|
|
1787
|
+
if (sourcemap) walk(declaration.decl, { enter(node) {
|
|
1788
|
+
node.start = void 0;
|
|
1789
|
+
node.end = void 0;
|
|
1790
|
+
} });
|
|
1791
|
+
for (const [i, id] of decl.id.elements.entries()) {
|
|
1792
|
+
const transformedBinding = {
|
|
1793
|
+
...id,
|
|
1794
|
+
typeAnnotation: declaration.bindings[i].typeAnnotation
|
|
1795
|
+
};
|
|
1796
|
+
overwriteNode(declaration.bindings[i], transformedBinding);
|
|
1797
|
+
}
|
|
1798
|
+
if (sourcemap) for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], {
|
|
1799
|
+
start: child.start,
|
|
1800
|
+
end: child.end
|
|
1801
|
+
});
|
|
1802
|
+
const transformedParams = depsFn.params;
|
|
1803
|
+
for (const [i, transformedParam] of transformedParams.entries()) {
|
|
1804
|
+
const transformedName = transformedParam.name;
|
|
1805
|
+
for (const originalTypeParam of declaration.params[i].typeParams) originalTypeParam.name = transformedName;
|
|
1806
|
+
}
|
|
1807
|
+
const transformedDeps = depsFn.body.elements;
|
|
1808
|
+
for (const [i, originalDep] of declaration.deps.entries()) {
|
|
1809
|
+
let transformedDep = transformedDeps[i];
|
|
1810
|
+
if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void") {
|
|
1811
|
+
const undefinedDep = b.Identifier({ name: "undefined" });
|
|
1812
|
+
undefinedDep.start = transformedDep.start;
|
|
1813
|
+
undefinedDep.end = transformedDep.end;
|
|
1814
|
+
transformedDep = undefinedDep;
|
|
1815
|
+
} else if (isInfer(transformedDep)) transformedDep.name = "__Infer";
|
|
1816
|
+
if (originalDep.replace) originalDep.replace(transformedDep);
|
|
1817
|
+
else Object.assign(originalDep, transformedDep);
|
|
1818
|
+
}
|
|
1819
|
+
return inheritNodeComments(node, declaration.decl);
|
|
1820
|
+
}).filter((node) => !!node);
|
|
1821
|
+
if (program.body.length === 0) return {
|
|
1822
|
+
code: EMPTY_STUB,
|
|
1823
|
+
map: null
|
|
1824
|
+
};
|
|
1825
|
+
const comments = /* @__PURE__ */ new Set();
|
|
1826
|
+
const commentsValue = /* @__PURE__ */ new Set();
|
|
1827
|
+
for (const id of chunk.moduleIds) {
|
|
1828
|
+
const preserveComments = commentsMap.get(id);
|
|
1829
|
+
if (preserveComments) {
|
|
1830
|
+
preserveComments.forEach((c) => {
|
|
1831
|
+
const id = c.type + c.value;
|
|
1832
|
+
if (commentsValue.has(id)) return;
|
|
1833
|
+
commentsValue.add(id);
|
|
1834
|
+
comments.add(c);
|
|
1835
|
+
});
|
|
1836
|
+
commentsMap.delete(id);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
if (comments.size) {
|
|
1840
|
+
program.body[0].comments ||= [];
|
|
1841
|
+
program.body[0].comments.unshift(...Array.from(comments, (c) => ({
|
|
1842
|
+
type: c.type,
|
|
1843
|
+
value: c.value,
|
|
1844
|
+
position: "before",
|
|
1845
|
+
sameLine: false
|
|
1846
|
+
})));
|
|
1847
|
+
}
|
|
1848
|
+
const result = print(program, {
|
|
1849
|
+
comments: true,
|
|
1850
|
+
...sourcemap && { sourceMaps: {
|
|
1851
|
+
source: code,
|
|
1852
|
+
sourceFileName: chunk.fileName
|
|
1853
|
+
} }
|
|
1854
|
+
});
|
|
1855
|
+
return {
|
|
1856
|
+
code: result.code,
|
|
1857
|
+
map: result.map ?? null
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function registerDeclaration(info) {
|
|
1861
|
+
const declarationId = declarationIdx++;
|
|
1862
|
+
declarationMap.set(declarationId, info);
|
|
1863
|
+
return declarationId;
|
|
1864
|
+
}
|
|
1865
|
+
function getDeclaration(declarationId) {
|
|
1866
|
+
return declarationMap.get(declarationId);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
async function collectModuleExports(context, nodes, id) {
|
|
1870
|
+
const info = {
|
|
1871
|
+
typeOnlyLocals: /* @__PURE__ */ new Set(),
|
|
1872
|
+
exports: /* @__PURE__ */ new Map(),
|
|
1873
|
+
reExports: [],
|
|
1874
|
+
exportAlls: []
|
|
1875
|
+
};
|
|
1876
|
+
for (const node of nodes) collectTypeOnlyLocals(node, info.typeOnlyLocals);
|
|
1877
|
+
for (const node of nodes) await collectExportInfo(context, node, id, info);
|
|
1878
|
+
return info;
|
|
1879
|
+
}
|
|
1880
|
+
function collectTypeOnlyLocals(node, typeOnlyLocals) {
|
|
1881
|
+
if (node.type !== "ImportDeclaration") return;
|
|
1882
|
+
for (const specifier of node.specifiers) if (node.importKind === "type" || "importKind" in specifier && specifier.importKind === "type") typeOnlyLocals.add(specifier.local.name);
|
|
1883
|
+
}
|
|
1884
|
+
function collectDeclarationNames(node) {
|
|
1885
|
+
if (node.type === "VariableDeclaration") return node.declarations.flatMap((decl) => collectPatternNames(decl.id));
|
|
1886
|
+
if ("id" in node && node.id) {
|
|
1887
|
+
if (node.id.type !== "Identifier" && node.id.type !== "TSQualifiedName") return [];
|
|
1888
|
+
const id = getIdFromTSEntityName(node.id);
|
|
1889
|
+
return id.type === "Identifier" ? [id.name] : [];
|
|
1890
|
+
}
|
|
1891
|
+
return [];
|
|
1892
|
+
}
|
|
1893
|
+
function collectPatternNames(node) {
|
|
1894
|
+
if (!node) return [];
|
|
1895
|
+
if (node.type === "Identifier") return [node.name];
|
|
1896
|
+
if (node.type === "RestElement") return collectPatternNames(node.argument);
|
|
1897
|
+
if (node.type === "AssignmentPattern") return collectPatternNames(node.left);
|
|
1898
|
+
if (node.type === "ArrayPattern") return node.elements.flatMap((element) => collectPatternNames(element));
|
|
1899
|
+
if (node.type === "ObjectPattern") return node.properties.flatMap((property) => {
|
|
1900
|
+
if (property.type === "RestElement") return collectPatternNames(property.argument);
|
|
1901
|
+
return collectPatternNames(property.value);
|
|
1902
|
+
});
|
|
1903
|
+
return [];
|
|
1904
|
+
}
|
|
1905
|
+
function isTypeOnlyExport(node, specifier) {
|
|
1906
|
+
return node.exportKind === "type" || specifier.exportKind === "type";
|
|
1907
|
+
}
|
|
1908
|
+
async function collectExportInfo(context, node, id, info) {
|
|
1909
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
1910
|
+
if (node.declaration) {
|
|
1911
|
+
for (const name of collectDeclarationNames(node.declaration)) info.exports.set(name, false);
|
|
1912
|
+
return;
|
|
1913
|
+
}
|
|
1914
|
+
const source = await resolveExportSource(context, node.source, id);
|
|
1915
|
+
for (const specifier of node.specifiers) {
|
|
1916
|
+
const typeOnly = isTypeOnlyExport(node, specifier);
|
|
1917
|
+
const exported = nameOf(specifier.exported);
|
|
1918
|
+
const local = nameOf(specifier.local);
|
|
1919
|
+
if (source) info.reExports.push({
|
|
1920
|
+
source,
|
|
1921
|
+
local,
|
|
1922
|
+
exported,
|
|
1923
|
+
typeOnly
|
|
1924
|
+
});
|
|
1925
|
+
else info.exports.set(exported, typeOnly || info.typeOnlyLocals.has(local));
|
|
1926
|
+
}
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
1930
|
+
info.exports.set("default", false);
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
if (node.type === "ExportAllDeclaration") {
|
|
1934
|
+
if (node.exported) {
|
|
1935
|
+
info.exports.set(nameOf(node.exported), node.exportKind === "type");
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
info.exportAlls.push({
|
|
1939
|
+
source: await resolveExportSource(context, node.source, id),
|
|
1940
|
+
rawSource: node.source.value,
|
|
1941
|
+
typeOnly: node.exportKind === "type"
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
async function resolveExportSource(context, source, importer) {
|
|
1946
|
+
if (!source) return;
|
|
1947
|
+
const resolved = await context.resolve(source.value, importer);
|
|
1948
|
+
if (!resolved || resolved.external) return;
|
|
1949
|
+
return resolved.id;
|
|
1950
|
+
}
|
|
1951
|
+
function collectChunkExportInfo(chunk, moduleExportsMap) {
|
|
1952
|
+
const exportsByModule = resolveAllModuleExports(moduleExportsMap);
|
|
1953
|
+
const roots = chunk.facadeModuleId && moduleExportsMap.has(chunk.facadeModuleId) ? [chunk.facadeModuleId] : chunk.moduleIds;
|
|
1954
|
+
const mergedExports = /* @__PURE__ */ new Map();
|
|
1955
|
+
const typeOnlyExportAllSources = /* @__PURE__ */ new Set();
|
|
1956
|
+
for (const root of roots) {
|
|
1957
|
+
const exports = exportsByModule.get(root);
|
|
1958
|
+
if (exports) for (const [name, typeOnly] of exports) setExportTypeOnly(mergedExports, name, typeOnly);
|
|
1959
|
+
const moduleExports = moduleExportsMap.get(root);
|
|
1960
|
+
if (!moduleExports) continue;
|
|
1961
|
+
for (const exportAll of moduleExports.exportAlls) {
|
|
1962
|
+
if (!exportAll.typeOnly || exportAll.source) continue;
|
|
1963
|
+
typeOnlyExportAllSources.add(exportAll.rawSource);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
const typeOnlyNames = /* @__PURE__ */ new Set();
|
|
1967
|
+
for (const [name, typeOnly] of mergedExports) if (typeOnly) typeOnlyNames.add(name);
|
|
1968
|
+
return {
|
|
1969
|
+
typeOnlyNames,
|
|
1970
|
+
typeOnlyExportAllSources
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
function resolveAllModuleExports(moduleExportsMap) {
|
|
1974
|
+
const exportsByModule = /* @__PURE__ */ new Map();
|
|
1975
|
+
for (const [id, info] of moduleExportsMap) exportsByModule.set(id, new Map(info.exports));
|
|
1976
|
+
let changed = true;
|
|
1977
|
+
while (changed) {
|
|
1978
|
+
changed = false;
|
|
1979
|
+
for (const [id, info] of moduleExportsMap) {
|
|
1980
|
+
const exports = exportsByModule.get(id);
|
|
1981
|
+
for (const reExport of info.reExports) {
|
|
1982
|
+
const sourceTypeOnly = (reExport.source ? exportsByModule.get(reExport.source) : void 0)?.get(reExport.local) ?? false;
|
|
1983
|
+
if (setExportTypeOnly(exports, reExport.exported, reExport.typeOnly || sourceTypeOnly)) changed = true;
|
|
1984
|
+
}
|
|
1985
|
+
for (const exportAll of info.exportAlls) {
|
|
1986
|
+
if (!exportAll.source) continue;
|
|
1987
|
+
const sourceExports = exportsByModule.get(exportAll.source);
|
|
1988
|
+
if (!sourceExports) continue;
|
|
1989
|
+
for (const [name, typeOnly] of sourceExports) {
|
|
1990
|
+
if (name === "default") continue;
|
|
1991
|
+
if (setExportTypeOnly(exports, name, exportAll.typeOnly || typeOnly)) changed = true;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
return exportsByModule;
|
|
1997
|
+
}
|
|
1998
|
+
function setExportTypeOnly(exports, name, typeOnly) {
|
|
1999
|
+
const current = exports.get(name);
|
|
2000
|
+
if (current === false || current === typeOnly) return false;
|
|
2001
|
+
if (current === void 0 || !typeOnly) {
|
|
2002
|
+
exports.set(name, typeOnly);
|
|
2003
|
+
return true;
|
|
2004
|
+
}
|
|
2005
|
+
return false;
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Collects all TSTypeParameter nodes from the given node and groups them by
|
|
2009
|
+
* their name. One name can associate with one or more type parameters. These
|
|
2010
|
+
* names will be used as the parameter name in the generated JavaScript
|
|
2011
|
+
* dependency function.
|
|
2012
|
+
*/
|
|
2013
|
+
function collectParams(node) {
|
|
2014
|
+
const typeParams = [];
|
|
2015
|
+
walk(node, { leave(node) {
|
|
2016
|
+
if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => name));
|
|
2017
|
+
} });
|
|
2018
|
+
const paramMap = /* @__PURE__ */ new Map();
|
|
2019
|
+
for (const typeParam of typeParams) {
|
|
2020
|
+
const name = typeParam.name;
|
|
2021
|
+
const group = paramMap.get(name);
|
|
2022
|
+
if (group) group.push(typeParam);
|
|
2023
|
+
else paramMap.set(name, [typeParam]);
|
|
2024
|
+
}
|
|
2025
|
+
return Array.from(paramMap.entries()).map(([name, typeParams]) => ({
|
|
2026
|
+
name,
|
|
2027
|
+
typeParams
|
|
2028
|
+
}));
|
|
2029
|
+
}
|
|
2030
|
+
async function collectDependencies(context, node, importer, namespaceStmts, children, identifierMap) {
|
|
2031
|
+
const deps = /* @__PURE__ */ new Set();
|
|
2032
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2033
|
+
const preserveImportTypeCache = /* @__PURE__ */ new Map();
|
|
2034
|
+
const inferredStack = [];
|
|
2035
|
+
let currentInferred = /* @__PURE__ */ new Set();
|
|
2036
|
+
function isInferred(node) {
|
|
2037
|
+
return node.type === "Identifier" && currentInferred.has(node.name);
|
|
2038
|
+
}
|
|
2039
|
+
await walkAsync(node, {
|
|
2040
|
+
enter(node) {
|
|
2041
|
+
if (node.type === "TSConditionalType") {
|
|
2042
|
+
const inferred = collectInferredNames(node.extendsType);
|
|
2043
|
+
inferredStack.push(inferred);
|
|
2044
|
+
}
|
|
2045
|
+
},
|
|
2046
|
+
async leave(node, path) {
|
|
2047
|
+
const { parent } = path;
|
|
2048
|
+
if (node.type === "TSConditionalType") inferredStack.pop();
|
|
2049
|
+
else if (parent?.type === "TSConditionalType") {
|
|
2050
|
+
const trueBranch = parent.trueType === node;
|
|
2051
|
+
currentInferred = new Set((trueBranch ? inferredStack : inferredStack.slice(0, -1)).flat());
|
|
2052
|
+
} else currentInferred = /* @__PURE__ */ new Set();
|
|
2053
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
2054
|
+
for (const specifier of node.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
|
|
2055
|
+
} else if (node.type === "TSInterfaceDeclaration" && node.extends) for (const heritage of node.extends || []) addDependency(heritage.expression);
|
|
2056
|
+
else if (node.type === "ClassDeclaration") {
|
|
2057
|
+
if (node.superClass) addDependency(node.superClass);
|
|
2058
|
+
if (node.implements) for (const implement of node.implements) addDependency(implement.expression);
|
|
2059
|
+
} else if (is.oneOf(node, [
|
|
2060
|
+
"Property",
|
|
2061
|
+
"PropertyDefinition",
|
|
2062
|
+
"TSAbstractPropertyDefinition",
|
|
2063
|
+
"MethodDefinition",
|
|
2064
|
+
"TSAbstractMethodDefinition",
|
|
2065
|
+
"TSPropertySignature",
|
|
2066
|
+
"TSMethodSignature"
|
|
2067
|
+
])) {
|
|
2068
|
+
if (node.computed && isReferenceId(node.key)) addDependency(node.key);
|
|
2069
|
+
if ("value" in node && isReferenceId(node.value)) addDependency(node.value);
|
|
2070
|
+
} else switch (node.type) {
|
|
2071
|
+
case "TSTypeReference":
|
|
2072
|
+
addDependency(TSEntityNameToRuntime(node.typeName));
|
|
2073
|
+
break;
|
|
2074
|
+
case "TSTypeQuery":
|
|
2075
|
+
if (seen.has(node.exprName)) return;
|
|
2076
|
+
if (node.exprName.type === "TSImportType") break;
|
|
2077
|
+
addDependency(TSEntityNameToRuntime(node.exprName));
|
|
2078
|
+
break;
|
|
2079
|
+
case "TSImportType": {
|
|
2080
|
+
seen.add(node);
|
|
2081
|
+
const { source, qualifier } = node;
|
|
2082
|
+
const resolved = await context.resolve(source.value, importer);
|
|
2083
|
+
if (!resolved || !!resolved.external) {
|
|
2084
|
+
preserveImportTypeCache.set(source.value, true);
|
|
2085
|
+
break;
|
|
2086
|
+
}
|
|
2087
|
+
const dep = importNamespace(node, qualifier, source, namespaceStmts, identifierMap);
|
|
2088
|
+
if (dep) addDependency(dep);
|
|
2089
|
+
break;
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
if (parent && !deps.has(node) && isChildSymbol(node, parent)) children.add(node);
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
2095
|
+
return Array.from(deps);
|
|
2096
|
+
function addDependency(node) {
|
|
2097
|
+
if (isThisExpression(node) || isInferred(node)) return;
|
|
2098
|
+
deps.add(node);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
|
|
2102
|
+
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
2103
|
+
const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
|
|
2104
|
+
let local = b.Identifier({ name: localName });
|
|
2105
|
+
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
2106
|
+
else namespaceStmts.set(source.value, {
|
|
2107
|
+
stmt: b.ImportDeclaration({
|
|
2108
|
+
specifiers: [b.ImportNamespaceSpecifier({ local })],
|
|
2109
|
+
source,
|
|
2110
|
+
phase: null,
|
|
2111
|
+
attributes: []
|
|
2112
|
+
}),
|
|
2113
|
+
local
|
|
2114
|
+
});
|
|
2115
|
+
if (imported) {
|
|
2116
|
+
const importedLeft = getIdFromTSEntityName(imported);
|
|
2117
|
+
if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
|
|
2118
|
+
overwriteNode(importedLeft, b.TSQualifiedName({
|
|
2119
|
+
left: local,
|
|
2120
|
+
right: { ...importedLeft }
|
|
2121
|
+
}));
|
|
2122
|
+
local = imported;
|
|
2123
|
+
}
|
|
2124
|
+
let replacement = node;
|
|
2125
|
+
if (node.typeArguments) {
|
|
2126
|
+
overwriteNode(node, b.TSTypeReference({
|
|
2127
|
+
typeName: local,
|
|
2128
|
+
typeArguments: node.typeArguments
|
|
2129
|
+
}));
|
|
2130
|
+
replacement = local;
|
|
2131
|
+
} else overwriteNode(node, local);
|
|
2132
|
+
return {
|
|
2133
|
+
...TSEntityNameToRuntime(local),
|
|
2134
|
+
replace(newNode) {
|
|
2135
|
+
overwriteNode(replacement, newNode);
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
function isChildSymbol(node, parent) {
|
|
2140
|
+
if (node.type === "Identifier") return true;
|
|
2141
|
+
if (is.oneOf(parent, ["TSPropertySignature", "TSMethodSignature"]) && parent.key === node) return true;
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
function collectInferredNames(node) {
|
|
2145
|
+
const inferred = [];
|
|
2146
|
+
walk(node, { enter(node) {
|
|
2147
|
+
if (node.type === "TSInferType" && node.typeParameter) inferred.push(node.typeParameter.name.name);
|
|
2148
|
+
} });
|
|
2149
|
+
return inferred;
|
|
2150
|
+
}
|
|
2151
|
+
const REFERENCE_RE = /\/\s*<reference\s+(?:path|types)=/;
|
|
2152
|
+
function collectReferenceDirectives(comment, negative = false) {
|
|
2153
|
+
return comment.filter((c) => REFERENCE_RE.test(c.value) !== negative);
|
|
2154
|
+
}
|
|
2155
|
+
const SOURCE_MAP_PRAGMA_RE = /^#\s*source(?:Mapping)?URL=/;
|
|
2156
|
+
function isSourceMapPragma(comment) {
|
|
2157
|
+
return SOURCE_MAP_PRAGMA_RE.test(comment.value);
|
|
2158
|
+
}
|
|
2159
|
+
function isCjsDtsInputSyntax(node) {
|
|
2160
|
+
return node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration" && node.moduleReference.type === "TSExternalModuleReference";
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Check if the given node is a {@link RuntimeBindingVariableDeclration}
|
|
2164
|
+
*/
|
|
2165
|
+
function isRuntimeBindingVariableDeclaration(node) {
|
|
2166
|
+
return node?.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].type === "VariableDeclarator" && node.declarations[0].id.type === "ArrayPattern" && isRuntimeBindingArrayExpression(node.declarations[0].init);
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Check if the given node is a {@link RuntimeBindingArrayExpression}
|
|
2170
|
+
*/
|
|
2171
|
+
function isRuntimeBindingArrayExpression(node) {
|
|
2172
|
+
return node?.type === "ArrayExpression" && isRuntimeBindingArrayElements(node.elements);
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* Check if the given array is a {@link RuntimeBindingArrayElements}
|
|
2176
|
+
*/
|
|
2177
|
+
function isRuntimeBindingArrayElements(elements) {
|
|
2178
|
+
const [declarationId, deps, children, effect] = elements;
|
|
2179
|
+
return is.NumericLiteral(declarationId) && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
|
|
2180
|
+
}
|
|
2181
|
+
function runtimeBindingArrayExpression(elements) {
|
|
2182
|
+
return b.ArrayExpression({ elements: [...elements] });
|
|
2183
|
+
}
|
|
2184
|
+
function isThisExpression(node) {
|
|
2185
|
+
return is.Identifier(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
|
|
2186
|
+
}
|
|
2187
|
+
function isInfer(node) {
|
|
2188
|
+
return is.Identifier(node, "infer");
|
|
2189
|
+
}
|
|
2190
|
+
function TSEntityNameToRuntime(node) {
|
|
2191
|
+
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
2192
|
+
const left = TSEntityNameToRuntime(node.left);
|
|
2193
|
+
return Object.assign(node, {
|
|
2194
|
+
type: "MemberExpression",
|
|
2195
|
+
object: left,
|
|
2196
|
+
property: node.right,
|
|
2197
|
+
computed: false
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
function getIdFromTSEntityName(node) {
|
|
2201
|
+
if (node.type === "Identifier" || node.type === "ThisExpression") return node;
|
|
2202
|
+
return getIdFromTSEntityName(node.left);
|
|
2203
|
+
}
|
|
2204
|
+
function isReferenceId(node) {
|
|
2205
|
+
return is.oneOf(node, ["Identifier", "MemberExpression"]);
|
|
2206
|
+
}
|
|
2207
|
+
function isHelperImport(node) {
|
|
2208
|
+
return node.type === "ImportDeclaration" && node.specifiers.length && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__exportAll", "__reExport"].includes(spec.local.name));
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* patch `.d.ts` suffix in import source to `.js`
|
|
2212
|
+
*/
|
|
2213
|
+
function patchImportExport(node, exportInfo, cjsDefault) {
|
|
2214
|
+
if (node.type === "ExportNamedDeclaration" && !node.declaration && !node.source && !node.specifiers.length && !node.attributes?.length) return false;
|
|
2215
|
+
if (node.type === "ImportDeclaration" && node.specifiers.length) {
|
|
2216
|
+
for (const specifier of node.specifiers) if (isInfer(specifier.local)) specifier.local.name = "__Infer";
|
|
2217
|
+
}
|
|
2218
|
+
if (is.oneOf(node, [
|
|
2219
|
+
"ImportDeclaration",
|
|
2220
|
+
"ExportAllDeclaration",
|
|
2221
|
+
"ExportNamedDeclaration"
|
|
2222
|
+
])) {
|
|
2223
|
+
if (node.type === "ExportAllDeclaration" && node.source && exportInfo.typeOnlyExportAllSources.has(node.source.value)) node.exportKind = "type";
|
|
2224
|
+
if (node.type === "ExportNamedDeclaration" && exportInfo.typeOnlyNames.size) {
|
|
2225
|
+
for (const spec of node.specifiers) {
|
|
2226
|
+
const name = nameOf(spec.exported);
|
|
2227
|
+
if (exportInfo.typeOnlyNames.has(name)) if (spec.type === "ExportSpecifier") spec.exportKind = "type";
|
|
2228
|
+
else node.exportKind = "type";
|
|
2229
|
+
}
|
|
2230
|
+
normalizeTypeOnlyExport(node);
|
|
2231
|
+
}
|
|
2232
|
+
if (node.source?.value && RE_DTS.test(node.source.value)) {
|
|
2233
|
+
node.source.value = filename_dts_to(node.source.value, "js");
|
|
2234
|
+
return node;
|
|
2235
|
+
}
|
|
2236
|
+
if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && nameOf(node.specifiers[0].exported) === "default") {
|
|
2237
|
+
const defaultExport = node.specifiers[0];
|
|
2238
|
+
return b.TSExportAssignment({ expression: defaultExport.local });
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
function normalizeTypeOnlyExport(node) {
|
|
2243
|
+
if (node.declaration || !node.specifiers.length) return;
|
|
2244
|
+
for (const specifier of node.specifiers) if (specifier.type !== "ExportSpecifier" || specifier.exportKind !== "type") return;
|
|
2245
|
+
node.exportKind = "type";
|
|
2246
|
+
for (const specifier of node.specifiers) if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Handle `__exportAll` call
|
|
2250
|
+
*/
|
|
2251
|
+
function patchTsNamespace(nodes) {
|
|
2252
|
+
const removed = /* @__PURE__ */ new Set();
|
|
2253
|
+
for (const [i, node] of nodes.entries()) {
|
|
2254
|
+
const result = getExportAllNamespace(node);
|
|
2255
|
+
if (!result) continue;
|
|
2256
|
+
const [binding, exports] = result;
|
|
2257
|
+
if (!exports.properties.length) continue;
|
|
2258
|
+
const namespaceExport = b.ExportNamedDeclaration({
|
|
2259
|
+
declaration: null,
|
|
2260
|
+
specifiers: exports.properties.filter((property) => property.type === "Property").map((property) => {
|
|
2261
|
+
const local = property.value.body;
|
|
2262
|
+
const exported = property.key;
|
|
2263
|
+
return b.ExportSpecifier({
|
|
2264
|
+
local,
|
|
2265
|
+
exported
|
|
2266
|
+
});
|
|
2267
|
+
}),
|
|
2268
|
+
source: null,
|
|
2269
|
+
attributes: []
|
|
2270
|
+
});
|
|
2271
|
+
nodes[i] = b.TSModuleDeclaration({
|
|
2272
|
+
id: binding,
|
|
2273
|
+
body: b.TSModuleBlock({ body: [namespaceExport] }),
|
|
2274
|
+
kind: "namespace",
|
|
2275
|
+
declare: true,
|
|
2276
|
+
global: false
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
return nodes.filter((node) => !removed.has(node));
|
|
2280
|
+
}
|
|
2281
|
+
function getExportAllNamespace(node) {
|
|
2282
|
+
if (node.type !== "VariableDeclaration" || node.declarations.length !== 1 || node.declarations[0].id.type !== "Identifier" || node.declarations[0].init?.type !== "CallExpression" || node.declarations[0].init.callee.type !== "Identifier" || node.declarations[0].init.callee.name !== "__exportAll" || node.declarations[0].init.arguments.length !== 1 || node.declarations[0].init.arguments[0].type !== "ObjectExpression") return false;
|
|
2283
|
+
return [node.declarations[0].id, node.declarations[0].init.arguments[0]];
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Handle `__reExport` call
|
|
2287
|
+
*/
|
|
2288
|
+
function patchReExport(nodes) {
|
|
2289
|
+
const exportsNames = /* @__PURE__ */ new Map();
|
|
2290
|
+
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);
|
|
2291
|
+
else if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && is.Identifier(node.expression.callee, "__reExport")) {
|
|
2292
|
+
const args = node.expression.arguments;
|
|
2293
|
+
exportsNames.set(args[0].name, args[1].name);
|
|
2294
|
+
} 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({
|
|
2295
|
+
id: b.Identifier({ name: node.declarations[0].id.name }),
|
|
2296
|
+
typeParameters: null,
|
|
2297
|
+
typeAnnotation: b.TSTypeReference({
|
|
2298
|
+
typeName: b.TSQualifiedName({
|
|
2299
|
+
left: b.Identifier({ name: exportsNames.get(node.declarations[0].init.object.name) }),
|
|
2300
|
+
right: b.Identifier({ name: node.declarations[0].init.property.name })
|
|
2301
|
+
}),
|
|
2302
|
+
typeArguments: null
|
|
2303
|
+
}),
|
|
2304
|
+
declare: false
|
|
2305
|
+
});
|
|
2306
|
+
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);
|
|
2307
|
+
return nodes;
|
|
2308
|
+
}
|
|
2309
|
+
function rewriteImportExport(node, set) {
|
|
2310
|
+
if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" && !node.declaration) {
|
|
2311
|
+
for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier") specifier.importKind = "value";
|
|
2312
|
+
else if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
|
|
2313
|
+
if (node.type === "ImportDeclaration") node.importKind = "value";
|
|
2314
|
+
else if (node.type === "ExportNamedDeclaration") node.exportKind = "value";
|
|
2315
|
+
return true;
|
|
2316
|
+
} else if (node.type === "ExportAllDeclaration") {
|
|
2317
|
+
node.exportKind = "value";
|
|
2318
|
+
return true;
|
|
2319
|
+
} else if (node.type === "TSImportEqualsDeclaration") {
|
|
2320
|
+
if (node.moduleReference.type === "TSExternalModuleReference") set(b.ImportDeclaration({
|
|
2321
|
+
specifiers: [b.ImportDefaultSpecifier({ local: node.id })],
|
|
2322
|
+
source: node.moduleReference.expression,
|
|
2323
|
+
phase: null,
|
|
2324
|
+
attributes: []
|
|
2325
|
+
}));
|
|
2326
|
+
return true;
|
|
2327
|
+
} else if (node.type === "TSExportAssignment" && node.expression.type === "Identifier") {
|
|
2328
|
+
set(b.ExportNamedDeclaration({
|
|
2329
|
+
declaration: null,
|
|
2330
|
+
specifiers: [b.ExportSpecifier({
|
|
2331
|
+
local: node.expression,
|
|
2332
|
+
exported: b.Identifier({ name: "default" })
|
|
2333
|
+
})],
|
|
2334
|
+
source: null,
|
|
2335
|
+
attributes: []
|
|
2336
|
+
}));
|
|
2337
|
+
return true;
|
|
2338
|
+
} else if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "Identifier") {
|
|
2339
|
+
set(b.ExportNamedDeclaration({
|
|
2340
|
+
declaration: null,
|
|
2341
|
+
specifiers: [b.ExportSpecifier({
|
|
2342
|
+
local: node.declaration,
|
|
2343
|
+
exported: b.Identifier({ name: "default" })
|
|
2344
|
+
})],
|
|
2345
|
+
source: null,
|
|
2346
|
+
attributes: []
|
|
2347
|
+
}));
|
|
2348
|
+
return true;
|
|
2349
|
+
}
|
|
2350
|
+
return false;
|
|
2351
|
+
}
|
|
2352
|
+
function overwriteNode(node, newNode) {
|
|
2353
|
+
for (const key of Object.keys(node)) Reflect.deleteProperty(node, key);
|
|
2354
|
+
Object.assign(node, newNode);
|
|
2355
|
+
return node;
|
|
2356
|
+
}
|
|
2357
|
+
function inheritNodeComments(oldNode, newNode) {
|
|
2358
|
+
newNode.comments ||= [];
|
|
2359
|
+
const pragmas = oldNode.comments?.filter((comment) => comment.position === "before" && comment.value.startsWith("#") && !isSourceMapPragma(comment));
|
|
2360
|
+
if (pragmas) newNode.comments.unshift(...pragmas);
|
|
2361
|
+
newNode.comments = newNode.comments.filter((comment) => !REFERENCE_RE.test(comment.value) && !isSourceMapPragma(comment));
|
|
2362
|
+
return newNode;
|
|
2363
|
+
}
|
|
2364
|
+
function getIdentifierIndex(identifierMap, name) {
|
|
2365
|
+
if (name in identifierMap) return ++identifierMap[name];
|
|
2366
|
+
return identifierMap[name] = 0;
|
|
2367
|
+
}
|
|
2368
|
+
const require = createRequire(import.meta.url);
|
|
2369
|
+
const debug$3 = createDebug("rolldown-plugin-dts:vue");
|
|
2370
|
+
const RE_VUE = /\.vue$/;
|
|
2371
|
+
function getVueVolarPlugin() {
|
|
2372
|
+
const ts = requireTS(`Vue support requires TypeScript to be installed. Please install \`typescript\` package.`);
|
|
2373
|
+
const [volarTypeScript, vue] = loadVueLanguageTools();
|
|
2374
|
+
const getLanguagePlugin = (ts, options) => {
|
|
2375
|
+
const $rootDir = options.options.$rootDir;
|
|
2376
|
+
const $configRaw = options.options.$configRaw;
|
|
2377
|
+
const resolver = new vue.CompilerOptionsResolver(ts, ts.sys.readFile);
|
|
2378
|
+
resolver.addConfig($configRaw?.vueCompilerOptions ?? {}, $rootDir);
|
|
2379
|
+
const vueOptions = resolver.build();
|
|
2380
|
+
return vue.createVueLanguagePlugin(ts, options.options, vueOptions, (id) => id);
|
|
2381
|
+
};
|
|
2382
|
+
return {
|
|
2383
|
+
extensionPatterns: [RE_VUE],
|
|
2384
|
+
tsFileExtensionInfos: [{
|
|
2385
|
+
extension: "vue",
|
|
2386
|
+
isMixedContent: true,
|
|
2387
|
+
scriptKind: ts.ScriptKind.Deferred
|
|
2388
|
+
}],
|
|
2389
|
+
volarTypeScript,
|
|
2390
|
+
create(ts, options) {
|
|
2391
|
+
return [getLanguagePlugin(ts, options)];
|
|
2392
|
+
},
|
|
2393
|
+
toTsFilename(id) {
|
|
2394
|
+
return id.replace(RE_VUE, ".vue.ts");
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
function loadVueLanguageTools() {
|
|
2399
|
+
debug$3("loading vue language tools");
|
|
2400
|
+
try {
|
|
2401
|
+
const vueTscPath = require.resolve("vue-tsc");
|
|
2402
|
+
return [require(require.resolve("@volar/typescript", { paths: [vueTscPath] })), require(require.resolve("@vue/language-core", { paths: [vueTscPath] }))];
|
|
2403
|
+
} catch (cause) {
|
|
2404
|
+
debug$3("vue language tools not found", cause);
|
|
2405
|
+
throw new Error("Failed to load vue language tools. Please manually install vue-tsc.", { cause });
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
var VolarContext = class {
|
|
2409
|
+
plugins;
|
|
2410
|
+
patterns;
|
|
2411
|
+
constructor(plugins) {
|
|
2412
|
+
this.plugins = plugins;
|
|
2413
|
+
this.patterns = plugins.flatMap((plugin) => plugin.extensionPatterns);
|
|
2414
|
+
}
|
|
2415
|
+
isVolarFile(id) {
|
|
2416
|
+
return this.patterns.some((pattern) => pattern.test(id));
|
|
2417
|
+
}
|
|
2418
|
+
getExtraFileExtensions() {
|
|
2419
|
+
if (!this.plugins.length) return;
|
|
2420
|
+
return this.plugins.flatMap((plugin) => plugin.tsFileExtensionInfos);
|
|
2421
|
+
}
|
|
2422
|
+
getCreateProgram(ts) {
|
|
2423
|
+
if (!this.plugins.length) return ts.createProgram;
|
|
2424
|
+
const { proxyCreateProgram } = this.plugins[0].volarTypeScript;
|
|
2425
|
+
return proxyCreateProgram(ts, ts.createProgram, (ts, options) => {
|
|
2426
|
+
const setups = [];
|
|
2427
|
+
const plugins = [];
|
|
2428
|
+
for (const plugin of this.plugins) {
|
|
2429
|
+
const result = plugin.create(ts, options);
|
|
2430
|
+
if (Array.isArray(result)) plugins.push(...result);
|
|
2431
|
+
else {
|
|
2432
|
+
if (result.setup) setups.push(result.setup);
|
|
2433
|
+
plugins.push(...result.languagePlugins);
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
return {
|
|
2437
|
+
setup: setups.length ? (language) => {
|
|
2438
|
+
for (const setup of setups) setup(language);
|
|
2439
|
+
} : void 0,
|
|
2440
|
+
languagePlugins: plugins
|
|
2441
|
+
};
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
toTsFilename(id) {
|
|
2445
|
+
for (const plugin of this.plugins) if (plugin.toTsFilename && plugin.extensionPatterns.some((pattern) => pattern.test(id))) return plugin.toTsFilename(id);
|
|
2446
|
+
return id;
|
|
2447
|
+
}
|
|
2448
|
+
};
|
|
2449
|
+
const debug$2 = createDebug("rolldown-plugin-dts:options");
|
|
2450
|
+
let warnedTsgo = false;
|
|
2451
|
+
function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, logger = console, volarPlugins, build = false, incremental = false, vue = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo }) {
|
|
2452
|
+
let resolvedTsconfig;
|
|
2453
|
+
if (tsconfig === true || tsconfig == null) {
|
|
2454
|
+
const { config, path } = at(cwd) || {};
|
|
2455
|
+
tsconfig = path;
|
|
2456
|
+
resolvedTsconfig = config;
|
|
2457
|
+
} else if (typeof tsconfig === "string") {
|
|
2458
|
+
tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
|
|
2459
|
+
resolvedTsconfig = ee(tsconfig).config;
|
|
2460
|
+
} else tsconfig = void 0;
|
|
2461
|
+
compilerOptions = {
|
|
2462
|
+
...resolvedTsconfig?.compilerOptions,
|
|
2463
|
+
...compilerOptions
|
|
2464
|
+
};
|
|
2465
|
+
incremental ||= compilerOptions.incremental || !!compilerOptions.tsBuildInfoFile;
|
|
2466
|
+
sourcemap ??= !!compilerOptions.declarationMap;
|
|
2467
|
+
compilerOptions.declarationMap = sourcemap;
|
|
2468
|
+
const tsconfigRaw = {
|
|
2469
|
+
...resolvedTsconfig,
|
|
2470
|
+
...overriddenTsconfigRaw,
|
|
2471
|
+
compilerOptions
|
|
2472
|
+
};
|
|
2473
|
+
volarPlugins ||= [];
|
|
2474
|
+
if (vue) volarPlugins.push(getVueVolarPlugin());
|
|
2475
|
+
if (volarPlugins.length) {
|
|
2476
|
+
if (isTS70Installed()) throw new Error("TypeScript 7.0 does not yet have a stable API and is experimental. The `vue` and `volarPlugins` options are not yet supported with TypeScript 7.0.");
|
|
2477
|
+
if (generator && generator !== "tsc") logger.warn("The `vue` and `volarPlugins` options are enabled, which requires the `tsc` generator. The `generator` option is ignored.");
|
|
2478
|
+
generator = "tsc";
|
|
2479
|
+
}
|
|
2480
|
+
const volarContext = new VolarContext(volarPlugins);
|
|
2481
|
+
if (!generator) if (tsgo) generator = "tsgo";
|
|
2482
|
+
else if (oxc || compilerOptions?.isolatedDeclarations) generator = "oxc";
|
|
2483
|
+
else if (isTS70Installed()) generator = "tsgo";
|
|
2484
|
+
else generator = "tsc";
|
|
2485
|
+
if (generator === "tsc") requireTS("Or enable `isolatedDeclarations` in your `tsconfig.json` to use Oxc instead.");
|
|
2486
|
+
else if (generator === "tsgo") {
|
|
2487
|
+
if (!tsconfig) throw new Error("tsgo generator requires a tsconfig file to be specified.");
|
|
2488
|
+
if (!warnedTsgo) {
|
|
2489
|
+
warnedTsgo = true;
|
|
2490
|
+
logger.warn("TypeScript 7.0 does not yet have a stable API and is experimental. Some options will be unavailable.");
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
if (oxc === true || !oxc) oxc = {};
|
|
2494
|
+
if (oxc) {
|
|
2495
|
+
oxc.stripInternal ??= !!compilerOptions?.stripInternal;
|
|
2496
|
+
oxc.sourcemap = !!compilerOptions.declarationMap;
|
|
2497
|
+
}
|
|
2498
|
+
if (tsgo === true || !tsgo) tsgo = {};
|
|
2499
|
+
emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
|
|
2500
|
+
const resolved = {
|
|
2501
|
+
generator,
|
|
2502
|
+
entry: entry ? Array.isArray(entry) ? entry : [entry] : void 0,
|
|
2503
|
+
cwd,
|
|
2504
|
+
dtsInput,
|
|
2505
|
+
emitDtsOnly,
|
|
2506
|
+
tsconfig,
|
|
2507
|
+
tsconfigRaw,
|
|
2508
|
+
sourcemap,
|
|
2509
|
+
resolver,
|
|
2510
|
+
cjsDefault,
|
|
2511
|
+
sideEffects,
|
|
2512
|
+
build,
|
|
2513
|
+
incremental,
|
|
2514
|
+
parallel,
|
|
2515
|
+
eager,
|
|
2516
|
+
newContext,
|
|
2517
|
+
emitJs,
|
|
2518
|
+
volarContext,
|
|
2519
|
+
oxc,
|
|
2520
|
+
tsgo,
|
|
2521
|
+
logger
|
|
2522
|
+
};
|
|
2523
|
+
debug$2("Resolved Options: %O", resolved);
|
|
2524
|
+
return resolved;
|
|
2525
|
+
}
|
|
2526
|
+
const debug$1 = createDebug("rolldown-plugin-dts:resolver");
|
|
2527
|
+
function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolver, sideEffects, volarContext }) {
|
|
2528
|
+
function isSourceFile(id) {
|
|
2529
|
+
return RE_TS.test(id) || RE_JSON.test(id) || volarContext.isVolarFile(id);
|
|
2530
|
+
}
|
|
2531
|
+
const baseDtsResolver = createResolver({
|
|
2532
|
+
tsconfig,
|
|
2533
|
+
resolveNodeModules: true,
|
|
2534
|
+
ResolverFactory
|
|
2535
|
+
});
|
|
2536
|
+
const moduleSideEffects = sideEffects ? true : null;
|
|
2537
|
+
return {
|
|
2538
|
+
name: "rolldown-plugin-dts:resolver",
|
|
2539
|
+
resolveId: {
|
|
2540
|
+
order: "pre",
|
|
2541
|
+
filter: [include(importerId(RE_DTS))],
|
|
2542
|
+
async handler(id, importer, options) {
|
|
2543
|
+
if (!importer) return;
|
|
2544
|
+
const external = {
|
|
2545
|
+
id,
|
|
2546
|
+
external: true,
|
|
2547
|
+
moduleSideEffects: sideEffects
|
|
2548
|
+
};
|
|
2549
|
+
const rolldownResolution = await this.resolve(id, importer, options);
|
|
2550
|
+
debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
|
|
2551
|
+
if (rolldownResolution?.external) {
|
|
2552
|
+
debug$1("Rolldown marked dts import as external:", id);
|
|
2553
|
+
return rolldownResolution;
|
|
2554
|
+
}
|
|
2555
|
+
const dtsResolution = await resolveDtsPath(id, importer, rolldownResolution);
|
|
2556
|
+
debug$1("Dts resolution for dts import %O from %O: %O", id, importer, dtsResolution);
|
|
2557
|
+
if (!dtsResolution) {
|
|
2558
|
+
if (RE_CSS.test(id)) {
|
|
2559
|
+
debug$1("Externalizing css import:", id);
|
|
2560
|
+
return external;
|
|
2561
|
+
}
|
|
2562
|
+
debug$1("Unresolvable dts import:", id, "from", importer);
|
|
2563
|
+
return isFilePath(id) ? null : external;
|
|
2564
|
+
}
|
|
2565
|
+
if (RE_DTS.test(dtsResolution)) {
|
|
2566
|
+
debug$1("Resolving dts import to declaration file:", id);
|
|
2567
|
+
return {
|
|
2568
|
+
id: dtsResolution,
|
|
2569
|
+
moduleSideEffects
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
if (isSourceFile(dtsResolution)) {
|
|
2573
|
+
debug$1("Resolving dts import to source file:", id);
|
|
2574
|
+
await this.load({ id: dtsResolution });
|
|
2575
|
+
return {
|
|
2576
|
+
id: filename_to_dts(dtsResolution, volarContext),
|
|
2577
|
+
moduleSideEffects
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
};
|
|
2583
|
+
async function resolveDtsPath(id, importer, rolldownResolution) {
|
|
2584
|
+
let dtsPath;
|
|
2585
|
+
if (resolver === "tsc") {
|
|
2586
|
+
const { tscResolve } = await import("./resolver-cwLsPb2o-oj1hqxK6.js");
|
|
2587
|
+
dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
|
|
2588
|
+
} else dtsPath = baseDtsResolver(id, importer);
|
|
2589
|
+
debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
|
|
2590
|
+
if (dtsPath) dtsPath = path.normalize(dtsPath);
|
|
2591
|
+
if (!dtsPath || !isSourceFile(dtsPath)) {
|
|
2592
|
+
if (rolldownResolution && isFilePath(rolldownResolution.id) && isSourceFile(rolldownResolution.id) && !rolldownResolution.external) return rolldownResolution.id;
|
|
2593
|
+
return null;
|
|
2594
|
+
}
|
|
2595
|
+
return dtsPath;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
function isFilePath(id) {
|
|
2599
|
+
return id.startsWith(".") || path.isAbsolute(id);
|
|
2600
|
+
}
|
|
2601
|
+
const debug = createDebug("rolldown-plugin-dts:options");
|
|
2602
|
+
function dts(options = {}) {
|
|
2603
|
+
debug("resolving dts options");
|
|
2604
|
+
const resolved = resolveOptions(options);
|
|
2605
|
+
debug("resolved dts options %o", resolved);
|
|
2606
|
+
const plugins = [];
|
|
2607
|
+
if (options.dtsInput) plugins.push(createDtsInputPlugin(resolved));
|
|
2608
|
+
else plugins.push(createGeneratePlugin(resolved));
|
|
2609
|
+
plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
|
|
2610
|
+
return plugins;
|
|
2611
|
+
}
|
|
2612
|
+
//#endregion
|
|
2613
|
+
export { dts };
|