All files / runtime-core/src/helpers toHandlers.ts

100% Statements 20/20
100% Branches 8/8
100% Functions 1/1
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 262x 2x           2x 5x 5x 5x 5x 5x 2x 2x 2x 5x 7x 7x 3x 4x 7x 7x 3x 3x  
import { isObject, toHandlerKey } from '@vue/shared'
import { warn } from '../warning'
 
/**
 * For prefixing keys in v-on="obj" with "on"
 * @private
 */
export function toHandlers(
  obj: Record<string, any>,
  preserveCaseIfNecessary?: boolean,
): Record<string, any> {
  const ret: Record<string, any> = {}
  if (__DEV__ && !isObject(obj)) {
    warn(`v-on with no argument expects an object value.`)
    return ret
  }
  for (const key in obj) {
    ret[
      preserveCaseIfNecessary && /[A-Z]/.test(key)
        ? `on:${key}`
        : toHandlerKey(key)
    ] = obj[key]
  }
  return ret
}