Skip to content

Commit 09bb3e9

Browse files
committed
fix(compiler-ssr): fix invalid codegen when v-slot name is explicit empty attr (#3326)
squashed from fix by @tjk
1 parent d9de6ca commit 09bb3e9

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

packages/compiler-core/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export { processIf } from './transforms/vIf'
4343
export { processFor, createForLoopParams } from './transforms/vFor'
4444
export {
4545
transformExpression,
46-
processExpression
46+
processExpression,
47+
stringifyExpression
4748
} from './transforms/transformExpression'
4849
export {
4950
buildSlots,

packages/compiler-core/src/transforms/transformExpression.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ function canPrefix(id: Identifier) {
361361
return true
362362
}
363363

364-
function stringifyExpression(exp: ExpressionNode | string): string {
364+
export function stringifyExpression(exp: ExpressionNode | string): string {
365365
if (isString(exp)) {
366366
return exp
367367
} else if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {

packages/compiler-ssr/__tests__/ssrComponent.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ describe('ssr: components', () => {
104104
`)
105105
})
106106

107+
test('empty attribute should not produce syntax error', () => {
108+
// previously this would produce syntax error `default: _withCtx((, _push, ...)`
109+
expect(compile(`<foo v-slot="">foo</foo>`).code).not.toMatch(`(,`)
110+
})
111+
107112
test('named slots', () => {
108113
expect(
109114
compile(`<foo>

packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import {
3636
CallExpression,
3737
JSChildNode,
3838
RESOLVE_DYNAMIC_COMPONENT,
39-
TRANSITION
39+
TRANSITION,
40+
stringifyExpression
4041
} from '@vue/compiler-dom'
4142
import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
4243
import {
@@ -145,8 +146,9 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
145146
wipMap.set(node, wipEntries)
146147

147148
const buildSSRSlotFn: SlotFnBuilder = (props, children, loc) => {
149+
const param0 = (props && stringifyExpression(props)) || `_`
148150
const fn = createFunctionExpression(
149-
[props || `_`, `_push`, `_parent`, `_scopeId`],
151+
[param0, `_push`, `_parent`, `_scopeId`],
150152
undefined, // no return, assign body later
151153
true, // newline
152154
true, // isSlot

0 commit comments

Comments
 (0)