instanceProxy.baz = 1
expect('baz' in instanceProxy).toBe(true)
})
+
+ // #864
+ test('should not warn declared but absent props', () => {
+ const Comp = {
+ props: ['test'],
+ render(this: any) {
+ return this.test
+ }
+ }
+ render(h(Comp), nodeOps.createElement('div'))
+ expect(
+ `was accessed during render but is not defined`
+ ).not.toHaveBeenWarned()
+ })
})
toRawType,
PatchFlags,
makeMap,
- isReservedProp
+ isReservedProp,
+ EMPTY_ARR
} from '@vue/shared'
import { warn } from './warning'
import { Data, ComponentInternalInstance } from './component'
return false
}
-function normalizePropsOptions(
+export function normalizePropsOptions(
raw: ComponentPropsOptions | void
): NormalizedPropsOptions {
if (!raw) {
- return [] as any
+ return EMPTY_ARR as any
}
if (normalizationMap.has(raw)) {
return normalizationMap.get(raw)!
currentRenderingInstance,
markAttrsAccessed
} from './componentRenderUtils'
+import { normalizePropsOptions } from './componentProps'
// public properties exposed on the proxy, which is used as the render context
// in templates (as `this` in the render option)
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
get(target: ComponentInternalInstance, key: string) {
- const {
- renderContext,
- data,
- props,
- propsProxy,
- accessCache,
- type,
- sink
- } = target
+ const { renderContext, data, propsProxy, accessCache, type, sink } = target
// data / props / renderContext
// This getter gets called for every property access on the render context
accessCache![key] = AccessTypes.CONTEXT
return renderContext[key]
} else if (type.props) {
- // only cache other properties when instance has declared (this stable)
+ // only cache other properties when instance has declared (thus stable)
// props
- if (hasOwn(props, key)) {
+ if (hasOwn(normalizePropsOptions(type.props)[0], key)) {
accessCache![key] = AccessTypes.PROPS
// return the value from propsProxy for ref unwrapping and readonly
return propsProxy![key]