fix(runtime-core): `in` operator returning `false` for built-in instance properties in `exposeProxy` (#6138)

fix #6137
This commit is contained in:
Julian Meinking 2022-10-26 11:54:10 +02:00 committed by GitHub
parent 018b850399
commit 32b51249bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -203,7 +203,9 @@ describe('api: expose', () => {
return h('div') return h('div')
}, },
setup(_, { expose }) { setup(_, { expose }) {
expose() expose({
foo: 42
})
return () => h(GrandChild, { ref: grandChildRef }) return () => h(GrandChild, { ref: grandChildRef })
} }
}) })
@ -216,7 +218,10 @@ describe('api: expose', () => {
} }
const root = nodeOps.createElement('div') const root = nodeOps.createElement('div')
render(h(Parent), root) render(h(Parent), root)
expect('$el' in childRef.value).toBe(true)
expect(childRef.value.$el.tag).toBe('div') expect(childRef.value.$el.tag).toBe('div')
expect('foo' in childRef.value).toBe(true)
expect('$parent' in grandChildRef.value).toBe(true)
expect(grandChildRef.value.$parent).toBe(childRef.value) expect(grandChildRef.value.$parent).toBe(childRef.value)
expect(grandChildRef.value.$parent.$parent).toBe(grandChildRef.value.$root) expect(grandChildRef.value.$parent.$parent).toBe(grandChildRef.value.$root)
}) })

View File

@ -945,6 +945,9 @@ export function getExposeProxy(instance: ComponentInternalInstance) {
} else if (key in publicPropertiesMap) { } else if (key in publicPropertiesMap) {
return publicPropertiesMap[key](instance) return publicPropertiesMap[key](instance)
} }
},
has(target, key: string) {
return key in target || key in publicPropertiesMap
} }
})) }))
) )