]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): transform kebab case props to camelcase on slots (#2490)
authoredison <daiwei521@126.com>
Fri, 27 Nov 2020 14:48:30 +0000 (22:48 +0800)
committerGitHub <noreply@github.com>
Fri, 27 Nov 2020 14:48:30 +0000 (09:48 -0500)
fix #2488

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

index d5e9f757582414849c4b43e0741c5663ec30b9c9..82a5c8e50e1bcd5f865e55cdc8b2b7f982c79a4c 100644 (file)
@@ -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,
@@ -124,6 +126,16 @@ describe('compiler: transform <slot> outlets', () => {
                 content: `qux`,
                 isStatic: false
               }
+            },
+            {
+              key: {
+                content: `fooBar`,
+                isStatic: true
+              },
+              value: {
+                content: `foo-bar`,
+                isStatic: false
+              }
             }
           ]
         }
index 58ef0b2f488ef749d49ab71fb58f8b762c1b981e..f3d5c0c73736852c9bd3382c987be2a0f7439bad 100644 (file)
@@ -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)) {
@@ -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 => {
+      if (
+        prop.type === NodeTypes.DIRECTIVE &&
+        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(