( dir, node, context, augmentor, )
| 27 | } |
| 28 | |
| 29 | export const transformOn: DirectiveTransform = ( |
| 30 | dir, |
| 31 | node, |
| 32 | context, |
| 33 | augmentor, |
| 34 | ) => { |
| 35 | const { loc, modifiers, arg } = dir as VOnDirectiveNode |
| 36 | if (!dir.exp && !modifiers.length) { |
| 37 | context.onError(createCompilerError(ErrorCodes.X_V_ON_NO_EXPRESSION, loc)) |
| 38 | } |
| 39 | let eventName: ExpressionNode |
| 40 | if (arg.type === NodeTypes.SIMPLE_EXPRESSION) { |
| 41 | if (arg.isStatic) { |
| 42 | let rawName = arg.content |
| 43 | if (__DEV__ && rawName.startsWith('vnode')) { |
| 44 | context.onError(createCompilerError(ErrorCodes.X_VNODE_HOOKS, arg.loc)) |
| 45 | } |
| 46 | if (rawName.startsWith('vue:')) { |
| 47 | rawName = `vnode-${rawName.slice(4)}` |
| 48 | } |
| 49 | const eventString = |
| 50 | node.tagType !== ElementTypes.ELEMENT || |
| 51 | rawName.startsWith('vnode') || |
| 52 | !/[A-Z]/.test(rawName) |
| 53 | ? // for non-element and vnode lifecycle event listeners, auto convert |
| 54 | // it to camelCase. See issue #2249 |
| 55 | toHandlerKey(camelize(rawName)) |
| 56 | : // preserve case for plain element listeners that have uppercase |
| 57 | // letters, as these may be custom elements' custom events |
| 58 | `on:${rawName}` |
| 59 | eventName = createSimpleExpression(eventString, true, arg.loc) |
| 60 | } else { |
| 61 | // #2388 |
| 62 | eventName = createCompoundExpression([ |
| 63 | `${context.helperString(TO_HANDLER_KEY)}(`, |
| 64 | arg, |
| 65 | `)`, |
| 66 | ]) |
| 67 | } |
| 68 | } else { |
| 69 | // already a compound expression. |
| 70 | eventName = arg |
| 71 | eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`) |
| 72 | eventName.children.push(`)`) |
| 73 | } |
| 74 | |
| 75 | // handler processing |
| 76 | let exp: ExpressionNode | undefined = dir.exp as |
| 77 | | SimpleExpressionNode |
| 78 | | undefined |
| 79 | if (exp && !exp.content.trim()) { |
| 80 | exp = undefined |
| 81 | } |
| 82 | let shouldCache: boolean = context.cacheHandlers && !exp && !context.inVOnce |
| 83 | if (exp) { |
| 84 | const isMemberExp = isMemberExpression(exp, context) |
| 85 | const isInlineStatement = !(isMemberExp || isFnExpression(exp, context)) |
| 86 | const hasMultipleStatements = exp.content.includes(`;`) |
nothing calls this directly
no test coverage detected