File tree 2 files changed +21
-6
lines changed
2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,20 @@ describe('compiler: transform v-on', () => {
300
300
expect ( onError ) . not . toHaveBeenCalled ( )
301
301
} )
302
302
303
+ test ( 'case conversion for vnode hooks' , ( ) => {
304
+ const { node } = parseWithVOn ( `<div v-on:vnode-mounted="onMount"/>` )
305
+ const props = ( node . codegenNode as CallExpression )
306
+ . arguments [ 1 ] as ObjectExpression
307
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
308
+ key : {
309
+ content : `onVnodeMounted`
310
+ } ,
311
+ value : {
312
+ content : `onMount`
313
+ }
314
+ } )
315
+ } )
316
+
303
317
describe ( 'cacheHandler' , ( ) => {
304
318
test ( 'empty handler' , ( ) => {
305
319
const { root, node } = parseWithVOn ( `<div v-on:click.prevent />` , {
Original file line number Diff line number Diff line change 8
8
createCompoundExpression ,
9
9
SimpleExpressionNode
10
10
} from '../ast'
11
- import { capitalize } from '@vue/shared'
11
+ import { capitalize , camelize } from '@vue/shared'
12
12
import { createCompilerError , ErrorCodes } from '../errors'
13
13
import { processExpression } from './transformExpression'
14
14
import { isMemberExpression , hasScopeRef } from '../utils'
@@ -38,11 +38,12 @@ export const transformOn: DirectiveTransform = (
38
38
let eventName : ExpressionNode
39
39
if ( arg . type === NodeTypes . SIMPLE_EXPRESSION ) {
40
40
if ( arg . isStatic ) {
41
- eventName = createSimpleExpression (
42
- `on${ capitalize ( arg . content ) } ` ,
43
- true ,
44
- arg . loc
45
- )
41
+ const rawName = arg . content
42
+ // for @vnode -xxx event listeners, auto convert it to camelCase
43
+ const normalizedName = rawName . startsWith ( `vnode` )
44
+ ? capitalize ( camelize ( rawName ) )
45
+ : capitalize ( rawName )
46
+ eventName = createSimpleExpression ( `on${ normalizedName } ` , true , arg . loc )
46
47
} else {
47
48
eventName = createCompoundExpression ( [ `"on" + (` , arg , `)` ] )
48
49
}
You can’t perform that action at this time.
0 commit comments