Skip to content

Commit

Permalink
fix(runtime-core): in operator returning false for built-in insta…
Browse files Browse the repository at this point in the history
…nce properties in `exposeProxy`

`exposeProxy` implements a fallback logic for accessing built-in instance properties but was missing the same logic for the `in` operator in the Proxy's `has()` handler.

fix vuejs#6137
  • Loading branch information
DrJume committed Jun 18, 2022
1 parent 25f7a16 commit eda083e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/runtime-core/__tests__/apiExpose.spec.ts
Expand Up @@ -216,7 +216,9 @@ describe('api: expose', () => {
}
const root = nodeOps.createElement('div')
render(h(Parent), root)
expect('$el' in childRef.value).toBe(true)
expect(childRef.value.$el.tag).toBe('div')
expect('$parent' in grandChildRef.value).toBe(true)
expect(grandChildRef.value.$parent).toBe(childRef.value)
expect(grandChildRef.value.$parent.$parent).toBe(grandChildRef.value.$root)
})
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime-core/src/component.ts
Expand Up @@ -942,6 +942,15 @@ export function getExposeProxy(instance: ComponentInternalInstance) {
} else if (key in publicPropertiesMap) {
return publicPropertiesMap[key](instance)
}
},
has(target, key: string) {
if (key in target) {
return true
} else if (key in publicPropertiesMap) {
return true
}

return false
}
}))
)
Expand Down

0 comments on commit eda083e

Please sign in to comment.