]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-ssr): fix invalid codegen when v-slot name is explicit empty attr (...
authorEvan You <yyx990803@gmail.com>
Wed, 26 Oct 2022 08:18:19 +0000 (16:18 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 26 Oct 2022 08:18:19 +0000 (16:18 +0800)
squashed from fix by @tjk

packages/compiler-core/src/index.ts
packages/compiler-core/src/transforms/transformExpression.ts
packages/compiler-ssr/__tests__/ssrComponent.spec.ts
packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

index 6ed7aa5b8974fbcf824abcd37f5e1d83385077fd..6a1f8b63b579a2c8d706aab1ecdd0aa0e39797e2 100644 (file)
@@ -43,7 +43,8 @@ export { processIf } from './transforms/vIf'
 export { processFor, createForLoopParams } from './transforms/vFor'
 export {
   transformExpression,
-  processExpression
+  processExpression,
+  stringifyExpression
 } from './transforms/transformExpression'
 export {
   buildSlots,
index e4311ad4f880f3a6aa6a15da1b1678a071a212a6..43c69559688b4f0a489c1f4cb62c76e48d9123de 100644 (file)
@@ -361,7 +361,7 @@ function canPrefix(id: Identifier) {
   return true
 }
 
-function stringifyExpression(exp: ExpressionNode | string): string {
+export function stringifyExpression(exp: ExpressionNode | string): string {
   if (isString(exp)) {
     return exp
   } else if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
index 5d5191ffb4494108acb8c55d92c0704b6b87dfc4..cd21e48cb9a3e471a1354ad681c7f92713e6eeb0 100644 (file)
@@ -104,6 +104,11 @@ describe('ssr: components', () => {
       `)
     })
 
+    test('empty attribute should not produce syntax error', () => {
+      // previously this would produce syntax error `default: _withCtx((, _push, ...)`
+      expect(compile(`<foo v-slot="">foo</foo>`).code).not.toMatch(`(,`)
+    })
+
     test('named slots', () => {
       expect(
         compile(`<foo>
index df190c768a8b938b5542b10e86d8890c88b68c85..dc8c6a4ae4f65ee8bad24f67dd84a636eb6737ad 100644 (file)
@@ -36,7 +36,8 @@ import {
   CallExpression,
   JSChildNode,
   RESOLVE_DYNAMIC_COMPONENT,
-  TRANSITION
+  TRANSITION,
+  stringifyExpression
 } from '@vue/compiler-dom'
 import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
 import {
@@ -145,8 +146,9 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
     wipMap.set(node, wipEntries)
 
     const buildSSRSlotFn: SlotFnBuilder = (props, children, loc) => {
+      const param0 = (props && stringifyExpression(props)) || `_`
       const fn = createFunctionExpression(
-        [props || `_`, `_push`, `_parent`, `_scopeId`],
+        [param0, `_push`, `_parent`, `_scopeId`],
         undefined, // no return, assign body later
         true, // newline
         true, // isSlot