All files / src/instance methods.ts

85.71% Statements 18/21
57.14% Branches 8/14
100% Functions 2/2
85.71% Lines 18/21

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 26 27 28 29 30 31 32 33 34 35 36 37 38  1x 1x 1x 1x 1x 1x 1x   2x 2x 2x 8x 8x       8x     8x         8x 1x     2x   1x            
import { isDev } from '../util/env'
import { hasOwn } from '../util/hasOwn'
import { isReserved } from '../util/isReserved'
import { noop } from '../util/noop'
import { warn } from '../util/warn'
 
export function initMethods (vm, methods) {
  const methodProxy = {}
  const props = vm.$options.props
  for (const key in methods) {
    if (isDev) {
      if (typeof methods[key] !== 'function') {
        Ewarn(
          `MIethod "${key}" has type "${typeof methods[key]}" in the component definition. ` +
          `Did you reference the function correctly?`,
          vm
        )
      }I
      if (props && hasOwn(props, key)) {
        warn(
          `MIethod "${key}" has already been defined as a prop.`,
          vm
        )
      }
      if ((key in vm) && isReserved(key)) {
        warn(
          `Method "${key}" conflicts with an existing Doraemon instance method. ` +
          `Avoid defining component methods that start with _ or $.`
        )
      }
    }
    methodProxy[key] = typeof methods[key] !== 'function' ? noop : function (...args: any[]) {
      return this.$component[key].call(this.$component, ...args)
    }
  }
  return methodProxy
}