Skip to content

Commit

Permalink
fix(compiler-ssr): fix invalid codegen when v-slot name is explicit e…
Browse files Browse the repository at this point in the history
…mpty attr (#3326)

squashed from fix by @tjk
  • Loading branch information
yyx990803 committed Oct 26, 2022
1 parent d9de6ca commit 09bb3e9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/compiler-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions packages/compiler-ssr/__tests__/ssrComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09bb3e9

Please sign in to comment.