@wevu/compiler 6.14.3 → 6.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -250,6 +250,7 @@ interface ForParseResult {
250
250
  */
251
251
  interface TemplateCompileOptions {
252
252
  platform?: MiniProgramPlatform;
253
+ htmlTagToWxml?: boolean | Record<string, string>;
253
254
  scopedSlotsCompiler?: ScopedSlotsCompilerMode;
254
255
  scopedSlotsRequireProps?: boolean;
255
256
  slotMultipleInstance?: boolean;
package/dist/index.mjs CHANGED
@@ -2956,6 +2956,16 @@ function transformScript(source, options) {
2956
2956
  };
2957
2957
  }
2958
2958
  //#endregion
2959
+ //#region src/inlineDataset.ts
2960
+ const NON_ALNUM_RE = /[^a-z0-9]+/gi;
2961
+ const LEADING_TRAILING_DASH_RE = /^-+|-+$/g;
2962
+ function normalizeEventDatasetSuffix(eventName) {
2963
+ return eventName.trim().replace(NON_ALNUM_RE, "-").replace(LEADING_TRAILING_DASH_RE, "").toLowerCase() || "event";
2964
+ }
2965
+ function createInlineExpressionId(seed) {
2966
+ return `i${seed.toString(36)}`;
2967
+ }
2968
+ //#endregion
2959
2969
  //#region src/plugins/vue/compiler/template/expression/wxml.ts
2960
2970
  function templateLiteralToConcat(node) {
2961
2971
  const segments = [];
@@ -3135,7 +3145,7 @@ function collectExpressionScopeBindings(exp, context) {
3135
3145
  }
3136
3146
  function registerInlineExpression$1(exp, context) {
3137
3147
  const scopeKeys = collectExpressionScopeBindings(exp, context);
3138
- const id = `__wv_inline_${context.inlineExpressionSeed++}`;
3148
+ const id = createInlineExpressionId(context.inlineExpressionSeed++);
3139
3149
  context.inlineExpressions.push({
3140
3150
  id,
3141
3151
  expression: printExpression(exp),
@@ -3585,25 +3595,20 @@ function lowerEventName(name) {
3585
3595
  if (!name) return name;
3586
3596
  return name.replace(LEADING_UPPER_RE, (s) => s.toLowerCase()).replace(UPPER_CHAR_RE, (s) => s.toLowerCase());
3587
3597
  }
3588
- function toEventBindingName(rawName, context) {
3598
+ function resolveMappedEventName(rawName, context) {
3589
3599
  const resolveEvent = (name) => context.platform.mapEventName(lowerEventName(name));
3590
- if (CAPTURE_BIND_EVENT_RE.test(rawName)) {
3591
- const eventName = resolveEvent(rawName.slice(11));
3592
- return context.platform.eventBindingAttr(`capture-bind:${eventName}`);
3593
- }
3594
- if (CAPTURE_CATCH_EVENT_RE.test(rawName)) {
3595
- const eventName = resolveEvent(rawName.slice(12));
3596
- return context.platform.eventBindingAttr(`capture-catch:${eventName}`);
3597
- }
3598
- if (MUT_BIND_EVENT_RE.test(rawName)) {
3599
- const eventName = resolveEvent(rawName.slice(7));
3600
- return context.platform.eventBindingAttr(`mut-bind:${eventName}`);
3601
- }
3602
- if (CATCH_EVENT_RE.test(rawName)) {
3603
- const eventName = resolveEvent(rawName.slice(5));
3604
- return context.platform.eventBindingAttr(`catch:${eventName}`);
3605
- }
3606
- const eventName = resolveEvent(rawName.slice(2));
3600
+ if (CAPTURE_BIND_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(11));
3601
+ if (CAPTURE_CATCH_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(12));
3602
+ if (MUT_BIND_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(7));
3603
+ if (CATCH_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(5));
3604
+ return resolveEvent(rawName.slice(2));
3605
+ }
3606
+ function toEventBindingName(rawName, context) {
3607
+ const eventName = resolveMappedEventName(rawName, context);
3608
+ if (CAPTURE_BIND_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`capture-bind:${eventName}`);
3609
+ if (CAPTURE_CATCH_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`capture-catch:${eventName}`);
3610
+ if (MUT_BIND_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`mut-bind:${eventName}`);
3611
+ if (CATCH_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`catch:${eventName}`);
3607
3612
  return context.platform.eventBindingAttr(`bind:${eventName}`);
3608
3613
  }
3609
3614
  function readJsxAttributeExpression(value) {
@@ -3626,13 +3631,14 @@ function extractJsxKeyExpression(node) {
3626
3631
  }
3627
3632
  function compileEventAttribute(name, value, context) {
3628
3633
  const bindAttr = toEventBindingName(name, context);
3634
+ const eventSuffix = normalizeEventDatasetSuffix(resolveMappedEventName(name, context));
3629
3635
  const exp = readJsxAttributeExpression(value);
3630
3636
  if (!exp) return [];
3631
3637
  if (t.isStringLiteral(exp) && exp.value) return [`${bindAttr}="${escapeAttr(exp.value)}"`];
3632
3638
  if (t.isIdentifier(exp)) return [`${bindAttr}="${escapeAttr(exp.name)}"`];
3633
3639
  if (t.isMemberExpression(exp) && !exp.computed && t.isThisExpression(exp.object) && t.isIdentifier(exp.property)) return [`${bindAttr}="${escapeAttr(exp.property.name)}"`];
3634
3640
  const inline = registerInlineExpression$1(exp, context);
3635
- const attrs = [`data-wv-inline-id="${inline.id}"`, `${bindAttr}="__weapp_vite_inline"`];
3641
+ const attrs = [`data-wi-${eventSuffix}="${inline.id}"`, `${bindAttr}="__weapp_vite_inline"`];
3636
3642
  inline.scopeKeys.forEach((scopeKey, index) => {
3637
3643
  attrs.push(`data-wv-s${index}="${renderMustache$1(scopeKey, context)}"`);
3638
3644
  });
@@ -4592,6 +4598,64 @@ function getClassStyleWxsSource(options = {}) {
4592
4598
  ].join("\n");
4593
4599
  }
4594
4600
  //#endregion
4601
+ //#region src/plugins/vue/compiler/template/htmlTagMapping.ts
4602
+ const DEFAULT_HTML_TO_WXML_TAG_MAP = {
4603
+ a: "navigator",
4604
+ article: "view",
4605
+ aside: "view",
4606
+ b: "text",
4607
+ blockquote: "view",
4608
+ button: "button",
4609
+ code: "text",
4610
+ dd: "view",
4611
+ div: "view",
4612
+ dl: "view",
4613
+ dt: "view",
4614
+ em: "text",
4615
+ figcaption: "view",
4616
+ figure: "view",
4617
+ footer: "view",
4618
+ form: "form",
4619
+ h1: "view",
4620
+ h2: "view",
4621
+ h3: "view",
4622
+ h4: "view",
4623
+ h5: "view",
4624
+ h6: "view",
4625
+ header: "view",
4626
+ i: "text",
4627
+ img: "image",
4628
+ input: "input",
4629
+ label: "label",
4630
+ li: "view",
4631
+ main: "view",
4632
+ nav: "view",
4633
+ ol: "view",
4634
+ p: "view",
4635
+ pre: "view",
4636
+ section: "view",
4637
+ small: "text",
4638
+ span: "text",
4639
+ strong: "text",
4640
+ textarea: "textarea",
4641
+ u: "text",
4642
+ ul: "view"
4643
+ };
4644
+ function resolveHtmlTagToWxmlMap(value) {
4645
+ if (value === false) return;
4646
+ if (value === true || value === void 0) return { ...DEFAULT_HTML_TO_WXML_TAG_MAP };
4647
+ return {
4648
+ ...DEFAULT_HTML_TO_WXML_TAG_MAP,
4649
+ ...Object.fromEntries(Object.entries(value).map(([key, mapped]) => [key.toLowerCase(), mapped]))
4650
+ };
4651
+ }
4652
+ function resolveTemplateTagName(tag, context) {
4653
+ if (!tag) return tag;
4654
+ const lowerTag = tag.toLowerCase();
4655
+ if (tag !== lowerTag) return tag;
4656
+ return context.htmlTagToWxmlMap?.[lowerTag] ?? tag;
4657
+ }
4658
+ //#endregion
4595
4659
  //#region src/plugins/vue/compiler/template/elements/forExpression.ts
4596
4660
  const IDENTIFIER_RE$4 = /^[A-Z_$][\w$]*$/i;
4597
4661
  const FOR_ITEM_ALIAS_PLACEHOLDER = "__wv_for_item__";
@@ -5286,7 +5350,7 @@ function registerInlineExpression(exp, context) {
5286
5350
  const indexBindings = buildInlineIndexBindings(context);
5287
5351
  const scopeResolvers = buildScopeResolvers(usedLocals, context, slotProps, indexBindings);
5288
5352
  const asset = {
5289
- id: `__wv_inline_${context.inlineExpressionSeed++}`,
5353
+ id: createInlineExpressionId(context.inlineExpressionSeed++),
5290
5354
  expression: updatedExpression,
5291
5355
  scopeKeys: usedLocals
5292
5356
  };
@@ -5781,11 +5845,6 @@ const isSimpleHandler = (value) => SIMPLE_IDENTIFIER_RE.test(value);
5781
5845
  function shouldUseDetailPayload(options) {
5782
5846
  return options?.isComponent === true;
5783
5847
  }
5784
- const NON_ALNUM_RE = /[^a-z0-9]+/gi;
5785
- const LEADING_TRAILING_DASH_RE = /^-+|-+$/g;
5786
- function normalizeEventDatasetSuffix(eventName) {
5787
- return eventName.trim().replace(NON_ALNUM_RE, "-").replace(LEADING_TRAILING_DASH_RE, "").toLowerCase() || "event";
5788
- }
5789
5848
  const QUOTE_RE = /"/g;
5790
5849
  function buildInlineScopeAttrs(scopeBindings, context) {
5791
5850
  return scopeBindings.map((binding, index) => {
@@ -5822,14 +5881,14 @@ function transformOnDirective(node, context, options) {
5822
5881
  const eventSuffix = normalizeEventDatasetSuffix(mappedEvent);
5823
5882
  const eventPrefix = resolveEventPrefix(node.modifiers);
5824
5883
  const bindAttr = context.platform.eventBindingAttr(`${eventPrefix}:${mappedEvent}`);
5825
- const detailAttr = useDetailPayload ? `data-wv-event-detail-${eventSuffix}="1"` : "";
5884
+ const detailAttr = useDetailPayload ? `data-wd-${eventSuffix}="1"` : "";
5826
5885
  if (context.rewriteScopedSlot) {
5827
5886
  if (inlineExpression) {
5828
5887
  const scopeAttrs = buildInlineScopeAttrs(inlineExpression.scopeBindings, context);
5829
5888
  const indexAttrs = buildInlineIndexAttrs(inlineExpression.indexBindings, context);
5830
5889
  return [
5831
5890
  detailAttr,
5832
- `data-wv-inline-id-${eventSuffix}="${inlineExpression.id}"`,
5891
+ `data-wi-${eventSuffix}="${inlineExpression.id}"`,
5833
5892
  ...scopeAttrs,
5834
5893
  ...indexAttrs,
5835
5894
  `${bindAttr}="__weapp_vite_owner"`
@@ -5837,7 +5896,7 @@ function transformOnDirective(node, context, options) {
5837
5896
  }
5838
5897
  if (!isInlineExpression && rawExpValue) return [
5839
5898
  detailAttr,
5840
- `data-wv-handler-${eventSuffix}="${rawExpValue}"`,
5899
+ `data-wh-${eventSuffix}="${rawExpValue}"`,
5841
5900
  `${bindAttr}="__weapp_vite_owner"`
5842
5901
  ].filter(Boolean).join(" ");
5843
5902
  if (isInlineExpression) {
@@ -5851,7 +5910,7 @@ function transformOnDirective(node, context, options) {
5851
5910
  const indexAttrs = buildInlineIndexAttrs(inlineExpression.indexBindings, context);
5852
5911
  return [
5853
5912
  detailAttr,
5854
- `data-wv-inline-id-${eventSuffix}="${inlineExpression.id}"`,
5913
+ `data-wi-${eventSuffix}="${inlineExpression.id}"`,
5855
5914
  ...scopeAttrs,
5856
5915
  ...indexAttrs,
5857
5916
  `${bindAttr}="__weapp_vite_inline"`
@@ -5898,7 +5957,8 @@ function isBuiltinTag(tag) {
5898
5957
  }
5899
5958
  function collectElementAttributes(node, context, options) {
5900
5959
  const { props } = node;
5901
- const isComponentElement = options?.isComponent ?? !isBuiltinTag(node.tag);
5960
+ const resolvedTag = options?.resolvedTag ?? resolveTemplateTagName(node.tag, context);
5961
+ const isComponentElement = options?.isComponent ?? !isBuiltinTag(resolvedTag);
5902
5962
  const attrs = options?.extraAttrs ? [...options.extraAttrs] : [];
5903
5963
  let staticClass;
5904
5964
  let staticId;
@@ -6402,11 +6462,11 @@ function transformComponentElement(node, context, transformNode) {
6402
6462
  //#endregion
6403
6463
  //#region src/plugins/vue/compiler/template/elements/tag-normal.ts
6404
6464
  function transformNormalElement(node, context, transformNode) {
6405
- const { tag } = node;
6465
+ const tag = resolveTemplateTagName(node.tag, context);
6406
6466
  const slotDirective = findSlotDirective(node);
6407
6467
  const templateSlotChildren = node.children.filter((child) => child.type === NodeTypes.ELEMENT && child.tag === "template" && findSlotDirective(child));
6408
6468
  if (slotDirective || templateSlotChildren.length > 0) return transformComponentWithSlots(node, context, transformNode);
6409
- const { attrs, vTextExp } = collectElementAttributes(node, context);
6469
+ const { attrs, vTextExp } = collectElementAttributes(node, context, { resolvedTag: tag });
6410
6470
  let children = "";
6411
6471
  if (node.children.length > 0) children = node.children.map((child) => transformNode(child, context)).join("");
6412
6472
  if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
@@ -6491,12 +6551,13 @@ function transformForElement(node, context, transformNode) {
6491
6551
  });
6492
6552
  const { attrs, vTextExp } = collectElementAttributes(elementWithoutFor, context, {
6493
6553
  forInfo,
6494
- extraAttrs
6554
+ extraAttrs,
6555
+ resolvedTag: resolveTemplateTagName(elementWithoutFor.tag, context)
6495
6556
  });
6496
6557
  let children = "";
6497
6558
  if (elementWithoutFor.children.length > 0) children = elementWithoutFor.children.map((child) => transformNode(child, context)).join("");
6498
6559
  if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
6499
- const { tag } = elementWithoutFor;
6560
+ const tag = resolveTemplateTagName(elementWithoutFor.tag, context);
6500
6561
  const attrString = attrs.length ? ` ${attrs.join(" ")}` : "";
6501
6562
  return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
6502
6563
  }));
@@ -6645,6 +6706,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6645
6706
  const resolvedRuntime = runtimeMode === "auto" ? options?.wxsExtension ? "wxs" : "js" : runtimeMode === "wxs" && !options?.wxsExtension ? "js" : runtimeMode;
6646
6707
  const wxsExtension = options?.wxsExtension;
6647
6708
  const scopedSlotsRequireProps = options?.scopedSlotsRequireProps ?? options?.scopedSlotsCompiler !== "augmented";
6709
+ const htmlTagToWxmlMap = resolveHtmlTagToWxmlMap(options?.htmlTagToWxml);
6648
6710
  try {
6649
6711
  const ast = parse$1(template, {
6650
6712
  isVoidTag: (tag) => HTML_VOID_TAGS.has(tag),
@@ -6657,6 +6719,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6657
6719
  filename,
6658
6720
  warnings,
6659
6721
  platform: options?.platform ?? wechatPlatform,
6722
+ htmlTagToWxmlMap,
6660
6723
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
6661
6724
  scopedSlotsRequireProps,
6662
6725
  slotMultipleInstance: options?.slotMultipleInstance ?? true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.14.3",
4
+ "version": "6.15.0",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -44,14 +44,14 @@
44
44
  "@vue/compiler-core": "^3.5.32",
45
45
  "@vue/compiler-dom": "^3.5.32",
46
46
  "comment-json": "^4.6.2",
47
- "lru-cache": "^11.3.2",
47
+ "lru-cache": "^11.3.3",
48
48
  "magic-string": "^0.30.21",
49
49
  "merge": "^2.1.1",
50
50
  "pathe": "^2.0.3",
51
51
  "vue": "^3.5.32",
52
52
  "@weapp-core/shared": "3.0.3",
53
- "@weapp-vite/ast": "6.14.3",
54
- "rolldown-require": "2.0.12"
53
+ "@weapp-vite/ast": "6.15.0",
54
+ "rolldown-require": "2.0.13"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public",