@vue/compiler-ssr 3.6.0-rc.13 → 3.6.0-rc.15

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.15
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -57,21 +57,49 @@ 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) {
73
- const { children } = branch;
74
- return processChildrenAsStatement(branch, context, !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && !(children.length === 1 && children[0].type === 11));
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
+ }
82
+ return processChildrenAsStatement(branch, context, !disableNestedFragments && !isBareBranch(branch));
83
+ }
84
+ /** Whether a branch renders as it is: its sole element or v-for, unwrapped. */
85
+ function isBareBranch({ children }) {
86
+ return children.length === 1 && (children[0].type === 1 || children[0].type === 11);
87
+ }
88
+ /**
89
+ * Whether two branches of a chain could start with the same node. Branches
90
+ * that each render one plain element, all of different tags, are told apart
91
+ * by the tag.
92
+ */
93
+ function hasLookalikeBranches(branches) {
94
+ if (branches.length < 2) return false;
95
+ const tags = /* @__PURE__ */ new Set();
96
+ for (const { children } of branches) {
97
+ const nodes = children.filter((child) => child.type !== 3);
98
+ const root = nodes.length === 1 ? nodes[0] : void 0;
99
+ if (!root || root.type !== 1 || root.tagType !== 0 || tags.has(root.tag)) return true;
100
+ tags.add(root.tag);
101
+ }
102
+ return false;
75
103
  }
76
104
  //#endregion
77
105
  //#region packages/compiler-ssr/src/transforms/ssrVFor.ts
@@ -156,6 +184,9 @@ function ssrProcessSuspense(node, context) {
156
184
  //#endregion
157
185
  //#region packages/compiler-ssr/src/transforms/ssrTransformElement.ts
158
186
  const rawChildrenMap = /* @__PURE__ */ new WeakMap();
187
+ const ssrTransformStyle = (node, context) => {
188
+ if (node.type === 1 && node.tagType !== 0) (0, _vue_compiler_dom.transformStyle)(node, context);
189
+ };
159
190
  const ssrTransformElement = (node, context) => {
160
191
  if (node.type !== 1 || node.tagType !== 0) return;
161
192
  return function ssrPostTransformElement() {
@@ -171,6 +202,7 @@ const ssrTransformElement = (node, context) => {
171
202
  }
172
203
  const needMergeProps = hasDynamicVBind || hasCustomDir;
173
204
  if (needMergeProps) {
205
+ (0, _vue_compiler_dom.transformStyle)(node, context);
174
206
  const { props, directives } = (0, _vue_compiler_dom.buildProps)(node, context, node.props, false, false, true);
175
207
  if (props || directives.length) {
176
208
  const mergedProps = buildSSRProps(props, directives, context);
@@ -203,6 +235,8 @@ const ssrTransformElement = (node, context) => {
203
235
  let dynamicClassBinding = void 0;
204
236
  let staticClassBinding = void 0;
205
237
  let dynamicStyleBinding = void 0;
238
+ let staticStyleBinding = void 0;
239
+ let staticStyleIndex = -1;
206
240
  for (let i = 0; i < node.props.length; i++) {
207
241
  const prop = node.props[i];
208
242
  if (node.tag === "input" && isTrueFalseValue(prop)) continue;
@@ -229,7 +263,16 @@ const ssrTransformElement = (node, context) => {
229
263
  if (attrName === "class") openTag.push(` class="`, dynamicClassBinding = (0, _vue_compiler_dom.createCallExpression)(context.helper(SSR_RENDER_CLASS), [value]), `"`);
230
264
  else if (attrName === "style") {
231
265
  if (dynamicStyleBinding) mergeCall(dynamicStyleBinding, value);
232
- else openTag.push(` style="`, dynamicStyleBinding = (0, _vue_compiler_dom.createCallExpression)(context.helper(SSR_RENDER_STYLE), [value]), `"`);
266
+ else {
267
+ dynamicStyleBinding = (0, _vue_compiler_dom.createCallExpression)(context.helper(SSR_RENDER_STYLE), [staticStyleBinding ? (0, _vue_compiler_dom.createArrayExpression)([staticStyleBinding, value]) : value]);
268
+ const parts = [
269
+ ` style="`,
270
+ dynamicStyleBinding,
271
+ `"`
272
+ ];
273
+ if (staticStyleBinding) openTag.splice(staticStyleIndex, 1, ...parts);
274
+ else openTag.push(...parts);
275
+ }
233
276
  } else {
234
277
  attrName = node.tag.indexOf("-") > 0 ? attrName : _vue_shared.propsToAttrMap[attrName] || attrName.toLowerCase();
235
278
  if ((0, _vue_shared.isBooleanAttr)(attrName)) openTag.push((0, _vue_compiler_dom.createConditionalExpression)((0, _vue_compiler_dom.createCallExpression)(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [value]), (0, _vue_compiler_dom.createSimpleExpression)(" " + attrName, true), (0, _vue_compiler_dom.createSimpleExpression)("", true), false));
@@ -251,6 +294,16 @@ const ssrTransformElement = (node, context) => {
251
294
  else if (!needMergeProps) {
252
295
  if (name === "key" || name === "ref") continue;
253
296
  if (name === "class" && prop.value) staticClassBinding = JSON.stringify(prop.value.content);
297
+ if (name === "style" && prop.value) {
298
+ const style = (0, _vue_shared.parseStringStyle)(prop.value.content);
299
+ if (dynamicStyleBinding) mergeCall(dynamicStyleBinding, JSON.stringify(style));
300
+ else {
301
+ staticStyleBinding = JSON.stringify(style);
302
+ staticStyleIndex = openTag.length;
303
+ openTag.push(` style="${(0, _vue_shared.escapeHtml)((0, _vue_shared.stringifyStyle)(style))}"`);
304
+ }
305
+ continue;
306
+ }
254
307
  openTag.push(` ${prop.name}` + (prop.value ? `="${(0, _vue_shared.escapeHtml)(prop.value.content)}"` : ``));
255
308
  }
256
309
  }
@@ -456,6 +509,16 @@ const ssrTransformComponent = (node, context) => {
456
509
  ]);
457
510
  };
458
511
  };
512
+ /**
513
+ * Whether the server render of `node` begins with markup of its own: a
514
+ * Teleport opens with its markers, a TransitionGroup with its tag or range,
515
+ * a Suspense in a vapor component with its slot's range, an appearing
516
+ * Transition with its `<template>`.
517
+ */
518
+ function beginsWithOwnMarkup(node) {
519
+ const component = componentTypeMap.get(node);
520
+ return component === _vue_compiler_dom.TELEPORT || component === _vue_compiler_dom.TRANSITION_GROUP || component === _vue_compiler_dom.SUSPENSE || component === _vue_compiler_dom.TRANSITION && !!(0, _vue_compiler_dom.findProp)(node, "appear", false, true);
521
+ }
459
522
  function ssrProcessComponent(node, context, parent) {
460
523
  const component = componentTypeMap.get(node);
461
524
  if (!node.ssrCodegenNode) {
@@ -607,7 +670,11 @@ function ssrCodegenTransform(ast, options) {
607
670
  ast.helpers.add(helper);
608
671
  });
609
672
  }
610
- processChildren(ast, context, ast.children.length > 1 && ast.children.some((c) => !(0, _vue_compiler_dom.isText)(c)));
673
+ const isFragment = ast.children.length > 1 && ast.children.some((c) => !(0, _vue_compiler_dom.isText)(c));
674
+ const vaporRange = !!options.vapor && (isFragment || opensRange(ast.children[0]));
675
+ if (vaporRange) context.pushStringPart(`<!--{-->`);
676
+ processChildren(ast, context, isFragment && !options.vapor);
677
+ if (vaporRange) context.pushStringPart(`<!--}-->`);
611
678
  ast.codegenNode = (0, _vue_compiler_dom.createBlockStatement)(context.body);
612
679
  ast.ssrHelpers = Array.from(/* @__PURE__ */ new Set([...Array.from(ast.helpers).filter((h) => h in ssrHelpers), ...context.helpers]));
613
680
  ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
@@ -646,6 +713,16 @@ function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new
646
713
  }
647
714
  };
648
715
  }
716
+ /** Whether the server render of `node` may begin with a component's range. */
717
+ function opensRange(node) {
718
+ if (!node) return false;
719
+ if (node.type === 1) return node.tagType === 1 && !beginsWithOwnMarkup(node);
720
+ if (node.type === 9) {
721
+ const [branch] = node.branches;
722
+ return node.branches.length === 1 && isBareBranch(branch) && opensRange(branch.children[0]);
723
+ }
724
+ return false;
725
+ }
649
726
  function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
650
727
  return createSSRTransformContext(parent.root, parent.options, parent.helpers, withSlotScopeId);
651
728
  }
@@ -858,7 +935,7 @@ function compile(source, options = {}) {
858
935
  ssrTransformElement,
859
936
  ssrTransformComponent,
860
937
  _vue_compiler_dom.trackSlotScopes,
861
- _vue_compiler_dom.transformStyle,
938
+ ssrTransformStyle,
862
939
  ...options.nodeTransforms || []
863
940
  ],
864
941
  directiveTransforms: {
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.15",
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.15",
32
+ "@vue/compiler-dom": "3.6.0-rc.15"
33
33
  }
34
34
  }