@vureact/compiler-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/bin/development.js +12 -0
- package/bin/production.js +3 -0
- package/bin/vureact.js +14 -0
- package/lib/chunk-5M5CTYQR.js +6495 -0
- package/lib/chunk-U72HWKIZ.esm.js +6495 -0
- package/lib/cli.d.cts +2 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.esm.js +176 -0
- package/lib/cli.js +176 -0
- package/lib/compiler-core.d.cts +1344 -0
- package/lib/compiler-core.d.ts +1344 -0
- package/lib/compiler-core.esm.js +36 -0
- package/lib/compiler-core.js +36 -0
- package/package.json +83 -0
|
@@ -0,0 +1,1344 @@
|
|
|
1
|
+
import { GeneratorOptions as GeneratorOptions$1 } from '@babel/generator';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import { Expression, ArrayExpression, JSXIdentifier } from '@babel/types';
|
|
4
|
+
import { ParseResult as ParseResult$1 } from '@babel/parser';
|
|
5
|
+
import { RootNode, SourceLocation } from '@vue/compiler-core';
|
|
6
|
+
import { SFCTemplateBlock, SFCScriptBlock, SFCStyleBlock } from '@vue/compiler-sfc';
|
|
7
|
+
import { Options } from 'prettier';
|
|
8
|
+
|
|
9
|
+
type LangType = 'js' | 'jsx' | 'ts' | 'tsx';
|
|
10
|
+
|
|
11
|
+
type ReactiveTypes = 'ref' | 'reactive' | 'indirect' | 'none';
|
|
12
|
+
|
|
13
|
+
interface ICompilationContext {
|
|
14
|
+
fileId: string;
|
|
15
|
+
source: string;
|
|
16
|
+
compName: string;
|
|
17
|
+
filename: string;
|
|
18
|
+
imports: Map<string, ImportItem[]>;
|
|
19
|
+
cssVars: string[];
|
|
20
|
+
inputType: FileInputType;
|
|
21
|
+
/** 函数组件的 prop 参数名 */
|
|
22
|
+
propField: string;
|
|
23
|
+
/** 是否使用了路由 */
|
|
24
|
+
route?: boolean;
|
|
25
|
+
/** 是否将 Less / Sass 样式语言处理为 CSS */
|
|
26
|
+
preprocessStyles?: boolean;
|
|
27
|
+
templateData: {
|
|
28
|
+
lang?: string;
|
|
29
|
+
/** 用于描述 `<slot>` / `<slot name="" ...props>` */
|
|
30
|
+
slots: Record<string, SlotNodesContext>;
|
|
31
|
+
/** 收集模板 ref 对应的 script 绑定元数据 */
|
|
32
|
+
refBindings: RefBindings;
|
|
33
|
+
/** 收集所有模板中的响应式变量,其来自 script 的绑定元数据 */
|
|
34
|
+
reactiveBindings: ReactiveBindinds;
|
|
35
|
+
};
|
|
36
|
+
scriptData: {
|
|
37
|
+
lang: LangType;
|
|
38
|
+
/** 用于收集 Vue 的 `provide(name, value)` */
|
|
39
|
+
provide: ProvideData;
|
|
40
|
+
propsTSIface: IPropsContext;
|
|
41
|
+
source: string;
|
|
42
|
+
};
|
|
43
|
+
styleData: {
|
|
44
|
+
filePath: string;
|
|
45
|
+
/** style module 的名称 */
|
|
46
|
+
moduleName?: string;
|
|
47
|
+
/** style scoped 对应 id */
|
|
48
|
+
scopeId?: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
type ImportItem = {
|
|
52
|
+
name: string;
|
|
53
|
+
onDemand: boolean;
|
|
54
|
+
};
|
|
55
|
+
type FileInputType = 'sfc' | 'script-js' | 'script-ts';
|
|
56
|
+
interface SlotNodesContext {
|
|
57
|
+
name: string;
|
|
58
|
+
isScope: boolean;
|
|
59
|
+
props: {
|
|
60
|
+
prop: string;
|
|
61
|
+
value: string;
|
|
62
|
+
tsType: t.TSTypeAnnotation;
|
|
63
|
+
}[];
|
|
64
|
+
}
|
|
65
|
+
interface ReactiveBindinds {
|
|
66
|
+
[name: string]: {
|
|
67
|
+
name: string;
|
|
68
|
+
value: t.Expression;
|
|
69
|
+
source: string;
|
|
70
|
+
reactiveType: ReactiveTypes;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
interface RefBindings {
|
|
74
|
+
[name: string]: {
|
|
75
|
+
tag: string;
|
|
76
|
+
name: string;
|
|
77
|
+
htmlType: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
interface ProvideData {
|
|
81
|
+
name: string;
|
|
82
|
+
value: string;
|
|
83
|
+
isOccupied: boolean;
|
|
84
|
+
provide: ProvideData | Record<string, any>;
|
|
85
|
+
}
|
|
86
|
+
interface IPropsContext {
|
|
87
|
+
/**
|
|
88
|
+
* props 接口名称
|
|
89
|
+
*/
|
|
90
|
+
name: string;
|
|
91
|
+
/**
|
|
92
|
+
* 标记为疑似有 props 但是在 js 环境下
|
|
93
|
+
*/
|
|
94
|
+
hasPropsInJsEnv?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 用于记录源码中对应 API 的 ts 类型
|
|
97
|
+
*
|
|
98
|
+
* 1.推导出的属性元数据,如 (defineProps(['foo', 'bar']))
|
|
99
|
+
* 记录 key 和对应的类型(默认为 any/String 等)
|
|
100
|
+
*
|
|
101
|
+
* 2.显式定义的 TS 类型节点,如 (defineProps<{...}>)
|
|
102
|
+
*/
|
|
103
|
+
propsTypes: t.TSType[];
|
|
104
|
+
emitTypes: t.TSType[];
|
|
105
|
+
slotTypes: t.TSType[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface ParseResult {
|
|
109
|
+
template: BlockIR<SFCTemplateBlock, RootNode>;
|
|
110
|
+
script: BlockIR<SFCScriptBlock, ParseResult$1>;
|
|
111
|
+
style: BlockIR<SFCStyleBlock, undefined>;
|
|
112
|
+
}
|
|
113
|
+
type BlockIR<S, T> = {
|
|
114
|
+
source?: S;
|
|
115
|
+
ast: T;
|
|
116
|
+
} | null;
|
|
117
|
+
interface ParserOptions {
|
|
118
|
+
plugins?: PluginRegister<ParseResult>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 解析 Vue 单文件组件(SFC)源码,生成结构化解析结果。
|
|
122
|
+
*
|
|
123
|
+
* 此函数是解析阶段的核心入口,
|
|
124
|
+
* 负责将 Vue SFC 源码解析为包含模板、脚本、样式等各个块的结构化数据。
|
|
125
|
+
*
|
|
126
|
+
* @param source - Vue 单文件组件的源码字符串
|
|
127
|
+
* @param ctx - 编译上下文对象
|
|
128
|
+
* @param plugins - 可选的插件注册表,用于对解析结果进行自定义处理和增强
|
|
129
|
+
* @returns 解析结果对象,包含模板、脚本、样式块的解析信息
|
|
130
|
+
* @throws 不会直接抛出异常,错误信息会通过日志系统记录
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* - 函数内部使用 Vue 官方的 `@vue/compiler-sfc` 进行基础解析
|
|
134
|
+
* - 解析结果会经过后处理阶段,包括脚本元数据扫描
|
|
135
|
+
* - 插件按照注册顺序依次执行,可以对解析结果进行修改或增强
|
|
136
|
+
* - 错误处理:语法错误和编译错误会通过日志系统记录,不会中断执行
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // 基础用法:解析一个简单的 Vue 组件
|
|
141
|
+
*
|
|
142
|
+
* const vueSource = `
|
|
143
|
+
* <template>
|
|
144
|
+
* <div class="greeting">
|
|
145
|
+
* Hello, {{ name }}!
|
|
146
|
+
* </div>
|
|
147
|
+
* </template>
|
|
148
|
+
*
|
|
149
|
+
* <script setup lang="ts">
|
|
150
|
+
* import { ref } from 'vue'
|
|
151
|
+
*
|
|
152
|
+
* const name = ref('World')
|
|
153
|
+
* const count = ref(0)
|
|
154
|
+
*
|
|
155
|
+
* function increment() {
|
|
156
|
+
* count.value++
|
|
157
|
+
* }
|
|
158
|
+
* </script>
|
|
159
|
+
*
|
|
160
|
+
* <style scoped>
|
|
161
|
+
* .greeting {
|
|
162
|
+
* color: #42b983;
|
|
163
|
+
* font-size: 1.5rem;
|
|
164
|
+
* }
|
|
165
|
+
* </style>
|
|
166
|
+
* `;
|
|
167
|
+
*
|
|
168
|
+
* const ctx: ICompilationContext = {
|
|
169
|
+
* filename: 'MyComponent.vue',
|
|
170
|
+
* // 其他上下文配置...
|
|
171
|
+
* };
|
|
172
|
+
*
|
|
173
|
+
* const result = parseSFC(vueSource, ctx);
|
|
174
|
+
*
|
|
175
|
+
* // 访问解析结果
|
|
176
|
+
* console.log(result.template?.ast); // 模板的 AST 节点
|
|
177
|
+
* console.log(result.script?.ast); // 脚本的 Babel 解析结果
|
|
178
|
+
* console.log(result.style?.source); // 样式块原始信息
|
|
179
|
+
*
|
|
180
|
+
* // 使用可选插件配置,进行自定义处理
|
|
181
|
+
* const options: ParserOptions = {
|
|
182
|
+
* plugins: {
|
|
183
|
+
* myPlugin: (result, ctx) => {
|
|
184
|
+
* // 提取组件元数据
|
|
185
|
+
* const componentName = extractComponentName(result);
|
|
186
|
+
* // 添加自定义分析结果
|
|
187
|
+
* result.metadata = {
|
|
188
|
+
* name: componentName,
|
|
189
|
+
* analyzedAt: new Date().toISOString()
|
|
190
|
+
* };
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* };
|
|
194
|
+
*
|
|
195
|
+
* const resultWithPlugin = parseSFC(vueSource, compilationContext, options);
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
declare function parseSFC(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 仅用于解析 script 文件,参数与 parseSFC 一致
|
|
202
|
+
*/
|
|
203
|
+
declare function parseOnlyScript(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 解析 Vue 组件源码的统一入口函数。
|
|
207
|
+
*
|
|
208
|
+
* 根据输入类型自动选择解析器:
|
|
209
|
+
* - `sfc`: 解析 Vue 单文件组件(包含 template/script/style)
|
|
210
|
+
* - `script-*`: 仅解析脚本文件(如 .js、.ts)
|
|
211
|
+
*
|
|
212
|
+
* @param source - 源码字符串
|
|
213
|
+
* @param ctx - 编译上下文,包含输入类型、文件名等信息
|
|
214
|
+
* @param options - 可选的解析器配置,如插件
|
|
215
|
+
* @returns 解析结果对象,包含模板、脚本、样式的结构化数据
|
|
216
|
+
*/
|
|
217
|
+
declare function parse(source: string, ctx: ICompilationContext, options?: ParserOptions): ParseResult;
|
|
218
|
+
|
|
219
|
+
interface ScriptBlockIR {
|
|
220
|
+
/** Transformed full script AST (used for script-only input). */
|
|
221
|
+
scriptAST?: ParseResult$1;
|
|
222
|
+
imports: t.ImportDeclaration[];
|
|
223
|
+
exports: t.ExportDeclaration[];
|
|
224
|
+
tsTypes: t.TypeScript[];
|
|
225
|
+
/** Executable statements extracted from script block. */
|
|
226
|
+
statement: {
|
|
227
|
+
/** Statements hoisted outside component function. */
|
|
228
|
+
global: t.Node[];
|
|
229
|
+
/** Statements kept inside component function. */
|
|
230
|
+
local: ParseResult$1<t.File> | null;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
declare const enum NodeTypes {
|
|
235
|
+
FRAGMENT = 0,
|
|
236
|
+
ELEMENT = 1,
|
|
237
|
+
TEXT = 2,
|
|
238
|
+
COMMENT = 3,
|
|
239
|
+
JSX_INTERPOLATION = 4
|
|
240
|
+
}
|
|
241
|
+
declare const enum PropTypes {
|
|
242
|
+
ATTRIBUTE = 1,
|
|
243
|
+
SLOT = 2,
|
|
244
|
+
EVENT = 3,
|
|
245
|
+
DYNAMIC_ATTRIBUTE = 4
|
|
246
|
+
}
|
|
247
|
+
interface BabelExp<T = Expression> {
|
|
248
|
+
content: string;
|
|
249
|
+
ast: T;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface BaseSimpleNodeIR {
|
|
253
|
+
type: NodeTypes;
|
|
254
|
+
content: string;
|
|
255
|
+
babelExp: Expression;
|
|
256
|
+
}
|
|
257
|
+
interface FragmentNodeIR {
|
|
258
|
+
type: NodeTypes;
|
|
259
|
+
children: TemplateChildNodeIR[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
interface ElementNodeIR extends BaseElementNodeIR {
|
|
263
|
+
type: NodeTypes;
|
|
264
|
+
props: (PropsIR | SlotPropsIR)[];
|
|
265
|
+
children: TemplateChildNodeIR[];
|
|
266
|
+
meta: Partial<ElementNodeIRMeta>;
|
|
267
|
+
conditionIsHandled: boolean;
|
|
268
|
+
isBuiltIn?: boolean;
|
|
269
|
+
isRoute?: boolean;
|
|
270
|
+
}
|
|
271
|
+
interface BaseElementNodeIR {
|
|
272
|
+
tag: string;
|
|
273
|
+
isComponent?: boolean;
|
|
274
|
+
isSelfClosing?: boolean;
|
|
275
|
+
ref?: string;
|
|
276
|
+
loc?: SourceLocation;
|
|
277
|
+
}
|
|
278
|
+
interface ElementNodeIRMeta {
|
|
279
|
+
condition: ConditionMeta;
|
|
280
|
+
loop: LoopMeta;
|
|
281
|
+
memo: MemoMeta;
|
|
282
|
+
show: ShowMeta;
|
|
283
|
+
}
|
|
284
|
+
type ConditionMeta = {
|
|
285
|
+
if?: boolean;
|
|
286
|
+
elseIf?: boolean;
|
|
287
|
+
else?: boolean;
|
|
288
|
+
value: string;
|
|
289
|
+
babelExp: BabelExp;
|
|
290
|
+
next?: ElementNodeIR;
|
|
291
|
+
isHandled: boolean;
|
|
292
|
+
};
|
|
293
|
+
type LoopMeta = {
|
|
294
|
+
isLoop?: boolean;
|
|
295
|
+
value: {
|
|
296
|
+
source: string;
|
|
297
|
+
value: string;
|
|
298
|
+
key?: string;
|
|
299
|
+
index?: string;
|
|
300
|
+
};
|
|
301
|
+
isHandled: boolean;
|
|
302
|
+
};
|
|
303
|
+
type MemoMeta = {
|
|
304
|
+
isMemo?: boolean;
|
|
305
|
+
value: string;
|
|
306
|
+
babelExp: BabelExp<ArrayExpression>;
|
|
307
|
+
isHandled: boolean;
|
|
308
|
+
};
|
|
309
|
+
type ShowMeta = {
|
|
310
|
+
isShow?: boolean;
|
|
311
|
+
value: string;
|
|
312
|
+
babelExp: BabelExp;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
interface PropsIR {
|
|
316
|
+
type: PropTypes;
|
|
317
|
+
rawName?: string;
|
|
318
|
+
name: string;
|
|
319
|
+
isStatic?: boolean;
|
|
320
|
+
modifiers?: string[];
|
|
321
|
+
value: PropIRValue;
|
|
322
|
+
isKeyLessVBind?: boolean;
|
|
323
|
+
babelExp: BabelExp<JSXIdentifier | Expression>;
|
|
324
|
+
}
|
|
325
|
+
type PropIRValue = {
|
|
326
|
+
content: string;
|
|
327
|
+
isStringLiteral?: boolean;
|
|
328
|
+
merge?: string[];
|
|
329
|
+
babelExp: BabelExp;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
interface SlotPropsIR {
|
|
333
|
+
type: PropTypes.SLOT;
|
|
334
|
+
name: string;
|
|
335
|
+
rawName: string;
|
|
336
|
+
isStatic: boolean;
|
|
337
|
+
isScoped: boolean;
|
|
338
|
+
content?: TemplateChildNodeIR[];
|
|
339
|
+
callback?: {
|
|
340
|
+
arg: string;
|
|
341
|
+
exp: TemplateChildNodeIR[];
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface TemplateBlockIR {
|
|
346
|
+
children: TemplateChildNodeIR[];
|
|
347
|
+
}
|
|
348
|
+
type TemplateChildNodeIR = ElementNodeIR | BaseSimpleNodeIR | FragmentNodeIR;
|
|
349
|
+
|
|
350
|
+
interface ReactIRDescriptor {
|
|
351
|
+
template: TemplateBlockIR;
|
|
352
|
+
script: ScriptBlockIR;
|
|
353
|
+
style?: string;
|
|
354
|
+
}
|
|
355
|
+
interface TransformerOptions {
|
|
356
|
+
plugins?: PluginRegister<ReactIRDescriptor>;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* 将 Vue SFC 解析结果转换为 React 中间表示(IR)。
|
|
360
|
+
*
|
|
361
|
+
* 此函数是转换阶段的核心入口,负责将 Vue 组件的解析结果(AST)转换为
|
|
362
|
+
* 适合生成 React 代码的中间表示形式。转换过程包括模板转换和脚本转换。
|
|
363
|
+
*
|
|
364
|
+
* @param ast - Vue SFC 的解析结果,来自 {@link parse} 函数的返回值
|
|
365
|
+
* @param ctx - 编译上下文对象
|
|
366
|
+
* @param plugins - 可选的插件注册表,用于对转换结果进行自定义处理和增强
|
|
367
|
+
* @returns React 中间表示描述符,包含模板、脚本和样式的转换结果
|
|
368
|
+
*
|
|
369
|
+
* @remarks
|
|
370
|
+
* - 模板转换:将 Vue 模板 AST 转换为 React 可用的模板 IR
|
|
371
|
+
* - 脚本转换:将 Vue 脚本 AST 转换为 React 可用的脚本 IR
|
|
372
|
+
* - 样式处理:提取样式块内容,保留原始 CSS 字符串
|
|
373
|
+
* - 插件支持:支持通过插件对转换结果进行自定义处理
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* // 转换示例
|
|
378
|
+
*
|
|
379
|
+
* const ctx: ICompilationContext = {
|
|
380
|
+
* filename: 'MyComponent.vue',
|
|
381
|
+
* // 其他上下文配置...
|
|
382
|
+
* };
|
|
383
|
+
*
|
|
384
|
+
* // 1. 首先解析 Vue SFC
|
|
385
|
+
* const parseResult = parse(vueSource, ctx);
|
|
386
|
+
*
|
|
387
|
+
* // 2. 将解析结果转换为 React IR
|
|
388
|
+
* const reactIR = transform(parseResult, ctx);
|
|
389
|
+
*
|
|
390
|
+
* // 访问转换结果
|
|
391
|
+
* console.log(reactIR.template); // 模板转换结果
|
|
392
|
+
* console.log(reactIR.script); // 脚本转换结果
|
|
393
|
+
* console.log(reactIR.style); // 样式内容字符串
|
|
394
|
+
*
|
|
395
|
+
* // 使用可选插件配置,进行自定义处理
|
|
396
|
+
* const options: TransformerOptions = {
|
|
397
|
+
* plugins: {
|
|
398
|
+
* extractMetadata: (result, ctx) => {
|
|
399
|
+
* const componentName = extractComponentNameFromScript(result.script);
|
|
400
|
+
* const propsCount = countProps(result.script);
|
|
401
|
+
*
|
|
402
|
+
* result.metadata = {
|
|
403
|
+
* name: componentName,
|
|
404
|
+
* propsCount,
|
|
405
|
+
* hasStyle: !!result.style,
|
|
406
|
+
* convertedAt: new Date().toISOString(),
|
|
407
|
+
* };
|
|
408
|
+
* },
|
|
409
|
+
*
|
|
410
|
+
* // 插2:样式预处理
|
|
411
|
+
* preprocessStyles: (result, ctx) => {
|
|
412
|
+
* if (result.style) {
|
|
413
|
+
* // 对样式进行预处理,如添加前缀等
|
|
414
|
+
* result.style = addVendorPrefixes(result.style);
|
|
415
|
+
* result.style = minifyCSS(result.style);
|
|
416
|
+
* }
|
|
417
|
+
* },
|
|
418
|
+
* }
|
|
419
|
+
* }
|
|
420
|
+
*
|
|
421
|
+
* // 使用多个插件进行转换
|
|
422
|
+
* const reactIRWithPlugins = transform(parseResult, ctx, plugins);
|
|
423
|
+
*
|
|
424
|
+
* // 插件处理后的结果包含自定义数据
|
|
425
|
+
* console.log(reactIRWithPlugins.metadata);
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
declare function transform(ast: ParseResult, ctx: ICompilationContext, options?: TransformerOptions): ReactIRDescriptor;
|
|
429
|
+
|
|
430
|
+
interface GeneratorOptions extends GeneratorOptions$1 {
|
|
431
|
+
plugins?: PluginRegister<GeneratorResult>;
|
|
432
|
+
}
|
|
433
|
+
interface GeneratorResult {
|
|
434
|
+
ast: t.Program | ParseResult$1;
|
|
435
|
+
code: string;
|
|
436
|
+
source: string;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* 将 React 中间表示(IR)生成为可执行的 JSX/TSX 代码。
|
|
440
|
+
*
|
|
441
|
+
* 此函数是代码生成阶段的核心入口,负责将转换后的 React IR 转换为
|
|
442
|
+
* 完整的 AST 并最终生成源代码。生成过程包括 JSX 构建和脚本构建。
|
|
443
|
+
*
|
|
444
|
+
* @param ir - React 中间表示描述符,来自 {@link transform} 函数的返回值
|
|
445
|
+
* @param ctx - 编译上下文对象
|
|
446
|
+
* @param options - 可选的生成选项,包括 Babel 生成器选项和插件
|
|
447
|
+
* @returns 生成结果对象,包含 AST、生成的代码和原始源码引用
|
|
448
|
+
*
|
|
449
|
+
* @remarks
|
|
450
|
+
* - JSX 构建:将模板 IR 转换为 JSX AST 节点
|
|
451
|
+
* - 脚本构建:将脚本 IR 与 JSX 结合,构建完整的程序 AST
|
|
452
|
+
* - 代码生成:使用 Babel 生成器将 AST 转换为源代码字符串
|
|
453
|
+
* - 插件支持:支持通过插件对生成结果进行自定义处理
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```typescript
|
|
457
|
+
* // 生成示例
|
|
458
|
+
*
|
|
459
|
+
* const ctx: ICompilationContext = {
|
|
460
|
+
* filename: 'MyComponent.vue',
|
|
461
|
+
* source: vueSource,
|
|
462
|
+
* // 其他上下文配置...
|
|
463
|
+
* };
|
|
464
|
+
*
|
|
465
|
+
* // 1. 解析 Vue SFC
|
|
466
|
+
* const parseResult = parse(vueSource, ctx);
|
|
467
|
+
*
|
|
468
|
+
* // 2. 转换为 React IR
|
|
469
|
+
* const reactIR = transform(parseResult, ctx);
|
|
470
|
+
*
|
|
471
|
+
* // 使用可选配置项进行自定义处理
|
|
472
|
+
* const generatorOptions: GeneratorOptions = {
|
|
473
|
+
* // 配置 jsesc 避免 Unicode 转义
|
|
474
|
+
* jsescOption: {
|
|
475
|
+
* minimal: true,
|
|
476
|
+
* quotes: 'single'
|
|
477
|
+
* },
|
|
478
|
+
* minified: true,
|
|
479
|
+
*
|
|
480
|
+
* // 自定义插件
|
|
481
|
+
* plugins: {
|
|
482
|
+
* // 插件1:代码格式化
|
|
483
|
+
* formatCode: (result, ctx) => {
|
|
484
|
+
* // 使用 prettier 格式化生成的代码
|
|
485
|
+
* result.code = prettier.format(result.code, {
|
|
486
|
+
* parser: 'babel',
|
|
487
|
+
* semi: true,
|
|
488
|
+
* singleQuote: true,
|
|
489
|
+
* });
|
|
490
|
+
* },
|
|
491
|
+
*
|
|
492
|
+
* // 插件2:代码质量检查
|
|
493
|
+
* lintGeneratedCode: (result, ctx) => {
|
|
494
|
+
* const issues = eslint.verify(result.code, {
|
|
495
|
+
* rules: {
|
|
496
|
+
* 'react/react-in-jsx-scope': 'off',
|
|
497
|
+
* 'no-unused-vars': 'warn',
|
|
498
|
+
* },
|
|
499
|
+
* });
|
|
500
|
+
*
|
|
501
|
+
* if (issues.length > 0) {
|
|
502
|
+
* result.lintIssues = issues;
|
|
503
|
+
* console.warn(`Found ${issues.length} lint issues in generated code`);
|
|
504
|
+
* }
|
|
505
|
+
* },
|
|
506
|
+
* },
|
|
507
|
+
* };
|
|
508
|
+
*
|
|
509
|
+
* // 3. 生成 React 组件
|
|
510
|
+
* const generated = generateComponent(reactIR, ctx, generatorOptions);
|
|
511
|
+
*
|
|
512
|
+
* // 访问生成结果
|
|
513
|
+
* console.log(generated.ast); // 完整的 Babel AST
|
|
514
|
+
* console.log(generated.code); // 生成的 React 代码
|
|
515
|
+
* console.log(generated.source); // 原始 Vue 源码
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
declare function generateComponent(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult;
|
|
519
|
+
|
|
520
|
+
declare function generateOnlyScript(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* 代码生成的统一入口函数。
|
|
524
|
+
*
|
|
525
|
+
* 根据输入类型自动选择生成器:
|
|
526
|
+
* - `sfc`: 生成完整的 React 组件(包含 JSX 和脚本)
|
|
527
|
+
* - `script-*`: 仅生成脚本代码(如 .js、.ts)
|
|
528
|
+
*
|
|
529
|
+
* @param ir - React 中间表示描述符,来自转换阶段的结果
|
|
530
|
+
* @param ctx - 编译上下文,包含输入类型、源码等信息
|
|
531
|
+
* @param options - 可选的生成器配置,如 Babel 生成选项和插件
|
|
532
|
+
* @returns 生成结果对象,包含 AST、生成的代码和原始源码
|
|
533
|
+
*/
|
|
534
|
+
declare function generate(ir: ReactIRDescriptor, ctx: ICompilationContext, options?: GeneratorOptions): GeneratorResult;
|
|
535
|
+
|
|
536
|
+
interface CompilerOptions {
|
|
537
|
+
/**
|
|
538
|
+
* Manually specify the root directory.
|
|
539
|
+
* @default process.cwd()
|
|
540
|
+
*/
|
|
541
|
+
root?: string;
|
|
542
|
+
/**
|
|
543
|
+
* Path to the source file or directory.
|
|
544
|
+
* - If it is a file, compile the single file.
|
|
545
|
+
* - If it is a directory, recursively compile all .vue files under the directory.
|
|
546
|
+
*
|
|
547
|
+
* @default
|
|
548
|
+
* 'src/' // The src directory under the root directory
|
|
549
|
+
*/
|
|
550
|
+
input?: string;
|
|
551
|
+
/**
|
|
552
|
+
* Whether to enable build cache and reuse the previous cache results
|
|
553
|
+
* @default true
|
|
554
|
+
*/
|
|
555
|
+
cache?: boolean;
|
|
556
|
+
output?: {
|
|
557
|
+
/**
|
|
558
|
+
* Output the name of the root directory corresponding to the file's location.
|
|
559
|
+
* @default '.vureact'
|
|
560
|
+
*/
|
|
561
|
+
workspace?: string;
|
|
562
|
+
/**
|
|
563
|
+
* Output directory name, relative to `output.workspace`
|
|
564
|
+
* @default 'dist'
|
|
565
|
+
*/
|
|
566
|
+
outDir?: string;
|
|
567
|
+
/**
|
|
568
|
+
* Whether to automatically call Vite to initialize a standard
|
|
569
|
+
* React project environment before compilation.
|
|
570
|
+
* @default true
|
|
571
|
+
*/
|
|
572
|
+
bootstrapVite?: boolean | {
|
|
573
|
+
/**
|
|
574
|
+
* @default 'react-ts'
|
|
575
|
+
*/
|
|
576
|
+
template: 'react-ts' | 'react';
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Specify asset files that do not need to be copied.
|
|
580
|
+
* They can be filenames or paths, using fuzzy matching.
|
|
581
|
+
* @default
|
|
582
|
+
* [
|
|
583
|
+
* 'package.json',
|
|
584
|
+
* 'package-lock.json',
|
|
585
|
+
* 'pnpm-lock.yaml',
|
|
586
|
+
* 'index.html',
|
|
587
|
+
* 'tsconfig.',
|
|
588
|
+
* 'vite.config.',
|
|
589
|
+
* 'eslint.config.',
|
|
590
|
+
* 'readme.',
|
|
591
|
+
* 'vue.',
|
|
592
|
+
* 'vureact.config.js',
|
|
593
|
+
* ]
|
|
594
|
+
*/
|
|
595
|
+
ignoreAssets?: string[];
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* Excluded file/directory matching patterns (glob syntax supported).
|
|
599
|
+
* @default
|
|
600
|
+
* [
|
|
601
|
+
* 'node_modules/**',
|
|
602
|
+
* 'dist/**',
|
|
603
|
+
* 'build/**',
|
|
604
|
+
* '.git/**',
|
|
605
|
+
* '.vureact/**'
|
|
606
|
+
* ]
|
|
607
|
+
*/
|
|
608
|
+
exclude?: string[];
|
|
609
|
+
/**
|
|
610
|
+
* Whether to recursively search subdirectories.
|
|
611
|
+
* @default true
|
|
612
|
+
*/
|
|
613
|
+
recursive?: boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Options passed through to babel-generator.
|
|
616
|
+
*/
|
|
617
|
+
generate?: GeneratorOptions$1;
|
|
618
|
+
/**
|
|
619
|
+
* Watch files in real time and auto-recompile on changes.
|
|
620
|
+
* @default false
|
|
621
|
+
*/
|
|
622
|
+
watch?: boolean;
|
|
623
|
+
/**
|
|
624
|
+
* Whether to process Less/Sass style languages into CSS
|
|
625
|
+
* @default true
|
|
626
|
+
*/
|
|
627
|
+
preprocessStyles?: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Can be used to add plugins and customize the output results of
|
|
630
|
+
* the parse/transform/codegen/compiled stages respectively.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* plugins: {
|
|
635
|
+
* // For example, add custom data to the parsing results.
|
|
636
|
+
* parser: {
|
|
637
|
+
* myPlugin: (result, ctx) => {
|
|
638
|
+
* result.metadata = {
|
|
639
|
+
* timestamp: Date.now()
|
|
640
|
+
* }
|
|
641
|
+
* },
|
|
642
|
+
* },
|
|
643
|
+
*
|
|
644
|
+
* // If the key names parse/transform/codegen are not specified,
|
|
645
|
+
* // the plugin will execute upon completion of compilation.
|
|
646
|
+
* yourPlguin: (result) => {
|
|
647
|
+
* console.log(result)
|
|
648
|
+
* }
|
|
649
|
+
* }
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
plugins?: PluginRegister<CompilationResult> & {
|
|
653
|
+
/**
|
|
654
|
+
* Register parser plugins
|
|
655
|
+
*/
|
|
656
|
+
parser?: PluginRegister<ParseResult>;
|
|
657
|
+
/**
|
|
658
|
+
* Register transformer plugins
|
|
659
|
+
*/
|
|
660
|
+
transformer?: PluginRegister<ReactIRDescriptor>;
|
|
661
|
+
/**
|
|
662
|
+
* Register codegen plugins
|
|
663
|
+
*/
|
|
664
|
+
codegen?: PluginRegister<GeneratorResult>;
|
|
665
|
+
};
|
|
666
|
+
format?: {
|
|
667
|
+
/**
|
|
668
|
+
* @default false
|
|
669
|
+
*/
|
|
670
|
+
enabled?: boolean;
|
|
671
|
+
/**
|
|
672
|
+
* @default 'prettier'
|
|
673
|
+
*/
|
|
674
|
+
formatter?: 'prettier' | 'builtin';
|
|
675
|
+
/**
|
|
676
|
+
* Configure the formatting options for Prettier,
|
|
677
|
+
* which takes effect only when the formatter is set to 'prettier'.
|
|
678
|
+
*/
|
|
679
|
+
prettierOptions?: Options;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Log Control Options
|
|
683
|
+
*/
|
|
684
|
+
logging?: {
|
|
685
|
+
/**
|
|
686
|
+
* @default true
|
|
687
|
+
*/
|
|
688
|
+
enabled?: boolean;
|
|
689
|
+
/** Whether to output warning messages. */
|
|
690
|
+
warnings?: boolean;
|
|
691
|
+
/** Whether to output info messages. */
|
|
692
|
+
info?: boolean;
|
|
693
|
+
/** Whether to output error messages. */
|
|
694
|
+
errors?: boolean;
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* Execute only after the first successful full compilation.
|
|
698
|
+
*/
|
|
699
|
+
onSuccess?: () => Promise<void | undefined>;
|
|
700
|
+
/**
|
|
701
|
+
* Execute after file are added or recompiled in `watch` mode.
|
|
702
|
+
*
|
|
703
|
+
* @param event Add or modify file
|
|
704
|
+
* @param unit Current sfc or script file compilation unit
|
|
705
|
+
*/
|
|
706
|
+
onChange?: (event: 'add' | 'change', unit: SFCUnit | ScriptUnit) => Promise<void | undefined>;
|
|
707
|
+
}
|
|
708
|
+
interface PluginRegister<T> {
|
|
709
|
+
[name: string]: (result: T, ctx: ICompilationContext) => void;
|
|
710
|
+
}
|
|
711
|
+
type CompilationResult = SFCCompilationResult | ScriptCompilationResult;
|
|
712
|
+
interface SFCCompilationResult extends BaseCompilationResult {
|
|
713
|
+
fileInfo: {
|
|
714
|
+
jsx: {
|
|
715
|
+
file: string;
|
|
716
|
+
lang: string;
|
|
717
|
+
};
|
|
718
|
+
css: {
|
|
719
|
+
file?: string;
|
|
720
|
+
hash?: string;
|
|
721
|
+
code?: string;
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
interface ScriptCompilationResult extends BaseCompilationResult {
|
|
726
|
+
fileInfo: {
|
|
727
|
+
script: {
|
|
728
|
+
file: string;
|
|
729
|
+
lang: string;
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
interface BaseCompilationResult extends GeneratorResult {
|
|
734
|
+
fileId: string;
|
|
735
|
+
hasRoute?: boolean;
|
|
736
|
+
}
|
|
737
|
+
interface ScriptUnit extends CompilationUnit {
|
|
738
|
+
output: {
|
|
739
|
+
script: OutputItem;
|
|
740
|
+
} | null;
|
|
741
|
+
}
|
|
742
|
+
interface SFCUnit extends CompilationUnit {
|
|
743
|
+
output: {
|
|
744
|
+
jsx: OutputItem;
|
|
745
|
+
css: Partial<OutputItem>;
|
|
746
|
+
} | null;
|
|
747
|
+
}
|
|
748
|
+
interface OutputItem {
|
|
749
|
+
file: string;
|
|
750
|
+
code: string;
|
|
751
|
+
}
|
|
752
|
+
interface AssetUnit extends Omit<CompilationUnit, 'fileId' | 'source'> {
|
|
753
|
+
}
|
|
754
|
+
interface CompilationUnit extends FileMeta {
|
|
755
|
+
file: string;
|
|
756
|
+
fileId: string;
|
|
757
|
+
source: string;
|
|
758
|
+
hasRoute?: boolean;
|
|
759
|
+
}
|
|
760
|
+
type LoadedCache<T = CacheMeta> = {
|
|
761
|
+
key: CacheKey;
|
|
762
|
+
target: T[];
|
|
763
|
+
source: CacheList;
|
|
764
|
+
};
|
|
765
|
+
type CacheMeta = Vue2ReactCacheMeta | FileCacheMeta;
|
|
766
|
+
declare enum CacheKey {
|
|
767
|
+
SFC = "sfc",
|
|
768
|
+
SCRIPT = "script",
|
|
769
|
+
ASSET = "copied"
|
|
770
|
+
}
|
|
771
|
+
interface CacheList {
|
|
772
|
+
[CacheKey.SFC]: Vue2ReactCacheMeta[];
|
|
773
|
+
[CacheKey.SCRIPT]: FileCacheMeta[];
|
|
774
|
+
[CacheKey.ASSET]: FileCacheMeta[];
|
|
775
|
+
}
|
|
776
|
+
type Vue2ReactCacheMeta = Omit<SFCUnit, 'source'>;
|
|
777
|
+
interface FileCacheMeta extends FileMeta {
|
|
778
|
+
file: string;
|
|
779
|
+
}
|
|
780
|
+
interface FileMeta {
|
|
781
|
+
fileSize: number;
|
|
782
|
+
mtime: number;
|
|
783
|
+
hash?: string;
|
|
784
|
+
}
|
|
785
|
+
interface CacheCheckResult {
|
|
786
|
+
shouldCompile: boolean;
|
|
787
|
+
hash?: string;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
declare class Helper {
|
|
791
|
+
private compilerOpts;
|
|
792
|
+
private pathFilter;
|
|
793
|
+
private workspaceDir;
|
|
794
|
+
private outDir;
|
|
795
|
+
constructor(opts: CompilerOptions);
|
|
796
|
+
/**
|
|
797
|
+
* 获取用户的项目根目录
|
|
798
|
+
*/
|
|
799
|
+
getProjectRoot(): string;
|
|
800
|
+
/**
|
|
801
|
+
* 获取输入文件的路径
|
|
802
|
+
*/
|
|
803
|
+
getInputPath(): string;
|
|
804
|
+
/**
|
|
805
|
+
* 检查 input 路径是否是单个文件
|
|
806
|
+
*/
|
|
807
|
+
isSingleFile(): boolean;
|
|
808
|
+
/**
|
|
809
|
+
* 获取输出文件的路径。如:'[root]/.vureact/dist/'
|
|
810
|
+
*/
|
|
811
|
+
getOuputPath(): string;
|
|
812
|
+
getOutDirName(): string;
|
|
813
|
+
getWorkspaceDir(): string;
|
|
814
|
+
/**
|
|
815
|
+
* 根据相对输出路径反推源文件路径
|
|
816
|
+
*/
|
|
817
|
+
getSourcePath(outputPath: string): string;
|
|
818
|
+
getIgnoreAssets(): Set<string>;
|
|
819
|
+
getIsCache(): boolean;
|
|
820
|
+
/**
|
|
821
|
+
* 返回原始目录下的 package.json 路径
|
|
822
|
+
*/
|
|
823
|
+
getRootPkgPath(): string;
|
|
824
|
+
/**
|
|
825
|
+
* 返回 output 的 package.json 路径
|
|
826
|
+
*/
|
|
827
|
+
getOutputPkgPath(): string;
|
|
828
|
+
/**
|
|
829
|
+
* 返回文件相对工作区的路径
|
|
830
|
+
*/
|
|
831
|
+
relativePath(filePath: string): string;
|
|
832
|
+
/**
|
|
833
|
+
* 替换 .vue 文件名后缀为 .jsx/.tsx
|
|
834
|
+
* @param filePath 文件完整路径
|
|
835
|
+
* @param ext 文件拓展名
|
|
836
|
+
* @returns 返回文件的相对路径,不包含当前工作区路径
|
|
837
|
+
*/
|
|
838
|
+
replaceVueFileExt(filePath: string, ext: string): string;
|
|
839
|
+
/**
|
|
840
|
+
* 判断是否应该跳过不需要进行文件搜索的路径
|
|
841
|
+
*/
|
|
842
|
+
shouldSkipPath(filePath: string): boolean;
|
|
843
|
+
/**
|
|
844
|
+
* 自动根据项目结构推导 react-app 目录下的对应位置
|
|
845
|
+
*/
|
|
846
|
+
resolveOutputPath(filePath: string, extname?: string): string;
|
|
847
|
+
/**
|
|
848
|
+
* 格式化代码
|
|
849
|
+
*/
|
|
850
|
+
formatCode({ code, fileInfo }: CompilationResult): Promise<string>;
|
|
851
|
+
/**
|
|
852
|
+
* 通用的缓存校验工具函数
|
|
853
|
+
* @param current 当前文件元数据
|
|
854
|
+
* @param cached 缓存中的旧数据
|
|
855
|
+
* @param getSource 获取文件内容的函数(仅在元数据不一致时才调用,避免多余 I/O)
|
|
856
|
+
*/
|
|
857
|
+
checkCacheStatus(current: FileMeta, cached: CacheMeta | undefined, getSource: () => Promise<string>): Promise<CacheCheckResult>;
|
|
858
|
+
/**
|
|
859
|
+
* 对比相同两个文件的基础元数据
|
|
860
|
+
*/
|
|
861
|
+
compareFileMeta(a: FileMeta, b: FileMeta): boolean;
|
|
862
|
+
/**
|
|
863
|
+
* 统一的写文件方法,包含自动创建目录
|
|
864
|
+
*/
|
|
865
|
+
writeFileWithDir(filePath: string, content: string): Promise<void>;
|
|
866
|
+
/**
|
|
867
|
+
* 加载指定文件的缓存内容
|
|
868
|
+
* @param key 缓存键
|
|
869
|
+
*/
|
|
870
|
+
loadCache(key: CacheKey.SFC): Promise<LoadedCache<Vue2ReactCacheMeta>>;
|
|
871
|
+
loadCache(key: CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<FileCacheMeta>>;
|
|
872
|
+
loadCache(key: CacheKey.SFC | CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<Vue2ReactCacheMeta | FileCacheMeta>>;
|
|
873
|
+
createCacheData(key: CacheKey): LoadedCache;
|
|
874
|
+
/**
|
|
875
|
+
* 获取缓存文件路径
|
|
876
|
+
*/
|
|
877
|
+
getCachePath(): string;
|
|
878
|
+
saveCache(data?: LoadedCache): Promise<void>;
|
|
879
|
+
genHash(content: string): string;
|
|
880
|
+
/**
|
|
881
|
+
* 扫描指定目录下的所有文件
|
|
882
|
+
* @param dir 目标目录
|
|
883
|
+
* @param filter 筛选指定的文件后缀名
|
|
884
|
+
*/
|
|
885
|
+
scanFiles(dir: string, filter: (file: string) => boolean): string[];
|
|
886
|
+
getAbsPath(filePath: string): string;
|
|
887
|
+
getFileMeta(filePath: string): Promise<FileMeta>;
|
|
888
|
+
removeOutputFile(filePath: string, resolveOutputPath?: boolean): Promise<void>;
|
|
889
|
+
updateCache(targetFile: string, newData: any, cache: LoadedCache): void;
|
|
890
|
+
resolveViteCreateApp(): void;
|
|
891
|
+
/**
|
|
892
|
+
* 获取需要排除编译的文件
|
|
893
|
+
*/
|
|
894
|
+
getExcludes(): string[];
|
|
895
|
+
/**
|
|
896
|
+
* 打印 core 模块执行过程中收集的日志
|
|
897
|
+
*/
|
|
898
|
+
printCoreLogs(): void;
|
|
899
|
+
printCompileInfo(file: string, duration: string): void;
|
|
900
|
+
print(...message: any[]): void;
|
|
901
|
+
/**
|
|
902
|
+
* 读取 package.json 文件内容,并处理成对象返回
|
|
903
|
+
*/
|
|
904
|
+
resolvePackageFile(path: string): Promise<Record<string, any>>;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* 基础编译器类,提供 Vue 到 React 代码转换的核心编译功能。
|
|
909
|
+
*
|
|
910
|
+
* 此类继承自 {@link Helper},是 VuReact 编译器的核心实现,负责:
|
|
911
|
+
* 1. 初始化编译上下文:为每次编译创建独立的上下文环境
|
|
912
|
+
* 2. 执行完整的编译流程:解析(parse)→ 转换(transform)→ 生成(generate)
|
|
913
|
+
* 3. 管理编译选项和配置:处理用户传入的编译器配置
|
|
914
|
+
* 4. 插件系统集成:支持解析、转换、生成各阶段的插件扩展
|
|
915
|
+
* 5. 错误处理和日志记录:通过日志系统记录编译过程中的信息
|
|
916
|
+
*
|
|
917
|
+
* 主要用途:
|
|
918
|
+
* - 供 {@link FileCompiler} 继承使用,实现文件系统级别的批量编译
|
|
919
|
+
* - 直接实例化用于单文件编译,适合集成到其他工具链中
|
|
920
|
+
*
|
|
921
|
+
* 核心特性:
|
|
922
|
+
* - 三阶段编译流水线:严格遵循解析→转换→生成的编译模型
|
|
923
|
+
* - 插件化架构:支持在编译各阶段插入自定义逻辑
|
|
924
|
+
* - 上下文隔离:每次编译创建独立上下文,避免状态污染
|
|
925
|
+
* - 资源感知:自动处理样式预处理和路由依赖检测
|
|
926
|
+
* - 错误恢复:编译错误通过日志记录,不会中断整个流程
|
|
927
|
+
*
|
|
928
|
+
* 编译流程详解:
|
|
929
|
+
* 1. 解析阶段:使用 {@link parse} 将 Vue 代码解析为抽象语法树(AST)
|
|
930
|
+
* 2. 转换阶段:使用 {@link transform} 将 Vue AST 转换为 React 中间表示(IR)
|
|
931
|
+
* 3. 生成阶段:使用 {@link generate} 将 React IR 生成为目标代码
|
|
932
|
+
* 4. 插件执行:在各阶段执行注册的插件,支持自定义扩展
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```typescript
|
|
936
|
+
* // 创建基础编译器实例
|
|
937
|
+
* const compiler = new BaseCompiler({
|
|
938
|
+
* cache: true,
|
|
939
|
+
* preprocessStyles: true,
|
|
940
|
+
* plugins: {
|
|
941
|
+
* parser: {
|
|
942
|
+
* myParserPlugin: (result, ctx) => {
|
|
943
|
+
* // 解析阶段插件
|
|
944
|
+
* }
|
|
945
|
+
* },
|
|
946
|
+
* transformer: {
|
|
947
|
+
* myTransformerPlugin: (result, ctx) => {
|
|
948
|
+
* // 转换阶段插件
|
|
949
|
+
* }
|
|
950
|
+
* }
|
|
951
|
+
* }
|
|
952
|
+
* });
|
|
953
|
+
*
|
|
954
|
+
* // 编译单个 Vue 文件
|
|
955
|
+
* const result = compiler.compile(vueSourceCode, '/path/to/Component.vue');
|
|
956
|
+
*
|
|
957
|
+
* // 获取编译结果
|
|
958
|
+
* console.log(result.fileInfo); // 包含 JSX 和 CSS 文件信息
|
|
959
|
+
* console.log(result.code); // 生成的 React 代码
|
|
960
|
+
* ```
|
|
961
|
+
*
|
|
962
|
+
* @remarks
|
|
963
|
+
* - 上下文管理:使用 {@link CompilationAdapter.createContext} 创建编译上下文
|
|
964
|
+
* - 错误处理:编译过程中的错误通过 {@link logger} 记录,不会抛出异常
|
|
965
|
+
* - 配置继承:继承 {@link Helper} 类的文件路径处理、缓存管理、格式化等工具方法
|
|
966
|
+
* - 版本管理:自动读取 package.json 中的版本号,便于调试和日志记录
|
|
967
|
+
*
|
|
968
|
+
* @see {@link FileCompiler} 用于文件系统级别的批量编译和增量构建
|
|
969
|
+
* @see {@link Helper} 提供基础的文件路径处理、缓存管理和格式化工具
|
|
970
|
+
* @see {@link CompilerOptions} 查看完整的编译器配置选项
|
|
971
|
+
* @see {@link CompilationResult} 编译结果的数据结构
|
|
972
|
+
*/
|
|
973
|
+
declare class BaseCompiler extends Helper {
|
|
974
|
+
version: string;
|
|
975
|
+
options: CompilerOptions;
|
|
976
|
+
private createContext;
|
|
977
|
+
/**
|
|
978
|
+
* 创建基础编译器实例
|
|
979
|
+
*
|
|
980
|
+
* @param options - 编译器配置选项,包括缓存设置、插件配置、样式预处理等,
|
|
981
|
+
* 所有选项都会传递给父类 {@link Helper} 进行初始化
|
|
982
|
+
*
|
|
983
|
+
* @see {@link CompilerOptions} 查看完整的配置选项说明
|
|
984
|
+
*/
|
|
985
|
+
constructor(options?: CompilerOptions);
|
|
986
|
+
/**
|
|
987
|
+
* 编译 Vue 源代码为 React 代码
|
|
988
|
+
*
|
|
989
|
+
* 该方法执行完整的编译流程,包括:
|
|
990
|
+
* 1. 上下文初始化:创建独立的编译上下文
|
|
991
|
+
* 2. 解析阶段:将 Vue 源代码解析为抽象语法树(AST)
|
|
992
|
+
* 3. 转换阶段:将 Vue AST 转换为 React 中间表示(IR)
|
|
993
|
+
* 4. 生成阶段:将 React IR 生成为目标代码
|
|
994
|
+
* 5. 插件执行:在各阶段执行注册的插件
|
|
995
|
+
* 6. 结果处理:整理编译结果并返回
|
|
996
|
+
*
|
|
997
|
+
* 编译过程使用 try-finally 确保上下文资源被正确清理,
|
|
998
|
+
* 即使编译过程中发生错误也不会导致资源泄漏。
|
|
999
|
+
*
|
|
1000
|
+
* @param source - Vue 源代码字符串
|
|
1001
|
+
* @param filename - 源文件名,用于生成文件ID和输出路径
|
|
1002
|
+
* @returns {CompilationResult} 编译结果,包含生成的代码和文件信息
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```typescript
|
|
1006
|
+
* const vueCode = `
|
|
1007
|
+
* <template>
|
|
1008
|
+
* <div class="container">{{ message }}</div>
|
|
1009
|
+
* </template>
|
|
1010
|
+
*
|
|
1011
|
+
* <script setup lang="ts">
|
|
1012
|
+
* import { ref } from 'vue;
|
|
1013
|
+
* const message = ref('Hello Vue')
|
|
1014
|
+
* </script>
|
|
1015
|
+
*
|
|
1016
|
+
* <style scoped>
|
|
1017
|
+
* .container {
|
|
1018
|
+
* padding: 20px;
|
|
1019
|
+
* }
|
|
1020
|
+
* </style>
|
|
1021
|
+
* `;
|
|
1022
|
+
*
|
|
1023
|
+
* const result = compiler.compile(vueCode, 'MyComponent.vue');
|
|
1024
|
+
* console.log(result.code); // 生成的 React JSX 代码
|
|
1025
|
+
* console.log(result.fileInfo.jsx.file); // 输出文件路径
|
|
1026
|
+
* ```
|
|
1027
|
+
*
|
|
1028
|
+
* @throws 不会直接抛出异常,错误通过日志系统记录
|
|
1029
|
+
* @see {@link parse} 解析函数
|
|
1030
|
+
* @see {@link transform} 转换函数
|
|
1031
|
+
* @see {@link generate} 生成函数
|
|
1032
|
+
* @see {@link executePlugins} 插件执行函数
|
|
1033
|
+
*/
|
|
1034
|
+
compile(source: string, filename: string): CompilationResult;
|
|
1035
|
+
/**
|
|
1036
|
+
* 处理 SFC 和 Script 文件的编译结果
|
|
1037
|
+
*
|
|
1038
|
+
* 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
|
|
1039
|
+
* 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
|
|
1040
|
+
* 对于 Script 文件,返回仅包含脚本信息的结果。
|
|
1041
|
+
*
|
|
1042
|
+
* 关键处理逻辑:
|
|
1043
|
+
* 1. 构建基础结果:包含文件ID、路由信息和生成的代码
|
|
1044
|
+
* 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
|
|
1045
|
+
* 3. 区分文件类型:
|
|
1046
|
+
* - SFC 文件:生成 .tsx 扩展名,包含样式信息
|
|
1047
|
+
* - Script 文件:保持原扩展名,不包含样式信息
|
|
1048
|
+
* 4. 样式处理:提取样式文件路径、作用域ID和样式代码
|
|
1049
|
+
*
|
|
1050
|
+
* @private
|
|
1051
|
+
* @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
|
|
1052
|
+
* @param gen - 代码生成结果,包含生成的代码和源码映射
|
|
1053
|
+
* @param ctxData - 编译上下文数据,包含文件信息和编译状态
|
|
1054
|
+
* @returns {CompilationResult} 整理后的编译结果
|
|
1055
|
+
*
|
|
1056
|
+
* @remarks
|
|
1057
|
+
* - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
|
|
1058
|
+
* - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
|
|
1059
|
+
* - 路由检测:自动检测组件是否使用路由,用于依赖注入
|
|
1060
|
+
* - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
|
|
1061
|
+
*
|
|
1062
|
+
* @see {@link SFCCompilationResult} SFC 编译结果类型
|
|
1063
|
+
* @see {@link ScriptCompilationResult} Script 编译结果类型
|
|
1064
|
+
*/
|
|
1065
|
+
private resolveResult;
|
|
1066
|
+
/**
|
|
1067
|
+
* 初始化 Babel 代码生成选项
|
|
1068
|
+
*
|
|
1069
|
+
* 合并用户自定义的生成选项与默认选项,确保代码生成的一致性和正确性。
|
|
1070
|
+
* 默认配置优化了代码的可读性和性能:
|
|
1071
|
+
* 1. 最小化 Unicode 转义:只转义必要的字符,保持代码可读性
|
|
1072
|
+
* 2. 统一引号风格:使用单引号,符合 JavaScript 社区常见约定
|
|
1073
|
+
* 3. 代码压缩:启用最小化,移除不必要的空白字符
|
|
1074
|
+
*
|
|
1075
|
+
* 如果用户提供了自定义选项,会与默认选项进行深度合并,
|
|
1076
|
+
* 用户选项的优先级高于默认选项。
|
|
1077
|
+
*
|
|
1078
|
+
* @private
|
|
1079
|
+
* @param filename - 可选的文件名,用于源码映射配置
|
|
1080
|
+
* @returns {GeneratorOptions} 合并后的 Babel 生成选项
|
|
1081
|
+
*
|
|
1082
|
+
* @remarks
|
|
1083
|
+
* - 源码映射支持:如果启用了 sourceMaps 且提供了文件名,会自动设置 sourceFileName
|
|
1084
|
+
* - 选项合并策略:用户选项会覆盖默认选项,实现灵活的配置
|
|
1085
|
+
* - 性能优化:默认启用 minified 以减少生成代码的体积
|
|
1086
|
+
* - 编码安全:使用 jsesc 确保特殊字符的正确转义
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* // 默认选项
|
|
1091
|
+
* const defaultOptions = {
|
|
1092
|
+
* jsescOption: { minimal: true, quotes: 'single' },
|
|
1093
|
+
* minified: true
|
|
1094
|
+
* };
|
|
1095
|
+
*
|
|
1096
|
+
* // 用户自定义选项
|
|
1097
|
+
* const userOptions = {
|
|
1098
|
+
* minified: false, // 覆盖默认值
|
|
1099
|
+
* sourceMaps: true // 新增选项
|
|
1100
|
+
* };
|
|
1101
|
+
*
|
|
1102
|
+
* // 合并结果
|
|
1103
|
+
* const merged = {
|
|
1104
|
+
* jsescOption: { minimal: true, quotes: 'single' },
|
|
1105
|
+
* minified: false, // 用户值
|
|
1106
|
+
* sourceMaps: true // 用户值
|
|
1107
|
+
* };
|
|
1108
|
+
* ```
|
|
1109
|
+
*
|
|
1110
|
+
* @see {@link GeneratorOptions} Babel 生成选项类型定义
|
|
1111
|
+
*/
|
|
1112
|
+
private prepareGenerateOptions;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* 文件系统编译器,负责将 Vue 项目批量转换为 React 项目。
|
|
1117
|
+
*
|
|
1118
|
+
* 此类继承自 {@link BaseCompiler},提供完整的文件系统级别编译功能,包括:
|
|
1119
|
+
* 1. 批量扫描和编译 Vue 单文件组件(SFC)
|
|
1120
|
+
* 2. 处理 JavaScript/TypeScript 脚本文件
|
|
1121
|
+
* 3. 资源文件(图片、样式、字体等)的智能拷贝
|
|
1122
|
+
* 4. 增量编译和高效的缓存管理
|
|
1123
|
+
* 5. 文件系统监控和自动清理
|
|
1124
|
+
* 6. Vite 项目环境自动初始化
|
|
1125
|
+
*
|
|
1126
|
+
* 主要特性:
|
|
1127
|
+
* - 增量编译:基于文件哈希、大小和修改时间进行变更检测,跳过未变更的文件
|
|
1128
|
+
* - 智能缓存:维护编译缓存,支持清理过期文件,提高编译效率
|
|
1129
|
+
* - 资源处理:自动识别并拷贝非编译文件,保持目录结构
|
|
1130
|
+
* - 错误隔离:单个文件编译失败不影响其他文件处理
|
|
1131
|
+
* - 并发处理:支持 Promise.all 并发处理多个文件,提升编译速度
|
|
1132
|
+
* - 路由感知:自动检测并注入 Vue Router 到 React Router 的转换依赖
|
|
1133
|
+
*
|
|
1134
|
+
* 架构设计:
|
|
1135
|
+
* 该类采用管理器模式,将不同职责分解到独立的子管理器中:
|
|
1136
|
+
* - {@link PipelineManager}: 管理编译管线流程
|
|
1137
|
+
* - {@link FileProcessor}: 处理单个文件的编译逻辑
|
|
1138
|
+
* - {@link CacheManager}: 管理编译缓存
|
|
1139
|
+
* - {@link AssetManager}: 处理资源文件拷贝
|
|
1140
|
+
* - {@link CleanupManager}: 清理过期文件和缓存
|
|
1141
|
+
* - {@link ViteBootstrapper}: 初始化 Vite React 项目环境
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```typescript
|
|
1145
|
+
* // 创建文件编译器实例
|
|
1146
|
+
* const compiler = new FileCompiler({
|
|
1147
|
+
* input: 'src',
|
|
1148
|
+
* exclude: ['src/main.ts'],
|
|
1149
|
+
* output: {
|
|
1150
|
+
* workspace: '.vureact',
|
|
1151
|
+
* outDir: 'react-app',
|
|
1152
|
+
* bootstrapVite: true
|
|
1153
|
+
* },
|
|
1154
|
+
* cache: true,
|
|
1155
|
+
* watch: false
|
|
1156
|
+
* });
|
|
1157
|
+
*
|
|
1158
|
+
* // 执行完整编译
|
|
1159
|
+
* await compiler.execute();
|
|
1160
|
+
*
|
|
1161
|
+
* // 处理单个 Vue 文件(适用于 watch 模式)
|
|
1162
|
+
* await compiler.processSFC('/path/to/Component.vue');
|
|
1163
|
+
*
|
|
1164
|
+
* // 处理单个 Script 文件
|
|
1165
|
+
* await compiler.processScript('/path/to/foo.ts');
|
|
1166
|
+
*
|
|
1167
|
+
* // 处理单个资源文件
|
|
1168
|
+
* await compiler.processAsset('/path/to/image.png');
|
|
1169
|
+
*
|
|
1170
|
+
* // 清理指定路径的输出文件
|
|
1171
|
+
* await compiler.removeOutputPath('/path/to/old-component.vue', CacheKey.SFC);
|
|
1172
|
+
* ```
|
|
1173
|
+
*
|
|
1174
|
+
* @remarks
|
|
1175
|
+
* - 编译流程:遵循 "环境初始化 → SFC编译 → Script编译 → 资源拷贝" 的顺序
|
|
1176
|
+
* - 缓存机制:使用文件哈希、大小和修改时间三重验证确保准确性
|
|
1177
|
+
* - 目录结构:保持输入目录结构到输出目录,便于项目迁移
|
|
1178
|
+
* - 错误处理:编译错误会记录到日志系统,但不会中断整个编译流程
|
|
1179
|
+
* - 性能优化:支持并发处理和增量编译,大幅提升大型项目编译速度
|
|
1180
|
+
*
|
|
1181
|
+
* @see {@link BaseCompiler} 提供核心的单文件编译功能
|
|
1182
|
+
* @see {@link Helper} 提供基础的文件路径处理和工具方法
|
|
1183
|
+
* @see {@link CompilerOptions} 完整的编译器配置选项
|
|
1184
|
+
*/
|
|
1185
|
+
declare class FileCompiler extends BaseCompiler {
|
|
1186
|
+
private skippedCount;
|
|
1187
|
+
private spinner;
|
|
1188
|
+
private viteBootstrapper;
|
|
1189
|
+
private pipelineManager;
|
|
1190
|
+
private fileProcessor;
|
|
1191
|
+
private compilationUnitProcessor;
|
|
1192
|
+
private cacheManager;
|
|
1193
|
+
private assetManager;
|
|
1194
|
+
private cleanupManager;
|
|
1195
|
+
/**
|
|
1196
|
+
* 创建文件系统编译器实例
|
|
1197
|
+
*
|
|
1198
|
+
* @param options - 编译器配置选项,继承自 BaseCompiler 的选项
|
|
1199
|
+
* 包括输入路径、输出配置、缓存设置、排除模式等
|
|
1200
|
+
* @see {@link CompilerOptions} 查看完整的选项说明
|
|
1201
|
+
*/
|
|
1202
|
+
constructor(options?: CompilerOptions);
|
|
1203
|
+
/**
|
|
1204
|
+
* 初始化所有管理器实例
|
|
1205
|
+
*
|
|
1206
|
+
* 按照依赖关系顺序创建各个管理器:
|
|
1207
|
+
* 1. 基础管理器(无依赖)
|
|
1208
|
+
* 2. 依赖基础管理器的管理器
|
|
1209
|
+
* 3. 依赖其他管理器的管理器
|
|
1210
|
+
*
|
|
1211
|
+
* @private
|
|
1212
|
+
*/
|
|
1213
|
+
private initializeManagers;
|
|
1214
|
+
/**
|
|
1215
|
+
* 执行完整的编译流程
|
|
1216
|
+
*
|
|
1217
|
+
* 该方法执行以下步骤:
|
|
1218
|
+
* 1. 环境初始化:清理旧输出(如果禁用缓存)并初始化 Vite 项目环境
|
|
1219
|
+
* 2. Vue 文件编译:批量处理所有 .vue 文件
|
|
1220
|
+
* 3. Script 文件编译:批量处理所有 .js/.ts 文件
|
|
1221
|
+
* 4. 资源文件拷贝:处理剩余的非编译文件
|
|
1222
|
+
* 5. 统计输出:显示编译结果和性能统计
|
|
1223
|
+
*
|
|
1224
|
+
* @async
|
|
1225
|
+
* @throws {Error} 当编译过程中发生致命错误时抛出
|
|
1226
|
+
* @returns {Promise<void>}
|
|
1227
|
+
*/
|
|
1228
|
+
execute(): Promise<void>;
|
|
1229
|
+
/**
|
|
1230
|
+
* 处理单个 Vue 单文件组件(SFC)
|
|
1231
|
+
*
|
|
1232
|
+
* 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
|
|
1233
|
+
* 支持增量编译,如果文件未变更则跳过编译。
|
|
1234
|
+
*
|
|
1235
|
+
* @async
|
|
1236
|
+
* @param filePath - Vue 文件的绝对路径
|
|
1237
|
+
* @param existingCache - 可选的预加载缓存对象,用于增量编译
|
|
1238
|
+
* @returns {Promise<SFCUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
|
|
1239
|
+
* @see {@link FileProcessor.processSFC}
|
|
1240
|
+
*/
|
|
1241
|
+
processSFC(filePath: string, existingCache?: LoadedCache<Vue2ReactCacheMeta>): Promise<SFCUnit | undefined>;
|
|
1242
|
+
/**
|
|
1243
|
+
* 处理单个 JavaScript/TypeScript 脚本文件
|
|
1244
|
+
*
|
|
1245
|
+
* 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
|
|
1246
|
+
* 支持增量编译,如果文件未变更则跳过编译。
|
|
1247
|
+
*
|
|
1248
|
+
* @async
|
|
1249
|
+
* @param filePath - 脚本文件的绝对路径
|
|
1250
|
+
* @param existingCache - 可选的预加载缓存对象,用于增量编译
|
|
1251
|
+
* @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
|
|
1252
|
+
* @see {@link FileProcessor.processScript}
|
|
1253
|
+
*/
|
|
1254
|
+
processScript(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<ScriptUnit | undefined>;
|
|
1255
|
+
/**
|
|
1256
|
+
* 处理单个文件(Vue 或 Script)
|
|
1257
|
+
*
|
|
1258
|
+
* 通用的文件处理方法,根据 CacheKey 类型自动选择处理逻辑。
|
|
1259
|
+
* 主要用于内部调用和统一的文件处理接口。
|
|
1260
|
+
*
|
|
1261
|
+
* @async
|
|
1262
|
+
* @param key - 文件类型标识(SFC 或 SCRIPT)
|
|
1263
|
+
* @param filePath - 文件的绝对路径
|
|
1264
|
+
* @param existingCache - 可选的预加载缓存对象
|
|
1265
|
+
* @returns {Promise<SFCUnit | ScriptUnit | undefined>} 编译单元对象
|
|
1266
|
+
* @see {@link FileProcessor.processFile}
|
|
1267
|
+
*/
|
|
1268
|
+
processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise<SFCUnit | ScriptUnit | undefined>;
|
|
1269
|
+
/**
|
|
1270
|
+
* 处理单个资源文件
|
|
1271
|
+
*
|
|
1272
|
+
* 比较文件与缓存,决定是否需要拷贝。
|
|
1273
|
+
* 资源文件包括图片、字体、样式文件等非编译文件。
|
|
1274
|
+
*
|
|
1275
|
+
* @async
|
|
1276
|
+
* @param filePath - 资源文件的绝对路径
|
|
1277
|
+
* @param existingCache - 可选的预加载缓存对象
|
|
1278
|
+
* @returns {Promise<FileCacheMeta>} 资源文件的缓存元数据
|
|
1279
|
+
* @see {@link AssetManager.processAsset}
|
|
1280
|
+
*/
|
|
1281
|
+
processAsset(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<FileCacheMeta>;
|
|
1282
|
+
/**
|
|
1283
|
+
* 删除指定路径对应的输出文件和缓存
|
|
1284
|
+
*
|
|
1285
|
+
* 当源文件被删除或重命名时,需要清理对应的输出文件。
|
|
1286
|
+
* 主要用于 watch 模式下的文件删除处理。
|
|
1287
|
+
*
|
|
1288
|
+
* @async
|
|
1289
|
+
* @param targetPath - 源代码的路径(文件或文件夹)
|
|
1290
|
+
* @param type - 清理类型,指定是 SFC、SCRIPT 还是 ASSET
|
|
1291
|
+
* @returns {Promise<void>}
|
|
1292
|
+
* @see {@link CleanupManager.removeOutputPath}
|
|
1293
|
+
*/
|
|
1294
|
+
removeOutputPath(targetPath: string, type: CacheKey): Promise<void>;
|
|
1295
|
+
/**
|
|
1296
|
+
* 获取跳过的文件数量
|
|
1297
|
+
*
|
|
1298
|
+
* 在增量编译中,未变更的文件会被跳过。
|
|
1299
|
+
* 此方法返回当前编译会话中跳过的文件数量。
|
|
1300
|
+
*
|
|
1301
|
+
* @returns {number} 跳过的文件数量
|
|
1302
|
+
*/
|
|
1303
|
+
getSkippedCount(): number;
|
|
1304
|
+
/**
|
|
1305
|
+
* 重置跳过的文件数量
|
|
1306
|
+
*
|
|
1307
|
+
* 在每次新的编译会话开始时调用,重置计数器。
|
|
1308
|
+
*/
|
|
1309
|
+
resetSkippedCount(): void;
|
|
1310
|
+
/**
|
|
1311
|
+
* 显示编译统计信息
|
|
1312
|
+
*
|
|
1313
|
+
* 在编译完成后调用,显示以下信息:
|
|
1314
|
+
* 1. 编译耗时
|
|
1315
|
+
* 2. 输出目录
|
|
1316
|
+
* 3. 跳过的文件数量
|
|
1317
|
+
* 4. 处理的文件分类统计
|
|
1318
|
+
*
|
|
1319
|
+
* @private
|
|
1320
|
+
* @param endTime - 格式化后的编译耗时字符串
|
|
1321
|
+
* @param sfcCount - 处理的 Vue 文件数量
|
|
1322
|
+
* @param scriptCount - 处理的脚本文件数量
|
|
1323
|
+
* @param assetCount - 处理的资源文件数量
|
|
1324
|
+
*/
|
|
1325
|
+
private showCompileStats;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* @see {@link CompilerOptions}
|
|
1330
|
+
*/
|
|
1331
|
+
declare function defineConfig(options: CompilerOptions): CompilerOptions;
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Next Vue to React compiler, compiles Vue 3 syntax into runnable React 18+ code.
|
|
1335
|
+
*
|
|
1336
|
+
* @extends FileCompiler
|
|
1337
|
+
*
|
|
1338
|
+
* @see {@link FileCompiler}
|
|
1339
|
+
* @see https://vureact.top
|
|
1340
|
+
*/
|
|
1341
|
+
declare class VuReact extends FileCompiler {
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type CacheCheckResult, CacheKey, type CacheList, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type FileCacheMeta, FileCompiler, type FileMeta, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type SFCCompilationResult, type SFCUnit, type ScriptCompilationResult, type ScriptUnit, type TransformerOptions, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };
|