fix(compiler-ssr): fix invalid codegen when v-slot name is explicit empty attr (#3326)

squashed from fix by @tjk
This commit is contained in:
Evan You 2022-10-26 16:18:19 +08:00
parent d9de6caecd
commit 09bb3e996e
4 changed files with 12 additions and 4 deletions

View File

@ -43,7 +43,8 @@ export { processIf } from './transforms/vIf'
export { processFor, createForLoopParams } from './transforms/vFor' export { processFor, createForLoopParams } from './transforms/vFor'
export { export {
transformExpression, transformExpression,
processExpression processExpression,
stringifyExpression
} from './transforms/transformExpression' } from './transforms/transformExpression'
export { export {
buildSlots, buildSlots,

View File

@ -361,7 +361,7 @@ function canPrefix(id: Identifier) {
return true return true
} }
function stringifyExpression(exp: ExpressionNode | string): string { export function stringifyExpression(exp: ExpressionNode | string): string {
if (isString(exp)) { if (isString(exp)) {
return exp return exp
} else if (exp.type === NodeTypes.SIMPLE_EXPRESSION) { } else if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {

View 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', () => { test('named slots', () => {
expect( expect(
compile(`<foo> compile(`<foo>

View File

@ -36,7 +36,8 @@ import {
CallExpression, CallExpression,
JSChildNode, JSChildNode,
RESOLVE_DYNAMIC_COMPONENT, RESOLVE_DYNAMIC_COMPONENT,
TRANSITION TRANSITION,
stringifyExpression
} from '@vue/compiler-dom' } from '@vue/compiler-dom'
import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers' import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers'
import { import {
@ -145,8 +146,9 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
wipMap.set(node, wipEntries) wipMap.set(node, wipEntries)
const buildSSRSlotFn: SlotFnBuilder = (props, children, loc) => { const buildSSRSlotFn: SlotFnBuilder = (props, children, loc) => {
const param0 = (props && stringifyExpression(props)) || `_`
const fn = createFunctionExpression( const fn = createFunctionExpression(
[props || `_`, `_push`, `_parent`, `_scopeId`], [param0, `_push`, `_parent`, `_scopeId`],
undefined, // no return, assign body later undefined, // no return, assign body later
true, // newline true, // newline
true, // isSlot true, // isSlot