@wevu/compiler 6.20.1 → 6.20.2

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.
Files changed (2) hide show
  1. package/dist/index.mjs +30 -19
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -4030,14 +4030,14 @@ function normalizeWxmlExpression(exp) {
4030
4030
  path.replaceWith(lowerOptionalChain(path.node));
4031
4031
  path.skip();
4032
4032
  } },
4033
- LogicalExpression(path) {
4033
+ LogicalExpression: { exit(path) {
4034
4034
  if (path.node.operator !== "??") return;
4035
4035
  const left = path.node.left;
4036
4036
  const right = path.node.right;
4037
4037
  const test = t.binaryExpression("!=", t.cloneNode(left), t.nullLiteral());
4038
4038
  path.replaceWith(t.conditionalExpression(test, t.cloneNode(left), t.cloneNode(right)));
4039
4039
  path.skip();
4040
- },
4040
+ } },
4041
4041
  TemplateLiteral(path) {
4042
4042
  if (t.isTaggedTemplateExpression(path.parent)) return;
4043
4043
  path.replaceWith(templateLiteralToConcat(path.node));
@@ -6453,10 +6453,13 @@ function resolveHtmlTagToWxmlMap(value) {
6453
6453
  ...Object.fromEntries(Object.entries(value).map(([key, mapped]) => [key.toLowerCase(), mapped]))
6454
6454
  };
6455
6455
  }
6456
+ function normalizeTemplateTagName(tag) {
6457
+ return tag.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
6458
+ }
6456
6459
  function resolveTemplateTagName(tag, context) {
6457
6460
  if (!tag) return tag;
6458
6461
  const lowerTag = tag.toLowerCase();
6459
- if (tag !== lowerTag) return tag;
6462
+ if (tag !== lowerTag) return normalizeTemplateTagName(tag);
6460
6463
  return context.htmlTagToWxmlMap?.[lowerTag] ?? tag;
6461
6464
  }
6462
6465
  function resolveMappedHtmlTagClassName(tag, context, resolvedTag) {
@@ -9381,7 +9384,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
9381
9384
  if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
9382
9385
  const mergedAttrs = [...extraAttrs, ...attrs];
9383
9386
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
9384
- const { tag } = node;
9387
+ const tag = resolveTemplateTagName(node.tag, context);
9385
9388
  return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
9386
9389
  }
9387
9390
  const scopedSlotDeclarations = [];
@@ -9394,7 +9397,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
9394
9397
  const ownerComponentName = context.componentNameMap?.[node.tag];
9395
9398
  for (const decl of scopedSlotDeclarations) {
9396
9399
  const slotKey = resolveSlotKey(context, decl.name);
9397
- const { componentName } = createScopedSlotComponent(context, slotKey, decl.props, decl.children, transformNode, { hostComponentName: node.tag });
9400
+ const { componentName } = createScopedSlotComponent(context, slotKey, decl.props, decl.children, transformNode, { hostComponentName: resolveTemplateTagName(node.tag, context) });
9398
9401
  slotNames.push({
9399
9402
  name: stringifySlotName(decl.name, context),
9400
9403
  condition: decl.condition
@@ -9423,7 +9426,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
9423
9426
  mergedAttrs.push(`${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(ownerIdExp, context)}"`);
9424
9427
  }
9425
9428
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
9426
- const { tag } = node;
9429
+ const tag = resolveTemplateTagName(node.tag, context);
9427
9430
  const plainSlotContent = slotDirective ? plainSlotDeclarations.map((decl) => renderSlotFallback(decl, context, transformNode, {
9428
9431
  component: node.tag,
9429
9432
  componentName: ownerComponentName,
@@ -9486,7 +9489,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
9486
9489
  if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
9487
9490
  const mergedAttrs = [...extraAttrs, ...attrs];
9488
9491
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
9489
- const { tag } = node;
9492
+ const tag = resolveTemplateTagName(node.tag, context);
9490
9493
  return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
9491
9494
  }
9492
9495
  if (slotDeclarations.some((decl) => Object.keys(decl.props).length)) context.warnings.push("已禁用作用域插槽参数,插槽绑定将被忽略。");
@@ -9506,7 +9509,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
9506
9509
  condition: decl.condition
9507
9510
  })), context, { forInfo: options?.forInfo });
9508
9511
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
9509
- const { tag } = node;
9512
+ const tag = resolveTemplateTagName(node.tag, context);
9510
9513
  return renderedSlots ? `<${tag}${attrString}>${renderedSlots}</${tag}>` : `<${tag}${attrString} />`;
9511
9514
  }
9512
9515
  function transformComponentElement(node, context, transformNode) {
@@ -9958,9 +9961,6 @@ function isWevuSfcComponent(result) {
9958
9961
  function isVueSfcSource(source) {
9959
9962
  return source.endsWith(".vue");
9960
9963
  }
9961
- function pascalToKebab(name) {
9962
- return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
9963
- }
9964
9964
  function kebabToCamel(name) {
9965
9965
  return name.replace(/-([a-z0-9])/g, (_, character) => character.toUpperCase());
9966
9966
  }
@@ -10044,12 +10044,12 @@ async function resolveVueSfcStaticComponentMeta(resolvedId, options) {
10044
10044
  function registerComponentName(result, tag, componentName) {
10045
10045
  if (!componentName) return;
10046
10046
  result.componentNameMap[tag] = componentName;
10047
- result.componentNameMap[pascalToKebab(tag)] = componentName;
10047
+ result.componentNameMap[normalizeTemplateTagName(tag)] = componentName;
10048
10048
  }
10049
10049
  function registerMiniProgramComponentTag(result, tag, isComponent) {
10050
10050
  if (!isComponent) return;
10051
10051
  result.miniProgramComponentTags.add(tag);
10052
- result.miniProgramComponentTags.add(pascalToKebab(tag));
10052
+ result.miniProgramComponentTags.add(normalizeTemplateTagName(tag));
10053
10053
  }
10054
10054
  function createComponentSourceInfo() {
10055
10055
  return {
@@ -10173,7 +10173,7 @@ async function collectScriptSetupUsingComponents(options) {
10173
10173
  }
10174
10174
  if (isVueSfcSource(importSource) || isWevuSfcComponent(resolved)) {
10175
10175
  result.wevuComponentTags.add(localName);
10176
- result.wevuComponentTags.add(pascalToKebab(localName));
10176
+ result.wevuComponentTags.add(normalizeTemplateTagName(localName));
10177
10177
  }
10178
10178
  registerComponentName(result, localName, componentMeta.componentName);
10179
10179
  for (const tag of templateTags) registerComponentName(result, tag, componentMeta.componentName);
@@ -10348,6 +10348,13 @@ function collectTemplateAutoImportTags(template, filename, warn) {
10348
10348
  shouldCollect: isAutoImportCandidateTag
10349
10349
  });
10350
10350
  }
10351
+ function normalizeUsingComponents(config) {
10352
+ const raw = config.usingComponents;
10353
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
10354
+ const usingComponents = {};
10355
+ for (const [name, from] of Object.entries(raw)) usingComponents[normalizeTemplateTagName(name)] = from;
10356
+ config.usingComponents = usingComponents;
10357
+ }
10351
10358
  async function compileConfigPhase(params) {
10352
10359
  const { descriptor, filename, autoUsingComponentsMap, autoImportTagsMap: precomputedAutoImportTagsMap, autoUsingComponents, autoImportTags, jsonDefaults, mergeJson, scriptSetupMacroConfig, result, warn } = params;
10353
10360
  let configObj;
@@ -10375,14 +10382,17 @@ async function compileConfigPhase(params) {
10375
10382
  }
10376
10383
  if (Object.keys(autoUsingComponentsMap).length > 0 || Object.keys(autoImportTagsMap).length > 0) {
10377
10384
  const existingRaw = configObj?.usingComponents;
10378
- const usingComponents = existingRaw && typeof existingRaw === "object" && !Array.isArray(existingRaw) ? existingRaw : {};
10385
+ const usingComponents = {};
10386
+ if (existingRaw && typeof existingRaw === "object" && !Array.isArray(existingRaw)) for (const [name, from] of Object.entries(existingRaw)) usingComponents[normalizeTemplateTagName(name)] = from;
10379
10387
  for (const [name, from] of Object.entries(autoImportTagsMap)) {
10380
- if (Reflect.has(usingComponents, name) && usingComponents[name] !== from) autoImportTags?.warn?.(`[Vue 编译] usingComponents 冲突:${filename} 中 <json>.usingComponents['${name}']='${usingComponents[name]}' 将被模板标签自动引入覆盖为 '${from}'`);
10381
- usingComponents[name] = from;
10388
+ const normalizedName = normalizeTemplateTagName(name);
10389
+ if (Reflect.has(usingComponents, normalizedName) && usingComponents[normalizedName] !== from) autoImportTags?.warn?.(`[Vue 编译] usingComponents 冲突:${filename} 中 <json>.usingComponents['${normalizedName}']='${usingComponents[normalizedName]}' 将被模板标签自动引入覆盖为 '${from}'`);
10390
+ usingComponents[normalizedName] = from;
10382
10391
  }
10383
10392
  for (const [name, from] of Object.entries(autoUsingComponentsMap)) {
10384
- if (Reflect.has(usingComponents, name) && usingComponents[name] !== from) autoUsingComponents?.warn?.(`[Vue 编译] usingComponents 冲突:${filename} 中 <json>.usingComponents['${name}']='${usingComponents[name]}' 将被 <script setup> 导入覆盖为 '${from}'`);
10385
- usingComponents[name] = from;
10393
+ const normalizedName = normalizeTemplateTagName(name);
10394
+ if (Reflect.has(usingComponents, normalizedName) && usingComponents[normalizedName] !== from) autoUsingComponents?.warn?.(`[Vue 编译] usingComponents 冲突:${filename} 中 <json>.usingComponents['${normalizedName}']='${usingComponents[normalizedName]}' 将被 <script setup> 导入覆盖为 '${from}'`);
10395
+ usingComponents[normalizedName] = from;
10386
10396
  }
10387
10397
  configObj = mergeJson(configObj ?? {}, { usingComponents }, "auto-using-components");
10388
10398
  }
@@ -10394,6 +10404,7 @@ async function compileConfigPhase(params) {
10394
10404
  }
10395
10405
  if (jsonDefaults && Object.keys(jsonDefaults).length > 0) configObj = mergeJson(configObj ?? {}, jsonDefaults, "defaults");
10396
10406
  if (scriptSetupMacroConfig && Object.keys(scriptSetupMacroConfig).length > 0) configObj = mergeJson(configObj ?? {}, scriptSetupMacroConfig, "macro");
10407
+ if (configObj) normalizeUsingComponents(configObj);
10397
10408
  if (configObj && Object.keys(configObj).length > 0) result.config = JSON.stringify(configObj, null, 2);
10398
10409
  }
10399
10410
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.20.1",
4
+ "version": "6.20.2",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -47,16 +47,16 @@
47
47
  "@vue/compiler-dom": "^3.5.41",
48
48
  "comment-json": "^5.0.0",
49
49
  "lru-cache": "^11.5.2",
50
- "magic-string": "^1.1.0",
50
+ "magic-string": "^1.2.0",
51
51
  "merge": "^2.1.1",
52
52
  "pathe": "^2.0.3",
53
53
  "postcss": "^8.5.26",
54
54
  "postcss-selector-parser": "^7.1.5",
55
55
  "vue": "^3.5.41",
56
56
  "@weapp-core/constants": "0.1.17",
57
- "@weapp-core/shared": "3.1.0",
58
- "@weapp-vite/ast": "6.20.1",
59
- "rolldown-require": "2.0.24"
57
+ "@weapp-core/shared": "3.1.1",
58
+ "@weapp-vite/ast": "6.20.2",
59
+ "rolldown-require": "2.0.25"
60
60
  },
61
61
  "publishConfig": {
62
62
  "access": "public",