@wevu/compiler 6.15.4 → 6.15.6

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
@@ -251,6 +251,7 @@ interface ForParseResult {
251
251
  interface TemplateCompileOptions {
252
252
  platform?: MiniProgramPlatform;
253
253
  htmlTagToWxml?: boolean | Record<string, string>;
254
+ htmlTagToWxmlTagClass?: boolean;
254
255
  scopedSlotsCompiler?: ScopedSlotsCompilerMode;
255
256
  scopedSlotsRequireProps?: boolean;
256
257
  slotMultipleInstance?: boolean;
package/dist/index.mjs CHANGED
@@ -4274,23 +4274,6 @@ function getSfcCheckMtime(config) {
4274
4274
  const CSS_RULE_RE = /([^{]+)(\{[^}]*\})/g;
4275
4275
  const CSS_CLASS_RE = /\.([a-z_][\w-]*)(?:\[[^\]]+\])?\s*\{/gi;
4276
4276
  /**
4277
- * 将 Vue SFC 的 style 块转换为 WXSS
4278
- */
4279
- function compileVueStyleToWxss(styleBlock, options) {
4280
- const { id, scoped, modules } = options;
4281
- let code = styleBlock.content;
4282
- if (scoped || styleBlock.scoped) code = transformScopedCss(code, id);
4283
- if (modules || styleBlock.module) {
4284
- const moduleName = typeof styleBlock.module === "string" ? styleBlock.module : "$style";
4285
- const moduleResult = transformCssModules(code, id);
4286
- return {
4287
- code: moduleResult.code,
4288
- modules: { [moduleName]: moduleResult.classes }
4289
- };
4290
- }
4291
- return { code };
4292
- }
4293
- /**
4294
4277
  * 转换 scoped CSS
4295
4278
  * 为每个选择器添加特定的 scoped 属性
4296
4279
  */
@@ -4307,6 +4290,22 @@ function transformScopedCss(source, id) {
4307
4290
  });
4308
4291
  }
4309
4292
  /**
4293
+ * 样式转换:CSS → WXSS
4294
+ * 处理小程序不支持的 CSS 特性
4295
+ */
4296
+ /**
4297
+ * 生成简单的 hash
4298
+ */
4299
+ function generateHash(str) {
4300
+ let hash = 0;
4301
+ for (let i = 0; i < str.length; i++) {
4302
+ const char = str.charCodeAt(i);
4303
+ hash = (hash << 5) - hash + char;
4304
+ hash = hash & hash;
4305
+ }
4306
+ return Math.abs(hash).toString(36) + str.length.toString(36);
4307
+ }
4308
+ /**
4310
4309
  * 转换 CSS Modules
4311
4310
  */
4312
4311
  function transformCssModules(source, id) {
@@ -4331,20 +4330,21 @@ function transformCssModules(source, id) {
4331
4330
  };
4332
4331
  }
4333
4332
  /**
4334
- * 样式转换:CSS WXSS
4335
- * 处理小程序不支持的 CSS 特性
4336
- */
4337
- /**
4338
- * 生成简单的 hash
4333
+ * Vue SFC 的 style 块转换为 WXSS
4339
4334
  */
4340
- function generateHash(str) {
4341
- let hash = 0;
4342
- for (let i = 0; i < str.length; i++) {
4343
- const char = str.charCodeAt(i);
4344
- hash = (hash << 5) - hash + char;
4345
- hash = hash & hash;
4335
+ function compileVueStyleToWxss(styleBlock, options) {
4336
+ const { id, scoped, modules } = options;
4337
+ let code = styleBlock.content;
4338
+ if (scoped || styleBlock.scoped) code = transformScopedCss(code, id);
4339
+ if (modules || styleBlock.module) {
4340
+ const moduleName = typeof styleBlock.module === "string" ? styleBlock.module : "$style";
4341
+ const moduleResult = transformCssModules(code, id);
4342
+ return {
4343
+ code: moduleResult.code,
4344
+ modules: { [moduleName]: moduleResult.classes }
4345
+ };
4346
4346
  }
4347
- return Math.abs(hash).toString(36) + str.length.toString(36);
4347
+ return { code };
4348
4348
  }
4349
4349
  //#endregion
4350
4350
  //#region src/plugins/vue/compiler/template/classStyleRuntime.ts
@@ -4612,6 +4612,7 @@ const DEFAULT_HTML_TO_WXML_TAG_MAP = {
4612
4612
  aside: "view",
4613
4613
  b: "text",
4614
4614
  blockquote: "view",
4615
+ br: "view",
4615
4616
  button: "button",
4616
4617
  code: "text",
4617
4618
  dd: "view",
@@ -4630,6 +4631,7 @@ const DEFAULT_HTML_TO_WXML_TAG_MAP = {
4630
4631
  h5: "view",
4631
4632
  h6: "view",
4632
4633
  header: "view",
4634
+ hr: "view",
4633
4635
  i: "text",
4634
4636
  img: "image",
4635
4637
  input: "input",
@@ -4662,6 +4664,14 @@ function resolveTemplateTagName(tag, context) {
4662
4664
  if (tag !== lowerTag) return tag;
4663
4665
  return context.htmlTagToWxmlMap?.[lowerTag] ?? tag;
4664
4666
  }
4667
+ function resolveMappedHtmlTagClassName(tag, context, resolvedTag) {
4668
+ if (!context.htmlTagToWxmlTagClass || !tag) return;
4669
+ const lowerTag = tag.toLowerCase();
4670
+ if (tag !== lowerTag) return;
4671
+ const mappedTag = context.htmlTagToWxmlMap?.[lowerTag];
4672
+ if (!mappedTag || (resolvedTag ?? mappedTag ?? tag) === lowerTag) return;
4673
+ return lowerTag;
4674
+ }
4665
4675
  //#endregion
4666
4676
  //#region src/plugins/vue/compiler/template/elements/forExpression.ts
4667
4677
  const IDENTIFIER_RE$4 = /^[A-Z_$][\w$]*$/i;
@@ -5973,11 +5983,17 @@ const builtinTagSet = new Set(components.map((tag) => tag.toLowerCase()));
5973
5983
  function isBuiltinTag(tag) {
5974
5984
  return builtinTagSet.has(tag.toLowerCase());
5975
5985
  }
5986
+ function prependStaticClass(staticClass, className) {
5987
+ const tokens = staticClass?.split(/\s+/).filter(Boolean) ?? [];
5988
+ if (!tokens.includes(className)) tokens.unshift(className);
5989
+ return tokens.join(" ");
5990
+ }
5976
5991
  function collectElementAttributes(node, context, options) {
5977
5992
  const { props } = node;
5978
5993
  const resolvedTag = options?.resolvedTag ?? resolveTemplateTagName(node.tag, context);
5979
5994
  const isComponentElement = options?.isComponent ?? !isBuiltinTag(resolvedTag);
5980
5995
  const attrs = options?.extraAttrs ? [...options.extraAttrs] : [];
5996
+ const mappedTagClass = resolveMappedHtmlTagClassName(node.tag, context, resolvedTag);
5981
5997
  let staticClass;
5982
5998
  let staticId;
5983
5999
  let dynamicClassExp;
@@ -6057,6 +6073,7 @@ function collectElementAttributes(node, context, options) {
6057
6073
  if (dir) attrs.push(dir);
6058
6074
  }
6059
6075
  }
6076
+ if (mappedTagClass) staticClass = prependStaticClass(staticClass, mappedTagClass);
6060
6077
  if (templateRef) {
6061
6078
  const className = `__wv-ref-${context.templateRefIndexSeed++}`;
6062
6079
  staticClass = staticClass ? `${staticClass} ${className}` : className;
@@ -6742,6 +6759,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6742
6759
  warnings,
6743
6760
  platform: options?.platform ?? wechatPlatform,
6744
6761
  htmlTagToWxmlMap,
6762
+ htmlTagToWxmlTagClass: options?.htmlTagToWxmlTagClass ?? true,
6745
6763
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
6746
6764
  scopedSlotsRequireProps,
6747
6765
  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.15.4",
4
+ "version": "6.15.6",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -51,8 +51,8 @@
51
51
  "vue": "^3.5.32",
52
52
  "@weapp-core/constants": "^0.1.1",
53
53
  "@weapp-core/shared": "3.0.3",
54
- "@weapp-vite/ast": "6.15.4",
55
- "rolldown-require": "2.0.13"
54
+ "rolldown-require": "2.0.13",
55
+ "@weapp-vite/ast": "6.15.6"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public",