@wevu/compiler 6.15.6 → 6.15.8

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 CHANGED
@@ -1,3 +1,4 @@
1
+ import { MpPlatform } from "@weapp-core/shared";
1
2
  import * as t from "@weapp-vite/ast/babelTypes";
2
3
  import { Expression } from "@weapp-vite/ast/babelTypes";
3
4
  import { AstEngineName, AstEngineName as AstEngineName$1 } from "@weapp-vite/ast";
@@ -167,11 +168,21 @@ declare function getSfcCheckMtime(config?: {
167
168
  }): boolean;
168
169
  //#endregion
169
170
  //#region src/plugins/vue/compiler/template/platform.d.ts
171
+ interface MiniProgramDirectiveAttrs {
172
+ ifAttr: string;
173
+ elifAttr: string;
174
+ elseAttr: string;
175
+ forAttr: string;
176
+ forItemAttr: string;
177
+ forIndexAttr: string;
178
+ keyAttr: string;
179
+ }
170
180
  /**
171
181
  * 小程序模板平台适配器定义。
172
182
  */
173
183
  interface MiniProgramPlatform {
174
184
  name: string;
185
+ directives: MiniProgramDirectiveAttrs;
175
186
  wrapIf: (exp: string, content: string, renderMustache: (exp: string) => string) => string;
176
187
  wrapElseIf: (exp: string, content: string, renderMustache: (exp: string) => string) => string;
177
188
  wrapElse: (content: string) => string;
@@ -308,39 +319,49 @@ interface LayoutHostBinding {
308
319
  kind?: 'component';
309
320
  }
310
321
  //#endregion
311
- //#region src/types/platform.d.ts
322
+ //#region src/plugins/vue/compiler/template/platforms/alipay.d.ts
323
+ declare const alipayPlatform: MiniProgramPlatform;
324
+ //#endregion
325
+ //#region src/plugins/vue/compiler/template/platforms/default.d.ts
312
326
  /**
313
- * 小程序平台标识。
327
+ * 默认小程序模板平台实现。
328
+ *
329
+ * 当前默认实现与微信模板语义保持一致,但应作为默认平台接入点使用,
330
+ * 以避免内部链路继续绑定具体宿主命名。
314
331
  */
315
- type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
316
- //#endregion
317
- //#region src/plugins/vue/compiler/template/platforms/alipay.d.ts
332
+ declare const defaultMiniProgramPlatform: MiniProgramPlatform;
318
333
  /**
319
- * 支付宝小程序平台适配器。
334
+ * 默认模板平台对象的简写别名。
320
335
  */
321
- declare const alipayPlatform: MiniProgramPlatform;
336
+ declare const defaultPlatform: MiniProgramPlatform;
322
337
  //#endregion
323
338
  //#region src/plugins/vue/compiler/template/platforms/swan.d.ts
324
- /**
325
- * 百度智能小程序平台适配器。
326
- */
327
339
  declare const swanPlatform: MiniProgramPlatform;
328
340
  //#endregion
329
341
  //#region src/plugins/vue/compiler/template/platforms/tt.d.ts
330
- /**
331
- * 抖音小程序平台适配器。
332
- */
333
342
  declare const ttPlatform: MiniProgramPlatform;
334
343
  //#endregion
335
- //#region src/plugins/vue/compiler/template/platforms/wechat.d.ts
344
+ //#region src/plugins/vue/compiler/template/platforms/index.d.ts
345
+ /**
346
+ * 获取默认模板适配器。
347
+ */
348
+ declare function getDefaultMiniProgramTemplatePlatform(): MiniProgramPlatform;
349
+ /**
350
+ * 获取默认小程序平台适配器。
351
+ */
352
+ declare const getDefaultMiniProgramPlatform: typeof getDefaultMiniProgramTemplatePlatform;
353
+ /**
354
+ * 默认模板平台对象别名,便于调用方避免继续依赖具体宿主命名。
355
+ */
356
+ declare const defaultMiniProgramTemplatePlatform: MiniProgramPlatform;
336
357
  /**
337
- * 微信小程序平台适配器。
358
+ * 微信模板平台兼容别名。
359
+ *
360
+ * 新代码应优先使用 defaultMiniProgramPlatform/defaultPlatform。
338
361
  */
339
362
  declare const wechatPlatform: MiniProgramPlatform;
340
- //#endregion
341
- //#region src/plugins/vue/compiler/template/platforms/index.d.ts
342
363
  /**
343
- * 获取指定平台的模板适配器,默认回退到 wechat。
364
+ * 获取指定平台的模板适配器,默认回退到默认模板平台。
344
365
  */
345
366
  declare function getMiniProgramTemplatePlatform(platform?: MpPlatform): MiniProgramPlatform;
346
367
  //#endregion
@@ -812,4 +833,4 @@ interface CollectVueTemplateTagsOptions {
812
833
  */
813
834
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
814
835
  //#endregion
815
- export { type AstEngineName, 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, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, 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 };
836
+ export { type AstEngineName, 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, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, 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
@@ -1,4 +1,4 @@
1
- import { removeExtensionDeep } from "@weapp-core/shared";
1
+ import { getMiniProgramRuntimeGlobalKeys, getMiniProgramTemplatePreset, removeExtensionDeep } from "@weapp-core/shared";
2
2
  import path from "pathe";
3
3
  import { NodeTypes, baseParse } from "@vue/compiler-core";
4
4
  import { createHash } from "node:crypto";
@@ -3248,6 +3248,23 @@ function stripRenderOptionFromScript(source, filename, warn) {
3248
3248
  return generate(ast).code;
3249
3249
  }
3250
3250
  //#endregion
3251
+ //#region src/plugins/vue/compiler/template/platform.ts
3252
+ /**
3253
+ * 创建结构指令属性名。
3254
+ */
3255
+ function createMiniProgramDirectiveAttrs(prefix, separator = ":") {
3256
+ const resolveAttr = (suffix) => `${prefix}${separator}${suffix}`;
3257
+ return {
3258
+ ifAttr: resolveAttr("if"),
3259
+ elifAttr: resolveAttr("elif"),
3260
+ elseAttr: resolveAttr("else"),
3261
+ forAttr: resolveAttr("for"),
3262
+ forItemAttr: resolveAttr("for-item"),
3263
+ forIndexAttr: resolveAttr("for-index"),
3264
+ keyAttr: resolveAttr("key")
3265
+ };
3266
+ }
3267
+ //#endregion
3251
3268
  //#region src/plugins/vue/compiler/template/platforms/alipay.ts
3252
3269
  const eventMap$3 = {
3253
3270
  click: "tap",
@@ -3300,19 +3317,21 @@ function toAlipayDirectiveEvent(prefix, eventName) {
3300
3317
  /**
3301
3318
  * 支付宝小程序平台适配器。
3302
3319
  */
3320
+ const directives$3 = createMiniProgramDirectiveAttrs("a");
3303
3321
  const alipayPlatform = {
3304
3322
  name: "alipay",
3305
- wrapIf: (exp, content, renderMustache) => `<block a:if="${renderMustache(exp)}">${content}</block>`,
3306
- wrapElseIf: (exp, content, renderMustache) => `<block a:elif="${renderMustache(exp)}">${content}</block>`,
3307
- wrapElse: (content) => `<block a:else>${content}</block>`,
3323
+ directives: directives$3,
3324
+ wrapIf: (exp, content, renderMustache) => `<block ${directives$3.ifAttr}="${renderMustache(exp)}">${content}</block>`,
3325
+ wrapElseIf: (exp, content, renderMustache) => `<block ${directives$3.elifAttr}="${renderMustache(exp)}">${content}</block>`,
3326
+ wrapElse: (content) => `<block ${directives$3.elseAttr}>${content}</block>`,
3308
3327
  forAttrs: (listExp, renderMustache, item, index) => {
3309
- const attrs = [`a:for="${renderMustache(listExp)}"`];
3310
- if (item) attrs.push(`a:for-item="${item}"`);
3311
- if (index) attrs.push(`a:for-index="${index}"`);
3328
+ const attrs = [`${directives$3.forAttr}="${renderMustache(listExp)}"`];
3329
+ if (item) attrs.push(`${directives$3.forItemAttr}="${item}"`);
3330
+ if (index) attrs.push(`${directives$3.forIndexAttr}="${index}"`);
3312
3331
  return attrs;
3313
3332
  },
3314
3333
  keyThisValue: "*this",
3315
- keyAttr: (value) => `a:key="${value}"`,
3334
+ keyAttr: (value) => `${directives$3.keyAttr}="${value}"`,
3316
3335
  mapEventName: (eventName) => eventMap$3[eventName] || eventName,
3317
3336
  eventBindingAttr: (eventName) => {
3318
3337
  const { prefix, name } = parseEventBinding$3(eventName);
@@ -3321,7 +3340,7 @@ const alipayPlatform = {
3321
3340
  }
3322
3341
  };
3323
3342
  //#endregion
3324
- //#region src/plugins/vue/compiler/template/platforms/swan.ts
3343
+ //#region src/plugins/vue/compiler/template/platforms/default.ts
3325
3344
  const eventMap$2 = {
3326
3345
  click: "tap",
3327
3346
  dblclick: "tap",
@@ -3359,22 +3378,27 @@ function parseEventBinding$2(eventName) {
3359
3378
  function shouldUseColonEventBinding$2(name) {
3360
3379
  return name.includes(":") || name.includes("-");
3361
3380
  }
3381
+ const directives$2 = createMiniProgramDirectiveAttrs("wx");
3362
3382
  /**
3363
- * 百度智能小程序平台适配器。
3383
+ * 默认小程序模板平台实现。
3384
+ *
3385
+ * 当前默认实现与微信模板语义保持一致,但应作为默认平台接入点使用,
3386
+ * 以避免内部链路继续绑定具体宿主命名。
3364
3387
  */
3365
- const swanPlatform = {
3366
- name: "swan",
3367
- wrapIf: (exp, content, renderMustache) => `<block s-if="${renderMustache(exp)}">${content}</block>`,
3368
- wrapElseIf: (exp, content, renderMustache) => `<block s-elif="${renderMustache(exp)}">${content}</block>`,
3369
- wrapElse: (content) => `<block s-else>${content}</block>`,
3388
+ const defaultMiniProgramPlatform = {
3389
+ name: "wechat",
3390
+ directives: directives$2,
3391
+ wrapIf: (exp, content, renderMustache) => `<block ${directives$2.ifAttr}="${renderMustache(exp)}">${content}</block>`,
3392
+ wrapElseIf: (exp, content, renderMustache) => `<block ${directives$2.elifAttr}="${renderMustache(exp)}">${content}</block>`,
3393
+ wrapElse: (content) => `<block ${directives$2.elseAttr}>${content}</block>`,
3370
3394
  forAttrs: (listExp, renderMustache, item, index) => {
3371
- const attrs = [`s-for="${renderMustache(listExp)}"`];
3372
- if (item) attrs.push(`s-for-item="${item}"`);
3373
- if (index) attrs.push(`s-for-index="${index}"`);
3395
+ const attrs = [`${directives$2.forAttr}="${renderMustache(listExp)}"`];
3396
+ if (item) attrs.push(`${directives$2.forItemAttr}="${item}"`);
3397
+ if (index) attrs.push(`${directives$2.forIndexAttr}="${index}"`);
3374
3398
  return attrs;
3375
3399
  },
3376
3400
  keyThisValue: "*this",
3377
- keyAttr: (value) => `s-key="${value}"`,
3401
+ keyAttr: (value) => `${directives$2.keyAttr}="${value}"`,
3378
3402
  mapEventName: (eventName) => eventMap$2[eventName] || eventName,
3379
3403
  eventBindingAttr: (eventName) => {
3380
3404
  const { prefix, name } = parseEventBinding$2(eventName);
@@ -3387,8 +3411,12 @@ const swanPlatform = {
3387
3411
  }
3388
3412
  }
3389
3413
  };
3414
+ /**
3415
+ * 默认模板平台对象的简写别名。
3416
+ */
3417
+ const defaultPlatform = defaultMiniProgramPlatform;
3390
3418
  //#endregion
3391
- //#region src/plugins/vue/compiler/template/platforms/tt.ts
3419
+ //#region src/plugins/vue/compiler/template/platforms/swan.ts
3392
3420
  const eventMap$1 = {
3393
3421
  click: "tap",
3394
3422
  dblclick: "tap",
@@ -3427,21 +3455,23 @@ function shouldUseColonEventBinding$1(name) {
3427
3455
  return name.includes(":") || name.includes("-");
3428
3456
  }
3429
3457
  /**
3430
- * 抖音小程序平台适配器。
3458
+ * 百度智能小程序平台适配器。
3431
3459
  */
3432
- const ttPlatform = {
3433
- name: "tt",
3434
- wrapIf: (exp, content, renderMustache) => `<block tt:if="${renderMustache(exp)}">${content}</block>`,
3435
- wrapElseIf: (exp, content, renderMustache) => `<block tt:elif="${renderMustache(exp)}">${content}</block>`,
3436
- wrapElse: (content) => `<block tt:else>${content}</block>`,
3460
+ const directives$1 = createMiniProgramDirectiveAttrs("s", "-");
3461
+ const swanPlatform = {
3462
+ name: "swan",
3463
+ directives: directives$1,
3464
+ wrapIf: (exp, content, renderMustache) => `<block ${directives$1.ifAttr}="${renderMustache(exp)}">${content}</block>`,
3465
+ wrapElseIf: (exp, content, renderMustache) => `<block ${directives$1.elifAttr}="${renderMustache(exp)}">${content}</block>`,
3466
+ wrapElse: (content) => `<block ${directives$1.elseAttr}>${content}</block>`,
3437
3467
  forAttrs: (listExp, renderMustache, item, index) => {
3438
- const attrs = [`tt:for="${renderMustache(listExp)}"`];
3439
- if (item) attrs.push(`tt:for-item="${item}"`);
3440
- if (index) attrs.push(`tt:for-index="${index}"`);
3468
+ const attrs = [`${directives$1.forAttr}="${renderMustache(listExp)}"`];
3469
+ if (item) attrs.push(`${directives$1.forItemAttr}="${item}"`);
3470
+ if (index) attrs.push(`${directives$1.forIndexAttr}="${index}"`);
3441
3471
  return attrs;
3442
3472
  },
3443
3473
  keyThisValue: "*this",
3444
- keyAttr: (value) => `tt:key="${value}"`,
3474
+ keyAttr: (value) => `${directives$1.keyAttr}="${value}"`,
3445
3475
  mapEventName: (eventName) => eventMap$1[eventName] || eventName,
3446
3476
  eventBindingAttr: (eventName) => {
3447
3477
  const { prefix, name } = parseEventBinding$1(eventName);
@@ -3455,7 +3485,7 @@ const ttPlatform = {
3455
3485
  }
3456
3486
  };
3457
3487
  //#endregion
3458
- //#region src/plugins/vue/compiler/template/platforms/wechat.ts
3488
+ //#region src/plugins/vue/compiler/template/platforms/tt.ts
3459
3489
  const eventMap = {
3460
3490
  click: "tap",
3461
3491
  dblclick: "tap",
@@ -3494,21 +3524,23 @@ function shouldUseColonEventBinding(name) {
3494
3524
  return name.includes(":") || name.includes("-");
3495
3525
  }
3496
3526
  /**
3497
- * 微信小程序平台适配器。
3527
+ * 抖音小程序平台适配器。
3498
3528
  */
3499
- const wechatPlatform = {
3500
- name: "wechat",
3501
- wrapIf: (exp, content, renderMustache) => `<block wx:if="${renderMustache(exp)}">${content}</block>`,
3502
- wrapElseIf: (exp, content, renderMustache) => `<block wx:elif="${renderMustache(exp)}">${content}</block>`,
3503
- wrapElse: (content) => `<block wx:else>${content}</block>`,
3529
+ const directives = createMiniProgramDirectiveAttrs("tt");
3530
+ const ttPlatform = {
3531
+ name: "tt",
3532
+ directives,
3533
+ wrapIf: (exp, content, renderMustache) => `<block ${directives.ifAttr}="${renderMustache(exp)}">${content}</block>`,
3534
+ wrapElseIf: (exp, content, renderMustache) => `<block ${directives.elifAttr}="${renderMustache(exp)}">${content}</block>`,
3535
+ wrapElse: (content) => `<block ${directives.elseAttr}>${content}</block>`,
3504
3536
  forAttrs: (listExp, renderMustache, item, index) => {
3505
- const attrs = [`wx:for="${renderMustache(listExp)}"`];
3506
- if (item) attrs.push(`wx:for-item="${item}"`);
3507
- if (index) attrs.push(`wx:for-index="${index}"`);
3537
+ const attrs = [`${directives.forAttr}="${renderMustache(listExp)}"`];
3538
+ if (item) attrs.push(`${directives.forItemAttr}="${item}"`);
3539
+ if (index) attrs.push(`${directives.forIndexAttr}="${index}"`);
3508
3540
  return attrs;
3509
3541
  },
3510
3542
  keyThisValue: "*this",
3511
- keyAttr: (value) => `wx:key="${value}"`,
3543
+ keyAttr: (value) => `${directives.keyAttr}="${value}"`,
3512
3544
  mapEventName: (eventName) => eventMap[eventName] || eventName,
3513
3545
  eventBindingAttr: (eventName) => {
3514
3546
  const { prefix, name } = parseEventBinding(eventName);
@@ -3523,20 +3555,37 @@ const wechatPlatform = {
3523
3555
  };
3524
3556
  //#endregion
3525
3557
  //#region src/plugins/vue/compiler/template/platforms/index.ts
3526
- const TEMPLATE_PLATFORMS = {
3527
- weapp: wechatPlatform,
3558
+ const TEMPLATE_PRESET_PLATFORMS = {
3559
+ wechat: defaultMiniProgramPlatform,
3528
3560
  alipay: alipayPlatform,
3529
3561
  tt: ttPlatform,
3530
- swan: swanPlatform,
3531
- jd: wechatPlatform,
3532
- xhs: wechatPlatform
3562
+ swan: swanPlatform
3533
3563
  };
3534
3564
  /**
3535
- * 获取指定平台的模板适配器,默认回退到 wechat。
3565
+ * 获取默认模板适配器。
3566
+ */
3567
+ function getDefaultMiniProgramTemplatePlatform() {
3568
+ return TEMPLATE_PRESET_PLATFORMS[getMiniProgramTemplatePreset()];
3569
+ }
3570
+ /**
3571
+ * 获取默认小程序平台适配器。
3572
+ */
3573
+ const getDefaultMiniProgramPlatform = getDefaultMiniProgramTemplatePlatform;
3574
+ /**
3575
+ * 默认模板平台对象别名,便于调用方避免继续依赖具体宿主命名。
3576
+ */
3577
+ const defaultMiniProgramTemplatePlatform = getDefaultMiniProgramTemplatePlatform();
3578
+ /**
3579
+ * 微信模板平台兼容别名。
3580
+ *
3581
+ * 新代码应优先使用 defaultMiniProgramPlatform/defaultPlatform。
3582
+ */
3583
+ const wechatPlatform = defaultMiniProgramPlatform;
3584
+ /**
3585
+ * 获取指定平台的模板适配器,默认回退到默认模板平台。
3536
3586
  */
3537
3587
  function getMiniProgramTemplatePlatform(platform) {
3538
- if (!platform) return wechatPlatform;
3539
- return TEMPLATE_PLATFORMS[platform] ?? wechatPlatform;
3588
+ return TEMPLATE_PRESET_PLATFORMS[getMiniProgramTemplatePreset(platform)] ?? getDefaultMiniProgramTemplatePlatform();
3540
3589
  }
3541
3590
  //#endregion
3542
3591
  //#region src/plugins/jsx/compileJsx/analysis.ts
@@ -3804,7 +3853,7 @@ function compileJsxElement(node, context) {
3804
3853
  //#region src/plugins/jsx/compileJsx/template.ts
3805
3854
  function createJsxCompileContext(options) {
3806
3855
  return {
3807
- platform: options?.template?.platform ?? wechatPlatform,
3856
+ platform: options?.template?.platform ?? getMiniProgramTemplatePlatform(),
3808
3857
  mustacheInterpolation: options?.template?.mustacheInterpolation ?? "compact",
3809
3858
  warnings: [],
3810
3859
  inlineExpressions: [],
@@ -5259,16 +5308,15 @@ const INLINE_GLOBALS = new Set([
5259
5308
  "clearTimeout",
5260
5309
  "setInterval",
5261
5310
  "clearInterval",
5262
- "wx",
5263
5311
  "Page",
5264
5312
  "App",
5265
5313
  "Component",
5266
5314
  "requirePlugin",
5267
5315
  "getApp",
5268
5316
  "getCurrentPages",
5269
- "WechatMiniprogram",
5270
5317
  "ctx",
5271
- "scope"
5318
+ "scope",
5319
+ ...getMiniProgramRuntimeGlobalKeys()
5272
5320
  ]);
5273
5321
  const IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
5274
5322
  const SIMPLE_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
@@ -5430,9 +5478,9 @@ const JS_RUNTIME_GLOBALS = new Set([
5430
5478
  "arguments",
5431
5479
  "globalThis",
5432
5480
  "__wevuUnref",
5433
- "wx",
5434
5481
  "getApp",
5435
- "getCurrentPages"
5482
+ "getCurrentPages",
5483
+ ...getMiniProgramRuntimeGlobalKeys()
5436
5484
  ]);
5437
5485
  function parseJsExpressionFile(exp) {
5438
5486
  try {
@@ -5767,7 +5815,7 @@ function transformBindDirective(node, context, forInfo) {
5767
5815
  const trimmed = expValue.trim();
5768
5816
  const warnKeyFallback = (reason) => {
5769
5817
  if (!forInfo) return;
5770
- context.warnings.push(`v-for :key "${trimmed}" ${reason},已降级为 wx:key="${context.platform.keyThisValue}"。建议使用稳定的基础类型 key(例如 item.id)。`);
5818
+ context.warnings.push(`v-for :key "${trimmed}" ${reason},已降级为 ${context.platform.keyAttr(context.platform.keyThisValue)}。建议使用稳定的基础类型 key(例如 item.id)。`);
5771
5819
  };
5772
5820
  if (forInfo?.item && trimmed === forInfo.item) return context.platform.keyAttr(context.platform.keyThisValue);
5773
5821
  if (forInfo?.key && trimmed === forInfo.key) return context.platform.keyAttr(context.platform.keyThisValue);
@@ -6757,7 +6805,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6757
6805
  source: template,
6758
6806
  filename,
6759
6807
  warnings,
6760
- platform: options?.platform ?? wechatPlatform,
6808
+ platform: options?.platform ?? getMiniProgramTemplatePlatform(),
6761
6809
  htmlTagToWxmlMap,
6762
6810
  htmlTagToWxmlTagClass: options?.htmlTagToWxmlTagClass ?? true,
6763
6811
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
@@ -7636,4 +7684,4 @@ async function compileVueFile(source, filename, options) {
7636
7684
  return result;
7637
7685
  }
7638
7686
  //#endregion
7639
- export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, 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 };
7687
+ export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.15.6",
4
+ "version": "6.15.8",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -50,9 +50,9 @@
50
50
  "pathe": "^2.0.3",
51
51
  "vue": "^3.5.32",
52
52
  "@weapp-core/constants": "^0.1.1",
53
- "@weapp-core/shared": "3.0.3",
54
- "rolldown-require": "2.0.13",
55
- "@weapp-vite/ast": "6.15.6"
53
+ "@weapp-core/shared": "3.0.4",
54
+ "@weapp-vite/ast": "6.15.8",
55
+ "rolldown-require": "2.0.13"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public",