Skip to content

Commit ef59a30

Browse files
authored
fix(compiler-core): transform kebab case props to camelcase on slots (#2490)
fix #2488
1 parent 735af1c commit ef59a30

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ describe('compiler: transform <slot> outlets', () => {
9595
})
9696

9797
test('default slot outlet with props', () => {
98-
const ast = parseWithSlots(`<slot foo="bar" :baz="qux" />`)
98+
const ast = parseWithSlots(
99+
`<slot foo="bar" :baz="qux" :foo-bar="foo-bar" />`
100+
)
99101
expect((ast.children[0] as ElementNode).codegenNode).toMatchObject({
100102
type: NodeTypes.JS_CALL_EXPRESSION,
101103
callee: RENDER_SLOT,
@@ -124,6 +126,16 @@ describe('compiler: transform <slot> outlets', () => {
124126
content: `qux`,
125127
isStatic: false
126128
}
129+
},
130+
{
131+
key: {
132+
content: `fooBar`,
133+
isStatic: true
134+
},
135+
value: {
136+
content: `foo-bar`,
137+
isStatic: false
138+
}
127139
}
128140
]
129141
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { isSlotOutlet, findProp } from '../utils'
1111
import { buildProps, PropsExpression } from './transformElement'
1212
import { createCompilerError, ErrorCodes } from '../errors'
1313
import { RENDER_SLOT } from '../runtimeHelpers'
14+
import { camelize } from '@vue/shared/'
1415

1516
export const transformSlotOutlet: NodeTransform = (node, context) => {
1617
if (isSlotOutlet(node)) {
@@ -68,9 +69,22 @@ export function processSlotOutlet(
6869
const propsWithoutName = name
6970
? node.props.filter(p => p !== name)
7071
: node.props
72+
7173
if (propsWithoutName.length > 0) {
74+
//#2488
75+
propsWithoutName.forEach(prop => {
76+
if (
77+
prop.type === NodeTypes.DIRECTIVE &&
78+
prop.arg &&
79+
prop.arg.type === NodeTypes.SIMPLE_EXPRESSION
80+
) {
81+
prop.arg.content = camelize(prop.arg.content)
82+
}
83+
})
84+
7285
const { props, directives } = buildProps(node, context, propsWithoutName)
7386
slotProps = props
87+
7488
if (directives.length) {
7589
context.onError(
7690
createCompilerError(

0 commit comments

Comments
 (0)