refactor: extract hasOwn helper
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
||||
isFunction,
|
||||
isArray,
|
||||
isObject,
|
||||
isReservedProp
|
||||
isReservedProp,
|
||||
hasOwn
|
||||
} from '@vue/shared'
|
||||
import { warn } from './warning'
|
||||
import { Data, ComponentInstance } from './component'
|
||||
@@ -123,7 +124,7 @@ export function resolveProps(
|
||||
if (isReservedProp(key)) continue
|
||||
// any non-declared data are put into a separate `attrs` object
|
||||
// for spreading
|
||||
if (hasDeclaredProps && !options.hasOwnProperty(key)) {
|
||||
if (hasDeclaredProps && !hasOwn(options, key)) {
|
||||
;(attrs || (attrs = {}))[key] = rawProps[key]
|
||||
} else {
|
||||
setProp(key, rawProps[key])
|
||||
@@ -135,8 +136,8 @@ export function resolveProps(
|
||||
for (const key in options) {
|
||||
let opt = options[key]
|
||||
if (opt == null) continue
|
||||
const isAbsent = !props.hasOwnProperty(key)
|
||||
const hasDefault = opt.hasOwnProperty('default')
|
||||
const isAbsent = !hasOwn(props, key)
|
||||
const hasDefault = hasOwn(opt, 'default')
|
||||
const currentValue = props[key]
|
||||
// default values
|
||||
if (hasDefault && currentValue === undefined) {
|
||||
@@ -173,7 +174,7 @@ export function resolveProps(
|
||||
) {
|
||||
const rawInitialProps = toRaw(propsProxy)
|
||||
for (const key in rawInitialProps) {
|
||||
if (!props.hasOwnProperty(key)) {
|
||||
if (!hasOwn(props, key)) {
|
||||
delete propsProxy[key]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { ComponentInstance } from './component'
|
||||
import { nextTick } from './scheduler'
|
||||
import { instanceWatch } from './apiWatch'
|
||||
import { EMPTY_OBJ } from '@vue/shared'
|
||||
import { EMPTY_OBJ, hasOwn } from '@vue/shared'
|
||||
|
||||
export const RenderProxyHandlers = {
|
||||
get(target: ComponentInstance, key: string) {
|
||||
const { renderContext, data, props, propsProxy } = target
|
||||
if (data !== EMPTY_OBJ && data.hasOwnProperty(key)) {
|
||||
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||||
return data[key]
|
||||
} else if (renderContext.hasOwnProperty(key)) {
|
||||
} else if (hasOwn(renderContext, key)) {
|
||||
return renderContext[key]
|
||||
} else if (props.hasOwnProperty(key)) {
|
||||
} else if (hasOwn(props, key)) {
|
||||
// return the value from propsProxy for ref unwrapping and readonly
|
||||
return (propsProxy as any)[key]
|
||||
} else {
|
||||
@@ -53,9 +53,9 @@ export const RenderProxyHandlers = {
|
||||
},
|
||||
set(target: ComponentInstance, key: string, value: any): boolean {
|
||||
const { data, renderContext } = target
|
||||
if (data !== EMPTY_OBJ && data.hasOwnProperty(key)) {
|
||||
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||||
data[key] = value
|
||||
} else if (renderContext.hasOwnProperty(key)) {
|
||||
} else if (hasOwn(renderContext, key)) {
|
||||
renderContext[key] = value
|
||||
} else if (key[0] === '$' && key.slice(1) in target) {
|
||||
// TODO warn attempt of mutating public property
|
||||
|
||||
Reference in New Issue
Block a user