vue3-core/packages/runtime-core/src/compat/props.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-04-22 03:09:18 +08:00
import { isArray } from '@vue/shared'
import { inject } from '../apiInject'
import type { ComponentInternalInstance, Data } from '../component'
import {
type ComponentOptions,
resolveMergedOptions,
} from '../componentOptions'
import { DeprecationTypes, warnDeprecation } from './compatConfig'
2021-04-06 23:08:21 +08:00
2021-04-22 03:09:18 +08:00
export function createPropsDefaultThis(
instance: ComponentInternalInstance,
rawProps: Data,
propKey: string,
) {
2021-04-06 23:08:21 +08:00
return new Proxy(
{},
{
2021-04-22 03:09:18 +08:00
get(_, key: string) {
__DEV__ &&
warnDeprecation(DeprecationTypes.PROPS_DEFAULT_THIS, null, propKey)
// $options
if (key === '$options') {
return resolveMergedOptions(instance)
}
// props
if (key in rawProps) {
return rawProps[key]
}
// injections
const injections = (instance.type as ComponentOptions).inject
if (injections) {
if (isArray(injections)) {
if (injections.includes(key)) {
return inject(key)
}
} else if (key in injections) {
return inject(key)
}
}
2021-04-06 23:08:21 +08:00
},
},
)
}