2019-09-23 10:19:42 +08:00
|
|
|
import { DirectiveTransform } from '../transform'
|
|
|
|
import { createObjectProperty, createExpression } from '../ast'
|
|
|
|
import { capitalize } from '@vue/shared'
|
2019-09-23 11:07:36 +08:00
|
|
|
import { CAPITALIZE } from '../runtimeConstants'
|
2019-09-23 10:19:42 +08:00
|
|
|
|
|
|
|
// v-on without arg is handled directly in ./element.ts due to it affecting
|
|
|
|
// codegen for the entire props object. This transform here is only for v-on
|
|
|
|
// *with* args.
|
|
|
|
export const transformOn: DirectiveTransform = (dir, context) => {
|
|
|
|
const arg = dir.arg!
|
|
|
|
const eventName = arg.isStatic
|
|
|
|
? createExpression(`on${capitalize(arg.content)}`, true, arg.loc)
|
2019-09-23 11:07:36 +08:00
|
|
|
: createExpression(`'on' + ${CAPITALIZE}(${arg.content})`, false, arg.loc)
|
2019-09-23 10:19:42 +08:00
|
|
|
// TODO .once modifier handling since it is platform agnostic
|
|
|
|
// other modifiers are handled in compiler-dom
|
|
|
|
return {
|
|
|
|
props: createObjectProperty(
|
|
|
|
eventName,
|
|
|
|
dir.exp || createExpression(`() => {}`, false, dir.loc),
|
|
|
|
dir.loc
|
|
|
|
),
|
|
|
|
needRuntime: false
|
|
|
|
}
|
|
|
|
}
|