How to use the @vue/shared.hasOwn function in @vue/shared

To help you get started, we’ve selected a few @vue/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
if (__DEV__ && !isObject(raw)) {
      warn(`invalid props options`, raw)
    }
    for (const key in raw) {
      const normalizedKey = camelize(key)
      if (normalizedKey[0] !== '$') {
        const opt = raw[key]
        const prop: NormalizedProp = (options[normalizedKey] =
          isArray(opt) || isFunction(opt) ? { type: opt } : opt)
        if (prop != null) {
          const booleanIndex = getTypeIndex(Boolean, prop.type)
          const stringIndex = getTypeIndex(String, prop.type)
          prop[BooleanFlags.shouldCast] = booleanIndex > -1
          prop[BooleanFlags.shouldCastTrue] = booleanIndex < stringIndex
          // if the prop needs boolean casting or default value
          if (booleanIndex > -1 || hasOwn(prop, 'default')) {
            needCastKeys.push(normalizedKey)
          }
        }
      } else if (__DEV__) {
        warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
      }
    }
  }
  const normalized: NormalizedPropsOptions = [options, needCastKeys]
  normalizationMap.set(raw, normalized)
  return normalized
}
github vuejs / vue-next / packages / reactivity / src / baseHandlers.ts View on Github external
function deleteProperty(target: object, key: string | symbol): boolean {
  const hadKey = hasOwn(target, key)
  const oldValue = (target as any)[key]
  const result = Reflect.deleteProperty(target, key)
  if (result && hadKey) {
    /* istanbul ignore else */
    if (__DEV__) {
      trigger(target, TriggerOpTypes.DELETE, key, { oldValue })
    } else {
      trigger(target, TriggerOpTypes.DELETE, key)
    }
  }
  return result
}
github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
setProp(key, true)
        }
      }
    }
    // validation
    if (__DEV__ && rawProps) {
      for (const key in options) {
        let opt = options[key]
        if (opt == null) continue
        let rawValue
        if (!(key in rawProps) && hyphenate(key) in rawProps) {
          rawValue = rawProps[hyphenate(key)]
        } else {
          rawValue = rawProps[key]
        }
        validateProp(key, toRaw(rawValue), opt, !hasOwn(props, key))
      }
    }
  } else {
    // if component has no declared props, $attrs === $props
    attrs = props
  }

  // in case of dynamic props, check if we need to delete keys from
  // the props proxy
  const { patchFlag } = instance.vnode
  if (
    propsProxy !== null &&
    (patchFlag === 0 || patchFlag & PatchFlags.FULL_PROPS)
  ) {
    const rawInitialProps = toRaw(propsProxy)
    for (const key in rawInitialProps) {
github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
}
  } else {
    // if component has no declared props, $attrs === $props
    attrs = props
  }

  // in case of dynamic props, check if we need to delete keys from
  // the props proxy
  const { patchFlag } = instance.vnode
  if (
    propsProxy !== null &&
    (patchFlag === 0 || patchFlag & PatchFlags.FULL_PROPS)
  ) {
    const rawInitialProps = toRaw(propsProxy)
    for (const key in rawInitialProps) {
      if (!hasOwn(props, key)) {
        delete propsProxy[key]
      }
    }
  }

  // lock readonly
  lock()

  instance.props = props
  instance.attrs = options ? attrs || EMPTY_OBJ : props
}
github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
// Any non-declared props are put into a separate `attrs` object
        // for spreading. Make sure to preserve original key casing
        ;(attrs || (attrs = {}))[key] = rawProps[key]
      } else {
        setProp(camelKey, rawProps[key])
      }
    }
  }
  if (hasDeclaredProps) {
    // set default values & cast booleans
    for (let i = 0; i < needCastKeys.length; i++) {
      const key = needCastKeys[i]
      let opt = options[key]
      if (opt == null) continue
      const isAbsent = !hasOwn(props, key)
      const hasDefault = hasOwn(opt, 'default')
      const currentValue = props[key]
      // default values
      if (hasDefault && currentValue === undefined) {
        const defaultValue = opt.default
        setProp(key, isFunction(defaultValue) ? defaultValue() : defaultValue)
      }
      // boolean casting
      if (opt[BooleanFlags.shouldCast]) {
        if (isAbsent && !hasDefault) {
          setProp(key, false)
        } else if (
          opt[BooleanFlags.shouldCastTrue] &&
          (currentValue === '' || currentValue === hyphenate(key))
        ) {
          setProp(key, true)
        }
github vuejs / vue-next / packages / reactivity / src / collectionHandlers.ts View on Github external
return (
    target: CollectionTypes,
    key: string | symbol,
    receiver: CollectionTypes
  ) =>
    Reflect.get(
      hasOwn(instrumentations, key) && key in target
        ? instrumentations
        : target,
      key,
      receiver
    )
}
github vuejs / vue-next / packages / runtime-core / src / componentProxy.ts View on Github external
has(target: ComponentInternalInstance, key: string) {
    const { data, accessCache, renderContext, type, sink } = target
    return (
      accessCache![key] !== undefined ||
      (data !== EMPTY_OBJ && hasOwn(data, key)) ||
      hasOwn(renderContext, key) ||
      (type.props != null && hasOwn(type.props, key)) ||
      hasOwn(publicPropertiesMap, key) ||
      hasOwn(sink, key)
    )
  },
github vuejs / vue-next / packages / runtime-core / src / componentProxy.ts View on Github external
has(target: ComponentInternalInstance, key: string) {
    const { data, accessCache, renderContext, type, sink } = target
    return (
      accessCache![key] !== undefined ||
      (data !== EMPTY_OBJ && hasOwn(data, key)) ||
      hasOwn(renderContext, key) ||
      (type.props != null && hasOwn(type.props, key)) ||
      hasOwn(publicPropertiesMap, key) ||
      hasOwn(sink, key)
    )
  },