@vue/compiler-ssr 3.6.0-rc.13 → 3.6.0-rc.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-ssr v3.6.0-rc.13
2
+ * @vue/compiler-ssr v3.6.0-rc.14
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -57,22 +57,47 @@ const ssrHelpers = {
57
57
  //#region packages/compiler-ssr/src/transforms/ssrVIf.ts
58
58
  const ssrTransformIf = (0, _vue_compiler_dom.createStructuralDirectiveTransform)(/^(?:if|else|else-if)$/, _vue_compiler_dom.processIf);
59
59
  function ssrProcessIf(node, context, disableNestedFragments = false, disableComment = false) {
60
- const [rootBranch] = node.branches;
61
- const ifStatement = (0, _vue_compiler_dom.createIfStatement)(rootBranch.condition, processIfBranch(rootBranch, context, disableNestedFragments));
60
+ const { branches } = node;
61
+ const ranged = !!context.options.vapor && hasLookalikeBranches(branches);
62
+ const [rootBranch] = branches;
63
+ const ifStatement = (0, _vue_compiler_dom.createIfStatement)(rootBranch.condition, processIfBranch(rootBranch, context, disableNestedFragments, ranged && 0));
62
64
  context.pushStatement(ifStatement);
63
65
  let currentIf = ifStatement;
64
- for (let i = 1; i < node.branches.length; i++) {
65
- const branch = node.branches[i];
66
- const branchBlockStatement = processIfBranch(branch, context, disableNestedFragments);
66
+ for (let i = 1; i < branches.length; i++) {
67
+ const branch = branches[i];
68
+ const branchBlockStatement = processIfBranch(branch, context, disableNestedFragments, ranged && i);
67
69
  if (branch.condition) currentIf = currentIf.alternate = (0, _vue_compiler_dom.createIfStatement)(branch.condition, branchBlockStatement);
68
70
  else currentIf.alternate = branchBlockStatement;
69
71
  }
70
72
  if (!currentIf.alternate && (!disableComment || context.options.vapor)) currentIf.alternate = (0, _vue_compiler_dom.createBlockStatement)([(0, _vue_compiler_dom.createCallExpression)(`_push`, ["`<!---->`"])]);
71
73
  }
72
- function processIfBranch(branch, context, disableNestedFragments = false) {
74
+ function processIfBranch(branch, context, disableNestedFragments = false, index = false) {
75
+ if (index !== false) {
76
+ const childContext = createChildContext(context);
77
+ childContext.pushStringPart(`<!--[${index}-->`);
78
+ processChildren(branch, childContext);
79
+ childContext.pushStringPart(`<!--]-->`);
80
+ return (0, _vue_compiler_dom.createBlockStatement)(childContext.body);
81
+ }
73
82
  const { children } = branch;
74
83
  return processChildrenAsStatement(branch, context, !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && !(children.length === 1 && children[0].type === 11));
75
84
  }
85
+ /**
86
+ * Whether two branches of a chain could start with the same node. Branches
87
+ * that each render one plain element, all of different tags, are told apart
88
+ * by the tag.
89
+ */
90
+ function hasLookalikeBranches(branches) {
91
+ if (branches.length < 2) return false;
92
+ const tags = /* @__PURE__ */ new Set();
93
+ for (const { children } of branches) {
94
+ const nodes = children.filter((child) => child.type !== 3);
95
+ const root = nodes.length === 1 ? nodes[0] : void 0;
96
+ if (!root || root.type !== 1 || root.tagType !== 0 || tags.has(root.tag)) return true;
97
+ tags.add(root.tag);
98
+ }
99
+ return false;
100
+ }
76
101
  //#endregion
77
102
  //#region packages/compiler-ssr/src/transforms/ssrVFor.ts
78
103
  const ssrTransformFor = (0, _vue_compiler_dom.createStructuralDirectiveTransform)("for", _vue_compiler_dom.processFor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-ssr",
3
- "version": "3.6.0-rc.13",
3
+ "version": "3.6.0-rc.14",
4
4
  "description": "@vue/compiler-ssr",
5
5
  "main": "dist/compiler-ssr.cjs.js",
6
6
  "types": "dist/compiler-ssr.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme",
30
30
  "dependencies": {
31
- "@vue/shared": "3.6.0-rc.13",
32
- "@vue/compiler-dom": "3.6.0-rc.13"
31
+ "@vue/shared": "3.6.0-rc.14",
32
+ "@vue/compiler-dom": "3.6.0-rc.14"
33
33
  }
34
34
  }