@wevu/compiler 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +225 -0
- package/dist/index.mjs +138 -0
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,13 @@ import * as t from "@babel/types";
|
|
|
4
4
|
import { Expression } from "@babel/types";
|
|
5
5
|
|
|
6
6
|
//#region src/auto-import-components/builtin.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 内置组件集合(来自自动生成的组件列表)。
|
|
9
|
+
*/
|
|
7
10
|
declare const builtinComponentsSet: Set<string>;
|
|
11
|
+
/**
|
|
12
|
+
* 判断标签是否为内置组件。
|
|
13
|
+
*/
|
|
8
14
|
declare function isBuiltinComponent(tag: string): boolean;
|
|
9
15
|
//#endregion
|
|
10
16
|
//#region src/constants.d.ts
|
|
@@ -20,7 +26,13 @@ declare const WE_VU_PAGE_HOOK_TO_FEATURE: {
|
|
|
20
26
|
readonly onAddToFavorites: "enableOnAddToFavorites";
|
|
21
27
|
readonly onSaveExitState: "enableOnSaveExitState";
|
|
22
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* wevu 运行时模块 ID。
|
|
31
|
+
*/
|
|
23
32
|
declare const WE_VU_MODULE_ID: "wevu";
|
|
33
|
+
/**
|
|
34
|
+
* wevu 运行时 API 名称映射。
|
|
35
|
+
*/
|
|
24
36
|
declare const WE_VU_RUNTIME_APIS: {
|
|
25
37
|
readonly createApp: "createApp";
|
|
26
38
|
readonly createWevuComponent: "createWevuComponent";
|
|
@@ -28,6 +40,9 @@ declare const WE_VU_RUNTIME_APIS: {
|
|
|
28
40
|
readonly defineComponent: "defineComponent";
|
|
29
41
|
readonly setWevuDefaults: "setWevuDefaults";
|
|
30
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* wevu 运行时 API 名称类型。
|
|
45
|
+
*/
|
|
31
46
|
type WevuRuntimeApiName = (typeof WE_VU_RUNTIME_APIS)[keyof typeof WE_VU_RUNTIME_APIS];
|
|
32
47
|
//#endregion
|
|
33
48
|
//#region src/plugins/utils/cache.d.ts
|
|
@@ -46,13 +61,25 @@ declare function readFile(id: string, options?: {
|
|
|
46
61
|
checkMtime?: boolean;
|
|
47
62
|
encoding?: BufferEncoding;
|
|
48
63
|
}): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* 判断文件或路径是否存在,可选缓存。
|
|
66
|
+
*/
|
|
49
67
|
declare function pathExists(id: string, options?: {
|
|
50
68
|
ttlMs?: number;
|
|
51
69
|
}): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* 清理指定文件相关的缓存。
|
|
72
|
+
*/
|
|
52
73
|
declare function invalidateFileCache(id: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* 清空所有文件缓存。
|
|
76
|
+
*/
|
|
53
77
|
declare function clearFileCaches(): void;
|
|
54
78
|
//#endregion
|
|
55
79
|
//#region src/plugins/utils/vueSfc.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* 读取并解析 SFC 的配置。
|
|
82
|
+
*/
|
|
56
83
|
interface ReadAndParseSfcOptions {
|
|
57
84
|
/**
|
|
58
85
|
* 直接传入源码以跳过文件读取。
|
|
@@ -67,6 +94,9 @@ interface ReadAndParseSfcOptions {
|
|
|
67
94
|
*/
|
|
68
95
|
resolveSrc?: ResolveSfcBlockSrcOptions;
|
|
69
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* 解析 SFC block `src` 的配置。
|
|
99
|
+
*/
|
|
70
100
|
interface ResolveSfcBlockSrcOptions {
|
|
71
101
|
resolveId?: (source: string, importer?: string) => Promise<string | undefined>;
|
|
72
102
|
readFile?: (id: string, options?: {
|
|
@@ -74,30 +104,57 @@ interface ResolveSfcBlockSrcOptions {
|
|
|
74
104
|
}) => Promise<string>;
|
|
75
105
|
checkMtime?: boolean;
|
|
76
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* 预处理 `<script setup src>`,避免编译器丢失 src。
|
|
109
|
+
*/
|
|
77
110
|
declare function preprocessScriptSetupSrc(source: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* 预处理普通 `<script src>`,避免编译器丢失 src。
|
|
113
|
+
*/
|
|
78
114
|
declare function preprocessScriptSrc(source: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* 将预处理的 `<script setup src>` 恢复为真实 src。
|
|
117
|
+
*/
|
|
79
118
|
declare function restoreScriptSetupSrc(descriptor: SFCDescriptor): void;
|
|
119
|
+
/**
|
|
120
|
+
* 将预处理的 `<script src>` 恢复为真实 src。
|
|
121
|
+
*/
|
|
80
122
|
declare function restoreScriptSrc(descriptor: SFCDescriptor): void;
|
|
123
|
+
/**
|
|
124
|
+
* 解析 SFC 中带 `src` 的 block,并返回依赖列表。
|
|
125
|
+
*/
|
|
81
126
|
declare function resolveSfcBlockSrc(descriptor: SFCDescriptor, filename: string, options?: ResolveSfcBlockSrcOptions): Promise<{
|
|
82
127
|
descriptor: SFCDescriptor;
|
|
83
128
|
deps: string[];
|
|
84
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* 读取并解析 SFC,支持缓存与 src 解析。
|
|
132
|
+
*/
|
|
85
133
|
declare function readAndParseSfc(filename: string, options?: ReadAndParseSfcOptions): Promise<{
|
|
86
134
|
source: string;
|
|
87
135
|
descriptor: SFCDescriptor;
|
|
88
136
|
errors: SFCParseResult['errors'];
|
|
89
137
|
}>;
|
|
138
|
+
/**
|
|
139
|
+
* 获取 SFC 读取时是否检查 mtime 的策略。
|
|
140
|
+
*/
|
|
90
141
|
declare function getSfcCheckMtime(config?: {
|
|
91
142
|
isDev?: boolean;
|
|
92
143
|
}): boolean;
|
|
93
144
|
//#endregion
|
|
94
145
|
//#region src/plugins/vue/compiler/style.d.ts
|
|
146
|
+
/**
|
|
147
|
+
* 样式编译结果。
|
|
148
|
+
*/
|
|
95
149
|
interface StyleCompileResult {
|
|
96
150
|
code: string;
|
|
97
151
|
map?: string;
|
|
98
152
|
scopedId?: string;
|
|
99
153
|
modules?: Record<string, Record<string, string>>;
|
|
100
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* 样式编译选项。
|
|
157
|
+
*/
|
|
101
158
|
interface StyleCompileOptions {
|
|
102
159
|
id: string;
|
|
103
160
|
scoped?: boolean;
|
|
@@ -110,6 +167,9 @@ interface StyleCompileOptions {
|
|
|
110
167
|
declare function compileVueStyleToWxss(styleBlock: SFCStyleBlock, options: StyleCompileOptions): StyleCompileResult;
|
|
111
168
|
//#endregion
|
|
112
169
|
//#region src/plugins/vue/compiler/template/platform.d.ts
|
|
170
|
+
/**
|
|
171
|
+
* 小程序模板平台适配器定义。
|
|
172
|
+
*/
|
|
113
173
|
interface MiniProgramPlatform {
|
|
114
174
|
name: string;
|
|
115
175
|
wrapIf: (exp: string, content: string) => string;
|
|
@@ -123,6 +183,9 @@ interface MiniProgramPlatform {
|
|
|
123
183
|
}
|
|
124
184
|
//#endregion
|
|
125
185
|
//#region src/plugins/vue/compiler/template/types.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* 作用域插槽组件资源描述。
|
|
188
|
+
*/
|
|
126
189
|
interface ScopedSlotComponentAsset {
|
|
127
190
|
id: string;
|
|
128
191
|
componentName: string;
|
|
@@ -132,11 +195,17 @@ interface ScopedSlotComponentAsset {
|
|
|
132
195
|
classStyleWxs?: boolean;
|
|
133
196
|
inlineExpressions?: InlineExpressionAsset[];
|
|
134
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* 内联表达式资源描述。
|
|
200
|
+
*/
|
|
135
201
|
interface InlineExpressionAsset {
|
|
136
202
|
id: string;
|
|
137
203
|
expression: string;
|
|
138
204
|
scopeKeys: string[];
|
|
139
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* 模板编译结果。
|
|
208
|
+
*/
|
|
140
209
|
interface TemplateCompileResult {
|
|
141
210
|
code: string;
|
|
142
211
|
warnings: string[];
|
|
@@ -148,6 +217,9 @@ interface TemplateCompileResult {
|
|
|
148
217
|
templateRefs?: TemplateRefBinding[];
|
|
149
218
|
inlineExpressions?: InlineExpressionAsset[];
|
|
150
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* v-for 解析结果。
|
|
222
|
+
*/
|
|
151
223
|
interface ForParseResult {
|
|
152
224
|
listExp?: string;
|
|
153
225
|
listExpAst?: Expression;
|
|
@@ -155,6 +227,9 @@ interface ForParseResult {
|
|
|
155
227
|
index?: string;
|
|
156
228
|
key?: string;
|
|
157
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* 模板编译选项。
|
|
232
|
+
*/
|
|
158
233
|
interface TemplateCompileOptions {
|
|
159
234
|
platform?: MiniProgramPlatform;
|
|
160
235
|
scopedSlotsCompiler?: ScopedSlotsCompilerMode;
|
|
@@ -164,8 +239,17 @@ interface TemplateCompileOptions {
|
|
|
164
239
|
wxsExtension?: string;
|
|
165
240
|
classStyleWxsSrc?: string;
|
|
166
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* 作用域插槽编译模式。
|
|
244
|
+
*/
|
|
167
245
|
type ScopedSlotsCompilerMode = 'auto' | 'augmented' | 'off';
|
|
246
|
+
/**
|
|
247
|
+
* class/style 运行时模式。
|
|
248
|
+
*/
|
|
168
249
|
type ClassStyleRuntime = 'wxs' | 'js';
|
|
250
|
+
/**
|
|
251
|
+
* class/style 绑定信息。
|
|
252
|
+
*/
|
|
169
253
|
interface ClassStyleBinding {
|
|
170
254
|
name: string;
|
|
171
255
|
type: 'class' | 'style';
|
|
@@ -173,6 +257,9 @@ interface ClassStyleBinding {
|
|
|
173
257
|
expAst?: Expression;
|
|
174
258
|
forStack: ForParseResult[];
|
|
175
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* template ref 绑定信息。
|
|
262
|
+
*/
|
|
176
263
|
interface TemplateRefBinding {
|
|
177
264
|
selector: string;
|
|
178
265
|
inFor: boolean;
|
|
@@ -182,30 +269,63 @@ interface TemplateRefBinding {
|
|
|
182
269
|
}
|
|
183
270
|
//#endregion
|
|
184
271
|
//#region src/types/platform.d.ts
|
|
272
|
+
/**
|
|
273
|
+
* 小程序平台标识。
|
|
274
|
+
*/
|
|
185
275
|
type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
|
|
186
276
|
//#endregion
|
|
187
277
|
//#region src/plugins/vue/compiler/template/platforms/alipay.d.ts
|
|
278
|
+
/**
|
|
279
|
+
* 支付宝小程序平台适配器。
|
|
280
|
+
*/
|
|
188
281
|
declare const alipayPlatform: MiniProgramPlatform;
|
|
189
282
|
//#endregion
|
|
190
283
|
//#region src/plugins/vue/compiler/template/platforms/swan.d.ts
|
|
284
|
+
/**
|
|
285
|
+
* 百度智能小程序平台适配器。
|
|
286
|
+
*/
|
|
191
287
|
declare const swanPlatform: MiniProgramPlatform;
|
|
192
288
|
//#endregion
|
|
193
289
|
//#region src/plugins/vue/compiler/template/platforms/tt.d.ts
|
|
290
|
+
/**
|
|
291
|
+
* 抖音小程序平台适配器。
|
|
292
|
+
*/
|
|
194
293
|
declare const ttPlatform: MiniProgramPlatform;
|
|
195
294
|
//#endregion
|
|
196
295
|
//#region src/plugins/vue/compiler/template/platforms/wechat.d.ts
|
|
296
|
+
/**
|
|
297
|
+
* 微信小程序平台适配器。
|
|
298
|
+
*/
|
|
197
299
|
declare const wechatPlatform: MiniProgramPlatform;
|
|
198
300
|
//#endregion
|
|
199
301
|
//#region src/plugins/vue/compiler/template/platforms/index.d.ts
|
|
302
|
+
/**
|
|
303
|
+
* 获取指定平台的模板适配器,默认回退到 wechat。
|
|
304
|
+
*/
|
|
200
305
|
declare function getMiniProgramTemplatePlatform(platform?: MpPlatform): MiniProgramPlatform;
|
|
201
306
|
//#endregion
|
|
202
307
|
//#region src/plugins/vue/compiler/template.d.ts
|
|
308
|
+
/**
|
|
309
|
+
* 将 Vue 模板编译为 WXML。
|
|
310
|
+
*/
|
|
203
311
|
declare function compileVueTemplateToWxml(template: string, filename: string, options?: TemplateCompileOptions): TemplateCompileResult;
|
|
204
312
|
//#endregion
|
|
205
313
|
//#region src/plugins/vue/compiler/template/classStyleRuntime.d.ts
|
|
314
|
+
/**
|
|
315
|
+
* class/style WXS 模块名。
|
|
316
|
+
*/
|
|
206
317
|
declare const CLASS_STYLE_WXS_MODULE = "__weapp_vite";
|
|
318
|
+
/**
|
|
319
|
+
* class/style WXS 文件名(不含扩展名)。
|
|
320
|
+
*/
|
|
207
321
|
declare const CLASS_STYLE_WXS_FILE = "__weapp_vite_class_style";
|
|
322
|
+
/**
|
|
323
|
+
* 构建 class/style WXS 引用标签。
|
|
324
|
+
*/
|
|
208
325
|
declare function buildClassStyleWxsTag(extension: string, src?: string): string;
|
|
326
|
+
/**
|
|
327
|
+
* 解析 class/style WXS 文件位置与引用路径。
|
|
328
|
+
*/
|
|
209
329
|
declare function resolveClassStyleWxsLocation(options: {
|
|
210
330
|
relativeBase: string;
|
|
211
331
|
extension: string;
|
|
@@ -214,6 +334,9 @@ declare function resolveClassStyleWxsLocation(options: {
|
|
|
214
334
|
fileName: string;
|
|
215
335
|
src: string;
|
|
216
336
|
};
|
|
337
|
+
/**
|
|
338
|
+
* 获取内置 class/style WXS 运行时代码。
|
|
339
|
+
*/
|
|
217
340
|
declare function getClassStyleWxsSource(): string;
|
|
218
341
|
//#endregion
|
|
219
342
|
//#region src/plugins/vue/transform/classStyleComputed.d.ts
|
|
@@ -224,14 +347,29 @@ interface ClassStyleHelperNames {
|
|
|
224
347
|
declare function buildClassStyleComputedCode(bindings: ClassStyleBinding[], helpers: ClassStyleHelperNames): string | null;
|
|
225
348
|
//#endregion
|
|
226
349
|
//#region src/types/json.d.ts
|
|
350
|
+
/**
|
|
351
|
+
* JSON 合并阶段枚举。
|
|
352
|
+
*/
|
|
227
353
|
type JsonMergeStage = 'defaults' | 'json-block' | 'auto-using-components' | 'component-generics' | 'macro' | 'emit' | 'merge-existing';
|
|
354
|
+
/**
|
|
355
|
+
* JSON 合并上下文。
|
|
356
|
+
*/
|
|
228
357
|
interface JsonMergeContext {
|
|
229
358
|
filename?: string;
|
|
230
359
|
kind?: 'app' | 'page' | 'component' | 'unknown';
|
|
231
360
|
stage: JsonMergeStage;
|
|
232
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* JSON 合并函数。
|
|
364
|
+
*/
|
|
233
365
|
type JsonMergeFunction = (target: Record<string, any>, source: Record<string, any>, context: JsonMergeContext) => Record<string, any> | void;
|
|
366
|
+
/**
|
|
367
|
+
* JSON 合并策略。
|
|
368
|
+
*/
|
|
234
369
|
type JsonMergeStrategy = 'deep' | 'assign' | 'replace' | JsonMergeFunction;
|
|
370
|
+
/**
|
|
371
|
+
* JSON 产物配置。
|
|
372
|
+
*/
|
|
235
373
|
interface JsonConfig {
|
|
236
374
|
/**
|
|
237
375
|
* 产物 JSON 默认值(用于 app/page/component)
|
|
@@ -252,12 +390,18 @@ interface JsonConfig {
|
|
|
252
390
|
}
|
|
253
391
|
//#endregion
|
|
254
392
|
//#region src/types/wevu.d.ts
|
|
393
|
+
/**
|
|
394
|
+
* wevu JSON 默认值配置(app/component)。
|
|
395
|
+
*/
|
|
255
396
|
interface WevuDefaults {
|
|
256
397
|
app?: Record<string, any>;
|
|
257
398
|
component?: Record<string, any>;
|
|
258
399
|
}
|
|
259
400
|
//#endregion
|
|
260
401
|
//#region src/plugins/vue/transform/compileVueFile/types.d.ts
|
|
402
|
+
/**
|
|
403
|
+
* Vue 单文件组件转换结果。
|
|
404
|
+
*/
|
|
261
405
|
interface VueTransformResult {
|
|
262
406
|
script?: string;
|
|
263
407
|
template?: string;
|
|
@@ -275,6 +419,9 @@ interface VueTransformResult {
|
|
|
275
419
|
sfcSrcDeps?: string[];
|
|
276
420
|
};
|
|
277
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* 自动生成 usingComponents 选项。
|
|
424
|
+
*/
|
|
278
425
|
interface AutoUsingComponentsOptions {
|
|
279
426
|
enabled?: boolean;
|
|
280
427
|
resolveUsingComponentPath?: (importSource: string, importerFilename: string, info?: {
|
|
@@ -284,6 +431,9 @@ interface AutoUsingComponentsOptions {
|
|
|
284
431
|
}) => Promise<string | undefined>;
|
|
285
432
|
warn?: (message: string) => void;
|
|
286
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* 自动导入模板标签组件选项。
|
|
436
|
+
*/
|
|
287
437
|
interface AutoImportTagsOptions {
|
|
288
438
|
enabled?: boolean;
|
|
289
439
|
resolveUsingComponent?: (tag: string, importerFilename: string) => Promise<{
|
|
@@ -292,6 +442,9 @@ interface AutoImportTagsOptions {
|
|
|
292
442
|
} | undefined>;
|
|
293
443
|
warn?: (message: string) => void;
|
|
294
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* 编译 Vue SFC 的选项集合。
|
|
447
|
+
*/
|
|
295
448
|
interface CompileVueFileOptions {
|
|
296
449
|
isPage?: boolean;
|
|
297
450
|
isApp?: boolean;
|
|
@@ -309,22 +462,49 @@ interface CompileVueFileOptions {
|
|
|
309
462
|
}
|
|
310
463
|
//#endregion
|
|
311
464
|
//#region src/plugins/vue/transform/compileVueFile/index.d.ts
|
|
465
|
+
/**
|
|
466
|
+
* 编译 Vue 单文件组件,输出脚本、模板、样式与配置结果。
|
|
467
|
+
*/
|
|
312
468
|
declare function compileVueFile(source: string, filename: string, options?: CompileVueFileOptions): Promise<VueTransformResult>;
|
|
313
469
|
//#endregion
|
|
314
470
|
//#region src/plugins/vue/transform/config.d.ts
|
|
471
|
+
/**
|
|
472
|
+
* JS 配置块的语言类型。
|
|
473
|
+
*/
|
|
315
474
|
type JsLikeLang = 'js' | 'ts';
|
|
475
|
+
/**
|
|
476
|
+
* 规范化配置块语言。
|
|
477
|
+
*/
|
|
316
478
|
declare function normalizeConfigLang(lang?: string): string;
|
|
479
|
+
/**
|
|
480
|
+
* 判断是否为 JSON 类语言。
|
|
481
|
+
*/
|
|
317
482
|
declare function isJsonLikeLang(lang: string): lang is "json" | "jsonc" | "json5";
|
|
483
|
+
/**
|
|
484
|
+
* 将语言标识归一为 js/ts。
|
|
485
|
+
*/
|
|
318
486
|
declare function resolveJsLikeLang(lang: string): JsLikeLang;
|
|
487
|
+
/**
|
|
488
|
+
* 执行 JS/TS 配置块并返回对象结果。
|
|
489
|
+
*/
|
|
319
490
|
declare function evaluateJsLikeConfig(source: string, filename: string, lang: string): Promise<any>;
|
|
491
|
+
/**
|
|
492
|
+
* 编译 SFC 内的 <json> 配置块并返回 JSON 字符串。
|
|
493
|
+
*/
|
|
320
494
|
declare function compileConfigBlocks(blocks: SFCBlock[], filename: string, options?: {
|
|
321
495
|
merge?: (target: Record<string, any>, source: Record<string, any>) => Record<string, any> | void;
|
|
322
496
|
}): Promise<string | undefined>;
|
|
323
497
|
//#endregion
|
|
324
498
|
//#region src/plugins/vue/transform/jsonMacros/rewrite.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* 从任意代码中剥离 JSON 宏调用。
|
|
501
|
+
*/
|
|
325
502
|
declare function stripJsonMacroCallsFromCode(code: string, filename: string): string;
|
|
326
503
|
//#endregion
|
|
327
504
|
//#region src/plugins/vue/transform/jsonMacros/index.d.ts
|
|
505
|
+
/**
|
|
506
|
+
* 从 `<script setup>` 中提取 JSON 宏配置并返回剥离后的代码。
|
|
507
|
+
*/
|
|
328
508
|
declare function extractJsonMacroFromScriptSetup(content: string, filename: string, lang?: string, options?: {
|
|
329
509
|
merge?: (target: Record<string, any>, source: Record<string, any>) => Record<string, any> | void;
|
|
330
510
|
}): Promise<{
|
|
@@ -335,7 +515,13 @@ declare function extractJsonMacroFromScriptSetup(content: string, filename: stri
|
|
|
335
515
|
}>;
|
|
336
516
|
//#endregion
|
|
337
517
|
//#region src/plugins/vue/transform/jsonMerge.d.ts
|
|
518
|
+
/**
|
|
519
|
+
* 按策略合并 JSON 配置对象。
|
|
520
|
+
*/
|
|
338
521
|
declare function mergeJsonWithStrategy(target: Record<string, any>, source: Record<string, any>, strategy: JsonMergeStrategy | undefined, context: JsonMergeContext): Record<string, any>;
|
|
522
|
+
/**
|
|
523
|
+
* 创建带上下文的 JSON 合并函数。
|
|
524
|
+
*/
|
|
339
525
|
declare function createJsonMerger(strategy: JsonMergeStrategy | undefined, baseContext: Omit<JsonMergeContext, 'stage'>): (target: Record<string, any>, source: Record<string, any>, stage: JsonMergeContext["stage"]) => Record<string, any>;
|
|
340
526
|
//#endregion
|
|
341
527
|
//#region src/plugins/vue/transform/scopedId.d.ts
|
|
@@ -400,25 +586,49 @@ interface TransformScriptOptions {
|
|
|
400
586
|
}
|
|
401
587
|
//#endregion
|
|
402
588
|
//#region src/plugins/vue/transform/transformScript/index.d.ts
|
|
589
|
+
/**
|
|
590
|
+
* 转换 Vue SFC 脚本:处理宏、导入、默认导出与 wevu 相关注入。
|
|
591
|
+
*/
|
|
403
592
|
declare function transformScript(source: string, options?: TransformScriptOptions): TransformResult;
|
|
404
593
|
//#endregion
|
|
405
594
|
//#region src/plugins/wevu/pageFeatures/types.d.ts
|
|
595
|
+
/**
|
|
596
|
+
* wevu 页面特性标识(由钩子映射表推导)。
|
|
597
|
+
*/
|
|
406
598
|
type WevuPageFeatureFlag = (typeof WE_VU_PAGE_HOOK_TO_FEATURE)[keyof typeof WE_VU_PAGE_HOOK_TO_FEATURE];
|
|
599
|
+
/**
|
|
600
|
+
* wevu 页面钩子名称。
|
|
601
|
+
*/
|
|
407
602
|
type WevuPageHookName = keyof typeof WE_VU_PAGE_HOOK_TO_FEATURE;
|
|
603
|
+
/**
|
|
604
|
+
* 模块解析器,用于注入特性时按需解析模块与源码。
|
|
605
|
+
*/
|
|
408
606
|
interface ModuleResolver {
|
|
409
607
|
resolveId: (source: string, importer: string) => Promise<string | undefined>;
|
|
410
608
|
loadCode: (id: string) => Promise<string | undefined>;
|
|
411
609
|
}
|
|
412
610
|
//#endregion
|
|
413
611
|
//#region src/plugins/wevu/pageFeatures/flags.d.ts
|
|
612
|
+
/**
|
|
613
|
+
* 扫描 AST,收集启用的 wevu 页面特性标识。
|
|
614
|
+
*/
|
|
414
615
|
declare function collectWevuPageFeatureFlags(ast: t.File): Set<WevuPageFeatureFlag>;
|
|
616
|
+
/**
|
|
617
|
+
* 将启用的页面特性注入到 options 对象中。
|
|
618
|
+
*/
|
|
415
619
|
declare function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject: t.ObjectExpression, enabled: Set<WevuPageFeatureFlag>): boolean;
|
|
416
620
|
//#endregion
|
|
417
621
|
//#region src/plugins/wevu/pageFeatures/inject.d.ts
|
|
622
|
+
/**
|
|
623
|
+
* 在 JS 源码中注入 wevu 页面特性(基于本文件分析)。
|
|
624
|
+
*/
|
|
418
625
|
declare function injectWevuPageFeaturesInJs(source: string): {
|
|
419
626
|
code: string;
|
|
420
627
|
transformed: boolean;
|
|
421
628
|
};
|
|
629
|
+
/**
|
|
630
|
+
* 在 JS 源码中注入 wevu 页面特性(支持跨模块解析)。
|
|
631
|
+
*/
|
|
422
632
|
declare function injectWevuPageFeaturesInJsWithResolver(source: string, options: {
|
|
423
633
|
id: string;
|
|
424
634
|
resolver: ModuleResolver;
|
|
@@ -428,6 +638,9 @@ declare function injectWevuPageFeaturesInJsWithResolver(source: string, options:
|
|
|
428
638
|
}>;
|
|
429
639
|
//#endregion
|
|
430
640
|
//#region src/plugins/wevu/pageFeatures/matcher.d.ts
|
|
641
|
+
/**
|
|
642
|
+
* 页面入口匹配器的数据源。
|
|
643
|
+
*/
|
|
431
644
|
interface PageEntryMatcherSource {
|
|
432
645
|
srcRoot: string;
|
|
433
646
|
loadEntries: () => Promise<{
|
|
@@ -440,6 +653,9 @@ interface PageEntryMatcherSource {
|
|
|
440
653
|
}>;
|
|
441
654
|
warn?: (message: string) => void;
|
|
442
655
|
}
|
|
656
|
+
/**
|
|
657
|
+
* 创建页面入口匹配器。
|
|
658
|
+
*/
|
|
443
659
|
declare function createPageEntryMatcher(source: PageEntryMatcherSource): {
|
|
444
660
|
markDirty(): void;
|
|
445
661
|
isPageFile(filePath: string): Promise<boolean>;
|
|
@@ -448,13 +664,22 @@ declare function createPageEntryMatcher(source: PageEntryMatcherSource): {
|
|
|
448
664
|
//#region src/utils/vueTemplateTags.d.ts
|
|
449
665
|
declare const RESERVED_VUE_COMPONENT_TAGS: Set<string>;
|
|
450
666
|
declare const VUE_COMPONENT_TAG_RE: RegExp;
|
|
667
|
+
/**
|
|
668
|
+
* 判断模板标签是否可能需要自动导入。
|
|
669
|
+
*/
|
|
451
670
|
declare function isAutoImportCandidateTag(tag: string): boolean;
|
|
671
|
+
/**
|
|
672
|
+
* 模板标签收集配置。
|
|
673
|
+
*/
|
|
452
674
|
interface CollectVueTemplateTagsOptions {
|
|
453
675
|
filename?: string;
|
|
454
676
|
warnLabel?: string;
|
|
455
677
|
warn?: (message: string) => void;
|
|
456
678
|
shouldCollect: (tag: string) => boolean;
|
|
457
679
|
}
|
|
680
|
+
/**
|
|
681
|
+
* 收集 Vue 模板中的自定义组件标签。
|
|
682
|
+
*/
|
|
458
683
|
declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
|
|
459
684
|
//#endregion
|
|
460
685
|
export { type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ScopedSlotComponentAsset, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, type WevuDefaults, type WevuPageFeatureFlag, type WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectVueTemplateTags, collectWevuPageFeatureFlags, compileConfigBlocks, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
|
package/dist/index.mjs
CHANGED
|
@@ -111,7 +111,13 @@ const components = [
|
|
|
111
111
|
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/auto-import-components/builtin.ts
|
|
114
|
+
/**
|
|
115
|
+
* 内置组件集合(来自自动生成的组件列表)。
|
|
116
|
+
*/
|
|
114
117
|
const builtinComponentsSet = new Set(components);
|
|
118
|
+
/**
|
|
119
|
+
* 判断标签是否为内置组件。
|
|
120
|
+
*/
|
|
115
121
|
function isBuiltinComponent(tag) {
|
|
116
122
|
return builtinComponentsSet.has(tag);
|
|
117
123
|
}
|
|
@@ -130,7 +136,13 @@ const WE_VU_PAGE_HOOK_TO_FEATURE = {
|
|
|
130
136
|
onAddToFavorites: "enableOnAddToFavorites",
|
|
131
137
|
onSaveExitState: "enableOnSaveExitState"
|
|
132
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* wevu 运行时模块 ID。
|
|
141
|
+
*/
|
|
133
142
|
const WE_VU_MODULE_ID = "wevu";
|
|
143
|
+
/**
|
|
144
|
+
* wevu 运行时 API 名称映射。
|
|
145
|
+
*/
|
|
134
146
|
const WE_VU_RUNTIME_APIS = {
|
|
135
147
|
createApp: "createApp",
|
|
136
148
|
createWevuComponent: "createWevuComponent",
|
|
@@ -188,6 +200,9 @@ async function readFile(id, options) {
|
|
|
188
200
|
loadCache.set(id, content);
|
|
189
201
|
return content;
|
|
190
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* 判断文件或路径是否存在,可选缓存。
|
|
205
|
+
*/
|
|
191
206
|
async function pathExists(id, options) {
|
|
192
207
|
const ttlMs = options?.ttlMs;
|
|
193
208
|
const cached = pathExistsCache.get(id);
|
|
@@ -197,11 +212,17 @@ async function pathExists(id, options) {
|
|
|
197
212
|
else pathExistsCache.set(id, exists);
|
|
198
213
|
return exists;
|
|
199
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 清理指定文件相关的缓存。
|
|
217
|
+
*/
|
|
200
218
|
function invalidateFileCache(id) {
|
|
201
219
|
mtimeCache.delete(id);
|
|
202
220
|
loadCache.delete(id);
|
|
203
221
|
pathExistsCache.delete(id);
|
|
204
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* 清空所有文件缓存。
|
|
225
|
+
*/
|
|
205
226
|
function clearFileCaches() {
|
|
206
227
|
mtimeCache.clear();
|
|
207
228
|
loadCache.clear();
|
|
@@ -210,6 +231,9 @@ function clearFileCaches() {
|
|
|
210
231
|
|
|
211
232
|
//#endregion
|
|
212
233
|
//#region src/utils/cachePolicy.ts
|
|
234
|
+
/**
|
|
235
|
+
* 获取 readFile 是否检查 mtime 的策略。
|
|
236
|
+
*/
|
|
213
237
|
function getReadFileCheckMtime(config) {
|
|
214
238
|
return Boolean(config?.isDev);
|
|
215
239
|
}
|
|
@@ -299,6 +323,9 @@ function getBlockLabel(kind) {
|
|
|
299
323
|
if (kind === "script setup") return "script setup";
|
|
300
324
|
return kind;
|
|
301
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* 预处理 `<script setup src>`,避免编译器丢失 src。
|
|
328
|
+
*/
|
|
302
329
|
function preprocessScriptSetupSrc(source) {
|
|
303
330
|
if (!source.includes("<script") || !source.includes("setup") || !source.includes("src")) return source;
|
|
304
331
|
return source.replace(SCRIPT_SETUP_TAG_RE, (full, attrs) => {
|
|
@@ -306,6 +333,9 @@ function preprocessScriptSetupSrc(source) {
|
|
|
306
333
|
return `<script${attrs.replace(/\bsrc(\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))/i, `${SCRIPT_SETUP_SRC_ATTR}$1`)}>`;
|
|
307
334
|
});
|
|
308
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* 预处理普通 `<script src>`,避免编译器丢失 src。
|
|
338
|
+
*/
|
|
309
339
|
function preprocessScriptSrc(source) {
|
|
310
340
|
if (!source.includes("<script") || !source.includes("src")) return source;
|
|
311
341
|
return source.replace(SCRIPT_SETUP_TAG_RE, (full, attrs) => {
|
|
@@ -313,6 +343,9 @@ function preprocessScriptSrc(source) {
|
|
|
313
343
|
return `<script${attrs.replace(/\bsrc(\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))/i, `${SCRIPT_SRC_ATTR}$1`)}>`;
|
|
314
344
|
});
|
|
315
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* 将预处理的 `<script setup src>` 恢复为真实 src。
|
|
348
|
+
*/
|
|
316
349
|
function restoreScriptSetupSrc(descriptor) {
|
|
317
350
|
const scriptSetup = descriptor.scriptSetup;
|
|
318
351
|
if (!scriptSetup?.attrs || !(SCRIPT_SETUP_SRC_ATTR in scriptSetup.attrs)) return;
|
|
@@ -320,6 +353,9 @@ function restoreScriptSetupSrc(descriptor) {
|
|
|
320
353
|
if (typeof raw === "string") scriptSetup.src = raw;
|
|
321
354
|
delete scriptSetup.attrs[SCRIPT_SETUP_SRC_ATTR];
|
|
322
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* 将预处理的 `<script src>` 恢复为真实 src。
|
|
358
|
+
*/
|
|
323
359
|
function restoreScriptSrc(descriptor) {
|
|
324
360
|
const script = descriptor.script;
|
|
325
361
|
if (!script?.attrs || !(SCRIPT_SRC_ATTR in script.attrs)) return;
|
|
@@ -356,6 +392,9 @@ async function readBlockContent(resolvedId, filename, options) {
|
|
|
356
392
|
throw new Error(`解析 ${filename} 失败:读取 ${resolvedId} 失败:${message}`);
|
|
357
393
|
}
|
|
358
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* 解析 SFC 中带 `src` 的 block,并返回依赖列表。
|
|
397
|
+
*/
|
|
359
398
|
async function resolveSfcBlockSrc(descriptor, filename, options) {
|
|
360
399
|
if (!options) return {
|
|
361
400
|
descriptor,
|
|
@@ -388,6 +427,9 @@ async function resolveSfcBlockSrc(descriptor, filename, options) {
|
|
|
388
427
|
deps: Array.from(deps)
|
|
389
428
|
};
|
|
390
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* 读取并解析 SFC,支持缓存与 src 解析。
|
|
432
|
+
*/
|
|
391
433
|
async function readAndParseSfc(filename, options) {
|
|
392
434
|
const checkMtime = options?.checkMtime ?? true;
|
|
393
435
|
const source = options?.source ?? await readFile(filename, { checkMtime });
|
|
@@ -435,6 +477,9 @@ async function readAndParseSfc(filename, options) {
|
|
|
435
477
|
errors: parsed.errors
|
|
436
478
|
};
|
|
437
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* 获取 SFC 读取时是否检查 mtime 的策略。
|
|
482
|
+
*/
|
|
438
483
|
function getSfcCheckMtime(config) {
|
|
439
484
|
return getReadFileCheckMtime(config);
|
|
440
485
|
}
|
|
@@ -533,16 +578,28 @@ function normalizeRoot(root) {
|
|
|
533
578
|
|
|
534
579
|
//#endregion
|
|
535
580
|
//#region src/plugins/vue/compiler/template/classStyleRuntime.ts
|
|
581
|
+
/**
|
|
582
|
+
* class/style WXS 模块名。
|
|
583
|
+
*/
|
|
536
584
|
const CLASS_STYLE_WXS_MODULE = "__weapp_vite";
|
|
585
|
+
/**
|
|
586
|
+
* class/style WXS 文件名(不含扩展名)。
|
|
587
|
+
*/
|
|
537
588
|
const CLASS_STYLE_WXS_FILE = "__weapp_vite_class_style";
|
|
538
589
|
function resolveScriptModuleTag(extension) {
|
|
539
590
|
return (extension.startsWith(".") ? extension.slice(1) : extension) === "sjs" ? "sjs" : "wxs";
|
|
540
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* 构建 class/style WXS 引用标签。
|
|
594
|
+
*/
|
|
541
595
|
function buildClassStyleWxsTag(extension, src) {
|
|
542
596
|
const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
|
|
543
597
|
const resolvedSrc = src ?? `./${CLASS_STYLE_WXS_FILE}.${normalized}`;
|
|
544
598
|
return `<${resolveScriptModuleTag(normalized)} module="${CLASS_STYLE_WXS_MODULE}" src="${resolvedSrc}"/>`;
|
|
545
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* 解析 class/style WXS 文件位置与引用路径。
|
|
602
|
+
*/
|
|
546
603
|
function resolveClassStyleWxsLocation(options) {
|
|
547
604
|
const normalizedExt = options.extension.startsWith(".") ? options.extension.slice(1) : options.extension;
|
|
548
605
|
const normalizedRoot = normalizeRoot(options.packageRoot ?? "");
|
|
@@ -557,6 +614,9 @@ function resolveClassStyleWxsLocation(options) {
|
|
|
557
614
|
src
|
|
558
615
|
};
|
|
559
616
|
}
|
|
617
|
+
/**
|
|
618
|
+
* 获取内置 class/style WXS 运行时代码。
|
|
619
|
+
*/
|
|
560
620
|
function getClassStyleWxsSource() {
|
|
561
621
|
return [
|
|
562
622
|
"var objectCtor = ({}).constructor",
|
|
@@ -2376,6 +2436,9 @@ function toOnEventName(eventName) {
|
|
|
2376
2436
|
if (!eventName) return "on";
|
|
2377
2437
|
return `on${(eventName[0] ?? "").toUpperCase()}${eventName.slice(1)}`;
|
|
2378
2438
|
}
|
|
2439
|
+
/**
|
|
2440
|
+
* 支付宝小程序平台适配器。
|
|
2441
|
+
*/
|
|
2379
2442
|
const alipayPlatform = {
|
|
2380
2443
|
name: "alipay",
|
|
2381
2444
|
wrapIf: (exp, content) => `<block a:if="{{${exp}}}">${content}</block>`,
|
|
@@ -2420,6 +2483,9 @@ const eventMap$2 = {
|
|
|
2420
2483
|
longtap: "longtap",
|
|
2421
2484
|
longpress: "longpress"
|
|
2422
2485
|
};
|
|
2486
|
+
/**
|
|
2487
|
+
* 百度智能小程序平台适配器。
|
|
2488
|
+
*/
|
|
2423
2489
|
const swanPlatform = {
|
|
2424
2490
|
name: "swan",
|
|
2425
2491
|
wrapIf: (exp, content) => `<block s-if="{{${exp}}}">${content}</block>`,
|
|
@@ -2463,6 +2529,9 @@ const eventMap$1 = {
|
|
|
2463
2529
|
longtap: "longtap",
|
|
2464
2530
|
longpress: "longpress"
|
|
2465
2531
|
};
|
|
2532
|
+
/**
|
|
2533
|
+
* 抖音小程序平台适配器。
|
|
2534
|
+
*/
|
|
2466
2535
|
const ttPlatform = {
|
|
2467
2536
|
name: "tt",
|
|
2468
2537
|
wrapIf: (exp, content) => `<block tt:if="{{${exp}}}">${content}</block>`,
|
|
@@ -2506,6 +2575,9 @@ const eventMap = {
|
|
|
2506
2575
|
longtap: "longtap",
|
|
2507
2576
|
longpress: "longpress"
|
|
2508
2577
|
};
|
|
2578
|
+
/**
|
|
2579
|
+
* 微信小程序平台适配器。
|
|
2580
|
+
*/
|
|
2509
2581
|
const wechatPlatform = {
|
|
2510
2582
|
name: "wechat",
|
|
2511
2583
|
wrapIf: (exp, content) => `<block wx:if="{{${exp}}}">${content}</block>`,
|
|
@@ -2535,6 +2607,9 @@ const TEMPLATE_PLATFORMS = {
|
|
|
2535
2607
|
jd: wechatPlatform,
|
|
2536
2608
|
xhs: wechatPlatform
|
|
2537
2609
|
};
|
|
2610
|
+
/**
|
|
2611
|
+
* 获取指定平台的模板适配器,默认回退到 wechat。
|
|
2612
|
+
*/
|
|
2538
2613
|
function getMiniProgramTemplatePlatform(platform) {
|
|
2539
2614
|
if (!platform) return wechatPlatform;
|
|
2540
2615
|
return TEMPLATE_PLATFORMS[platform] ?? wechatPlatform;
|
|
@@ -2542,6 +2617,9 @@ function getMiniProgramTemplatePlatform(platform) {
|
|
|
2542
2617
|
|
|
2543
2618
|
//#endregion
|
|
2544
2619
|
//#region src/plugins/vue/compiler/template.ts
|
|
2620
|
+
/**
|
|
2621
|
+
* 将 Vue 模板编译为 WXML。
|
|
2622
|
+
*/
|
|
2545
2623
|
function compileVueTemplateToWxml(template, filename, options) {
|
|
2546
2624
|
const warnings = [];
|
|
2547
2625
|
const runtimeMode = options?.classStyleRuntime ?? "auto";
|
|
@@ -2711,9 +2789,15 @@ const RESERVED_VUE_COMPONENT_TAGS = new Set([
|
|
|
2711
2789
|
"suspense"
|
|
2712
2790
|
]);
|
|
2713
2791
|
const VUE_COMPONENT_TAG_RE = /^[A-Z_$][\w$]*$/i;
|
|
2792
|
+
/**
|
|
2793
|
+
* 判断模板标签是否可能需要自动导入。
|
|
2794
|
+
*/
|
|
2714
2795
|
function isAutoImportCandidateTag(tag) {
|
|
2715
2796
|
return tag.includes("-") || /^[A-Z][\w$]*$/.test(tag);
|
|
2716
2797
|
}
|
|
2798
|
+
/**
|
|
2799
|
+
* 收集 Vue 模板中的自定义组件标签。
|
|
2800
|
+
*/
|
|
2717
2801
|
function collectVueTemplateTags(template, options) {
|
|
2718
2802
|
const tags = /* @__PURE__ */ new Set();
|
|
2719
2803
|
const warn = options.warn;
|
|
@@ -2748,6 +2832,9 @@ function collectVueTemplateTags(template, options) {
|
|
|
2748
2832
|
|
|
2749
2833
|
//#endregion
|
|
2750
2834
|
//#region src/utils/warn.ts
|
|
2835
|
+
/**
|
|
2836
|
+
* 解析警告处理函数,未提供时回退到 console.warn。
|
|
2837
|
+
*/
|
|
2751
2838
|
function resolveWarnHandler(warn) {
|
|
2752
2839
|
return warn ?? ((message) => {
|
|
2753
2840
|
console.warn(message);
|
|
@@ -2843,19 +2930,31 @@ function resolveWevuConfigTempDir(fromDir) {
|
|
|
2843
2930
|
|
|
2844
2931
|
//#endregion
|
|
2845
2932
|
//#region src/plugins/vue/transform/config.ts
|
|
2933
|
+
/**
|
|
2934
|
+
* 规范化配置块语言。
|
|
2935
|
+
*/
|
|
2846
2936
|
function normalizeConfigLang(lang) {
|
|
2847
2937
|
if (!lang) return "json";
|
|
2848
2938
|
const lower = lang.toLowerCase();
|
|
2849
2939
|
if (lower === "txt") return "json";
|
|
2850
2940
|
return lower;
|
|
2851
2941
|
}
|
|
2942
|
+
/**
|
|
2943
|
+
* 判断是否为 JSON 类语言。
|
|
2944
|
+
*/
|
|
2852
2945
|
function isJsonLikeLang(lang) {
|
|
2853
2946
|
return lang === "json" || lang === "jsonc" || lang === "json5";
|
|
2854
2947
|
}
|
|
2948
|
+
/**
|
|
2949
|
+
* 将语言标识归一为 js/ts。
|
|
2950
|
+
*/
|
|
2855
2951
|
function resolveJsLikeLang(lang) {
|
|
2856
2952
|
if (lang === "ts" || lang === "tsx" || lang === "cts" || lang === "mts") return "ts";
|
|
2857
2953
|
return "js";
|
|
2858
2954
|
}
|
|
2955
|
+
/**
|
|
2956
|
+
* 执行 JS/TS 配置块并返回对象结果。
|
|
2957
|
+
*/
|
|
2859
2958
|
async function evaluateJsLikeConfig(source, filename, lang) {
|
|
2860
2959
|
const dir = path.dirname(filename);
|
|
2861
2960
|
const extension = resolveJsLikeLang(lang) === "ts" ? "ts" : "js";
|
|
@@ -2887,6 +2986,9 @@ async function evaluateJsLikeConfig(source, filename, lang) {
|
|
|
2887
2986
|
}
|
|
2888
2987
|
});
|
|
2889
2988
|
}
|
|
2989
|
+
/**
|
|
2990
|
+
* 编译 SFC 内的 <json> 配置块并返回 JSON 字符串。
|
|
2991
|
+
*/
|
|
2890
2992
|
async function compileConfigBlocks(blocks, filename, options) {
|
|
2891
2993
|
const jsonBlocks = blocks.filter((block) => block.type === "json");
|
|
2892
2994
|
if (!jsonBlocks.length) return;
|
|
@@ -3212,6 +3314,9 @@ function findProgramPath(ast) {
|
|
|
3212
3314
|
|
|
3213
3315
|
//#endregion
|
|
3214
3316
|
//#region src/plugins/vue/transform/jsonMacros/rewrite.ts
|
|
3317
|
+
/**
|
|
3318
|
+
* 移除 `<script setup>` 中的 JSON 宏语句,返回剥离后的代码与宏源码片段。
|
|
3319
|
+
*/
|
|
3215
3320
|
function stripScriptSetupMacroStatements(content, ast, filename) {
|
|
3216
3321
|
const ms = new MagicString(content);
|
|
3217
3322
|
const macroStatementSources = [];
|
|
@@ -3231,6 +3336,9 @@ function stripScriptSetupMacroStatements(content, ast, filename) {
|
|
|
3231
3336
|
macroStatementSources
|
|
3232
3337
|
};
|
|
3233
3338
|
}
|
|
3339
|
+
/**
|
|
3340
|
+
* 从任意代码中剥离 JSON 宏调用。
|
|
3341
|
+
*/
|
|
3234
3342
|
function stripJsonMacroCallsFromCode(code, filename) {
|
|
3235
3343
|
let ast;
|
|
3236
3344
|
try {
|
|
@@ -3258,6 +3366,9 @@ function stripJsonMacroCallsFromCode(code, filename) {
|
|
|
3258
3366
|
|
|
3259
3367
|
//#endregion
|
|
3260
3368
|
//#region src/plugins/vue/transform/jsonMacros/index.ts
|
|
3369
|
+
/**
|
|
3370
|
+
* 从 `<script setup>` 中提取 JSON 宏配置并返回剥离后的代码。
|
|
3371
|
+
*/
|
|
3261
3372
|
async function extractJsonMacroFromScriptSetup(content, filename, lang, options) {
|
|
3262
3373
|
const ast = parseScriptSetupAst(content, filename);
|
|
3263
3374
|
const { macroNames } = collectMacroCallPaths(ast, filename);
|
|
@@ -3302,6 +3413,9 @@ function toPlainRecord(value) {
|
|
|
3302
3413
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
3303
3414
|
return value;
|
|
3304
3415
|
}
|
|
3416
|
+
/**
|
|
3417
|
+
* 按策略合并 JSON 配置对象。
|
|
3418
|
+
*/
|
|
3305
3419
|
function mergeJsonWithStrategy(target, source, strategy, context) {
|
|
3306
3420
|
const base = { ...toPlainRecord(target) };
|
|
3307
3421
|
const incoming = toPlainRecord(source);
|
|
@@ -3319,6 +3433,9 @@ function mergeJsonWithStrategy(target, source, strategy, context) {
|
|
|
3319
3433
|
recursive(merged, incoming);
|
|
3320
3434
|
return merged;
|
|
3321
3435
|
}
|
|
3436
|
+
/**
|
|
3437
|
+
* 创建带上下文的 JSON 合并函数。
|
|
3438
|
+
*/
|
|
3322
3439
|
function createJsonMerger(strategy, baseContext) {
|
|
3323
3440
|
return (target, source, stage) => {
|
|
3324
3441
|
return mergeJsonWithStrategy(target, source, strategy, {
|
|
@@ -3467,6 +3584,9 @@ function isTopLevel(path) {
|
|
|
3467
3584
|
|
|
3468
3585
|
//#endregion
|
|
3469
3586
|
//#region src/plugins/wevu/pageFeatures/flags.ts
|
|
3587
|
+
/**
|
|
3588
|
+
* 扫描 AST,收集启用的 wevu 页面特性标识。
|
|
3589
|
+
*/
|
|
3470
3590
|
function collectWevuPageFeatureFlags(ast) {
|
|
3471
3591
|
const namedHookLocals = /* @__PURE__ */ new Map();
|
|
3472
3592
|
const namespaceLocals = /* @__PURE__ */ new Set();
|
|
@@ -3514,6 +3634,9 @@ function collectWevuPageFeatureFlags(ast) {
|
|
|
3514
3634
|
});
|
|
3515
3635
|
return enabled;
|
|
3516
3636
|
}
|
|
3637
|
+
/**
|
|
3638
|
+
* 将启用的页面特性注入到 options 对象中。
|
|
3639
|
+
*/
|
|
3517
3640
|
function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject, enabled) {
|
|
3518
3641
|
if (!enabled.size) return false;
|
|
3519
3642
|
const expectedKeys = Array.from(enabled);
|
|
@@ -3980,6 +4103,9 @@ async function collectWevuFeaturesFromSetupReachableImports(pageModule, setupFn,
|
|
|
3980
4103
|
|
|
3981
4104
|
//#endregion
|
|
3982
4105
|
//#region src/plugins/wevu/pageFeatures/inject.ts
|
|
4106
|
+
/**
|
|
4107
|
+
* 在 JS 源码中注入 wevu 页面特性(基于本文件分析)。
|
|
4108
|
+
*/
|
|
3983
4109
|
function injectWevuPageFeaturesInJs(source) {
|
|
3984
4110
|
const ast = parseJsLike(source);
|
|
3985
4111
|
const enabled = collectWevuPageFeatureFlags(ast);
|
|
@@ -4003,6 +4129,9 @@ function injectWevuPageFeaturesInJs(source) {
|
|
|
4003
4129
|
transformed: true
|
|
4004
4130
|
};
|
|
4005
4131
|
}
|
|
4132
|
+
/**
|
|
4133
|
+
* 在 JS 源码中注入 wevu 页面特性(支持跨模块解析)。
|
|
4134
|
+
*/
|
|
4006
4135
|
async function injectWevuPageFeaturesInJsWithResolver(source, options) {
|
|
4007
4136
|
const ast = parseJsLike(source);
|
|
4008
4137
|
const { optionsObjects, module } = collectTargetOptionsObjects(ast, options.id);
|
|
@@ -4038,6 +4167,9 @@ async function injectWevuPageFeaturesInJsWithResolver(source, options) {
|
|
|
4038
4167
|
|
|
4039
4168
|
//#endregion
|
|
4040
4169
|
//#region src/plugins/wevu/pageFeatures/matcher.ts
|
|
4170
|
+
/**
|
|
4171
|
+
* 创建页面入口匹配器。
|
|
4172
|
+
*/
|
|
4041
4173
|
function createPageEntryMatcher(source) {
|
|
4042
4174
|
let cached;
|
|
4043
4175
|
const warn = resolveWarnHandler(source.warn);
|
|
@@ -4827,6 +4959,9 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
4827
4959
|
|
|
4828
4960
|
//#endregion
|
|
4829
4961
|
//#region src/plugins/vue/transform/transformScript/index.ts
|
|
4962
|
+
/**
|
|
4963
|
+
* 转换 Vue SFC 脚本:处理宏、导入、默认导出与 wevu 相关注入。
|
|
4964
|
+
*/
|
|
4830
4965
|
function transformScript(source, options) {
|
|
4831
4966
|
const ast = parse$2(source, BABEL_TS_MODULE_PARSER_OPTIONS);
|
|
4832
4967
|
const warn = resolveWarnHandler(options?.warn);
|
|
@@ -5002,6 +5137,9 @@ function compileTemplatePhase(descriptor, filename, options, result) {
|
|
|
5002
5137
|
|
|
5003
5138
|
//#endregion
|
|
5004
5139
|
//#region src/plugins/vue/transform/compileVueFile/index.ts
|
|
5140
|
+
/**
|
|
5141
|
+
* 编译 Vue 单文件组件,输出脚本、模板、样式与配置结果。
|
|
5142
|
+
*/
|
|
5005
5143
|
async function compileVueFile(source, filename, options) {
|
|
5006
5144
|
const parsed = await parseVueFile(source, filename, options);
|
|
5007
5145
|
const result = { meta: { ...parsed.meta } };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@babel/generator": "^7.29.
|
|
44
|
+
"@babel/generator": "^7.29.1",
|
|
45
45
|
"@babel/parser": "^7.29.0",
|
|
46
46
|
"@babel/traverse": "^7.29.0",
|
|
47
47
|
"@babel/types": "^7.29.0",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"merge": "^2.1.1",
|
|
54
54
|
"pathe": "^2.0.3",
|
|
55
55
|
"vue": "^3.5.27",
|
|
56
|
-
"@weapp-core/shared": "3.0.
|
|
57
|
-
"rolldown-require": "2.0.
|
|
56
|
+
"@weapp-core/shared": "3.0.1",
|
|
57
|
+
"rolldown-require": "2.0.5"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|