1- import { EffectScope } from '@vue/reactivity'
2- import { EMPTY_OBJ , NOOP , isFunction } from '@vue/shared'
1+ import { EffectScope , isRef } from '@vue/reactivity'
2+ import { EMPTY_OBJ , isArray , isFunction } from '@vue/shared'
33import type { Block } from './apiRender'
44import type { DirectiveBinding } from './directives'
55import {
@@ -45,6 +45,30 @@ export type SetupContext<E = EmitsOptions> = E extends any
4545export function createSetupContext (
4646 instance : ComponentInternalInstance ,
4747) : SetupContext {
48+ const expose : SetupContext [ 'expose' ] = exposed => {
49+ if ( __DEV__ ) {
50+ if ( instance . exposed ) {
51+ warn ( `expose() should be called only once per setup().` )
52+ }
53+ if ( exposed != null ) {
54+ let exposedType : string = typeof exposed
55+ if ( exposedType === 'object' ) {
56+ if ( isArray ( exposed ) ) {
57+ exposedType = 'array'
58+ } else if ( isRef ( exposed ) ) {
59+ exposedType = 'ref'
60+ }
61+ }
62+ if ( exposedType !== 'object' ) {
63+ warn (
64+ `expose() should be passed a plain object, received ${ exposedType } .` ,
65+ )
66+ }
67+ }
68+ }
69+ instance . exposed = exposed || { }
70+ }
71+
4872 if ( __DEV__ ) {
4973 // We use getters in dev in case libs like test-utils overwrite instance
5074 // properties (overwrites should not be done in prod)
@@ -58,7 +82,7 @@ export function createSetupContext(
5882 get emit ( ) {
5983 return ( event : string , ...args : any [ ] ) => instance . emit ( event , ...args )
6084 } ,
61- expose : NOOP ,
85+ expose,
6286 } )
6387 } else {
6488 return {
@@ -67,7 +91,7 @@ export function createSetupContext(
6791 } ,
6892 emit : instance . emit ,
6993 slots : instance . slots ,
70- expose : NOOP ,
94+ expose,
7195 }
7296 }
7397}
@@ -114,9 +138,12 @@ export interface ComponentInternalInstance {
114138 attrs : Data
115139 slots : InternalSlots
116140 refs : Data
141+ // exposed properties via expose()
142+ exposed ?: Record < string , any >
117143
118144 attrsProxy ?: Data
119145 slotsProxy ?: Slots
146+ exposeProxy ?: Record < string , any >
120147
121148 // lifecycle
122149 isMounted : boolean
0 commit comments