2019-09-23 10:19:42 +08:00
|
|
|
import { DirectiveTransform } from '../transform'
|
|
|
|
import { createObjectProperty, createExpression } from '../ast'
|
|
|
|
import { capitalize } from '@vue/shared'
|
|
|
|
|
|
|
|
// 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.
|
2019-09-25 10:03:28 +08:00
|
|
|
export const transformOn: DirectiveTransform = ({ arg, exp, loc }) => {
|
|
|
|
const eventName = arg!.isStatic
|
|
|
|
? createExpression(`on${capitalize(arg!.content)}`, true, arg!.loc)
|
|
|
|
: createExpression(`'on' + (${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,
|
2019-09-25 10:03:28 +08:00
|
|
|
exp || createExpression(`() => {}`, false, loc),
|
|
|
|
loc
|
2019-09-23 10:19:42 +08:00
|
|
|
),
|
|
|
|
needRuntime: false
|
|
|
|
}
|
|
|
|
}
|