Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-core): transform kebab case props to camelcase on slots (close #2488) #2490

Merged
merged 8 commits into from
Nov 27, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ describe('compiler: transform <slot> outlets', () => {
})

test('default slot outlet with props', () => {
const ast = parseWithSlots(`<slot foo="bar" :baz="qux" />`)
const ast = parseWithSlots(
`<slot foo="bar" :baz="qux" :foo-bar="foo-bar" />`
)
expect((ast.children[0] as ElementNode).codegenNode).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
callee: RENDER_SLOT,
Expand Down Expand Up @@ -124,6 +126,16 @@ describe('compiler: transform <slot> outlets', () => {
content: `qux`,
isStatic: false
}
},
{
key: {
content: `fooBar`,
isStatic: true
},
value: {
content: `foo-bar`,
isStatic: false
}
}
]
}
Expand Down
14 changes: 14 additions & 0 deletions packages/compiler-core/src/transforms/transformSlotOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isSlotOutlet, findProp } from '../utils'
import { buildProps, PropsExpression } from './transformElement'
import { createCompilerError, ErrorCodes } from '../errors'
import { RENDER_SLOT } from '../runtimeHelpers'
import { camelize } from '@vue/shared/'

export const transformSlotOutlet: NodeTransform = (node, context) => {
if (isSlotOutlet(node)) {
Expand Down Expand Up @@ -68,9 +69,22 @@ export function processSlotOutlet(
const propsWithoutName = name
? node.props.filter(p => p !== name)
: node.props

if (propsWithoutName.length > 0) {
//#2488
propsWithoutName.forEach(prop => {
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
if (
prop.type === NodeTypes.DIRECTIVE &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: here only v-bind args should be camelized so we should check prop.name === 'bind'. I also refactored the logic to reduce iterations from 3 to 1, see 7cd85be

prop.arg &&
prop.arg.type === NodeTypes.SIMPLE_EXPRESSION
) {
prop.arg.content = camelize(prop.arg.content)
}
})

const { props, directives } = buildProps(node, context, propsWithoutName)
slotProps = props

if (directives.length) {
context.onError(
createCompilerError(
Expand Down