@wevu/compiler 6.15.13 → 6.15.14

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
@@ -276,6 +276,7 @@ interface TemplateCompileOptions {
276
276
  htmlTagToWxmlTagClass?: boolean;
277
277
  scopedSlotsCompiler?: ScopedSlotsCompilerMode;
278
278
  scopedSlotsRequireProps?: boolean;
279
+ slotSingleRootNoWrapper?: boolean;
279
280
  slotMultipleInstance?: boolean;
280
281
  classStyleRuntime?: ClassStyleRuntime | 'auto';
281
282
  objectLiteralBindMode?: ObjectLiteralBindMode;
package/dist/index.mjs CHANGED
@@ -6366,11 +6366,31 @@ function createScopedSlotComponent(context, slotKey, props, children, transformN
6366
6366
  slotKey
6367
6367
  };
6368
6368
  }
6369
+ function injectAttributeIntoOpeningTag(source, attr) {
6370
+ if (!source.startsWith("<") || source.startsWith("</") || source.startsWith("<!--")) return null;
6371
+ let tagNameEnd = 1;
6372
+ while (tagNameEnd < source.length) {
6373
+ const char = source[tagNameEnd];
6374
+ if (char === " " || char === "\n" || char === "\r" || char === " " || char === "/" || char === ">") break;
6375
+ tagNameEnd += 1;
6376
+ }
6377
+ if (tagNameEnd <= 1) return null;
6378
+ return `${source.slice(0, tagNameEnd)} ${attr}${source.slice(tagNameEnd)}`;
6379
+ }
6369
6380
  function renderSlotFallback(decl, context, transformNode) {
6370
- const content = decl.children.map((child) => transformNode(child, context)).join("");
6371
- if (!content) return "";
6381
+ const rawRenderedChildren = decl.children.map((child) => ({ code: transformNode(child, context) }));
6382
+ const rawContent = rawRenderedChildren.map((item) => item.code).join("");
6383
+ if (!rawContent) return "";
6372
6384
  const slotAttr = renderSlotNameAttribute(decl.name, context, "slot");
6373
- if (!slotAttr) return content;
6385
+ if (!slotAttr) return rawContent;
6386
+ if (!context.slotSingleRootNoWrapper) return `<view ${slotAttr}>${rawContent}</view>`;
6387
+ const renderedChildren = rawRenderedChildren.filter((item) => item.code.trim().length > 0);
6388
+ if (!renderedChildren.length) return "";
6389
+ const content = renderedChildren.map((item) => item.code).join("");
6390
+ if (renderedChildren.length === 1) {
6391
+ const projected = injectAttributeIntoOpeningTag(renderedChildren[0].code, slotAttr);
6392
+ if (projected) return projected;
6393
+ }
6374
6394
  return `<view ${slotAttr}>${content}</view>`;
6375
6395
  }
6376
6396
  function transformSlotElement(node, context, transformNode) {
@@ -6812,6 +6832,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6812
6832
  const resolvedRuntime = runtimeMode === "auto" ? options?.wxsExtension ? "wxs" : "js" : runtimeMode === "wxs" && !options?.wxsExtension ? "js" : runtimeMode;
6813
6833
  const wxsExtension = options?.wxsExtension;
6814
6834
  const scopedSlotsRequireProps = options?.scopedSlotsRequireProps ?? options?.scopedSlotsCompiler !== "augmented";
6835
+ const slotSingleRootNoWrapper = options?.slotSingleRootNoWrapper ?? false;
6815
6836
  const htmlTagToWxmlMap = resolveHtmlTagToWxmlMap(options?.htmlTagToWxml);
6816
6837
  try {
6817
6838
  const ast = parse$1(template, {
@@ -6829,6 +6850,7 @@ function compileVueTemplateToWxml(template, filename, options) {
6829
6850
  htmlTagToWxmlTagClass: options?.htmlTagToWxmlTagClass ?? true,
6830
6851
  scopedSlotsCompiler: options?.scopedSlotsCompiler ?? "auto",
6831
6852
  scopedSlotsRequireProps,
6853
+ slotSingleRootNoWrapper,
6832
6854
  slotMultipleInstance: options?.slotMultipleInstance ?? true,
6833
6855
  scopedSlotComponents: [],
6834
6856
  componentGenerics: {},
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.15.13",
4
+ "version": "6.15.14",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -42,18 +42,18 @@
42
42
  ],
43
43
  "dependencies": {
44
44
  "@jridgewell/remapping": "^2.3.5",
45
- "@vue/compiler-core": "^3.5.32",
46
- "@vue/compiler-dom": "^3.5.32",
45
+ "@vue/compiler-core": "^3.5.33",
46
+ "@vue/compiler-dom": "^3.5.33",
47
47
  "comment-json": "^5.0.0",
48
48
  "lru-cache": "^11.3.5",
49
49
  "magic-string": "^0.30.21",
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
- "vue": "^3.5.32",
53
- "@weapp-core/constants": "^0.1.1",
52
+ "vue": "^3.5.33",
53
+ "@weapp-core/constants": "^0.1.2",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.15.13",
56
- "rolldown-require": "2.0.14"
55
+ "@weapp-vite/ast": "6.15.14",
56
+ "rolldown-require": "2.0.15"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public",