vue3-yuanma/packages/compiler-core/src/transforms/vOn.ts
2019-09-24 22:03:28 -04:00

23 lines
846 B
TypeScript

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.
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)
// TODO .once modifier handling since it is platform agnostic
// other modifiers are handled in compiler-dom
return {
props: createObjectProperty(
eventName,
exp || createExpression(`() => {}`, false, loc),
loc
),
needRuntime: false
}
}