File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 7
7
DirectiveHook ,
8
8
VNode ,
9
9
DirectiveBinding ,
10
- nextTick
10
+ nextTick ,
11
+ defineComponent
11
12
} from '@vue/runtime-test'
12
13
import { currentInstance , ComponentInternalInstance } from '../src/component'
13
14
@@ -395,4 +396,29 @@ describe('directives', () => {
395
396
expect ( beforeUpdate ) . toHaveBeenCalledTimes ( 1 )
396
397
expect ( count . value ) . toBe ( 1 )
397
398
} )
399
+
400
+ test ( 'should receive exposeProxy for closed instances' , async ( ) => {
401
+ let res : string
402
+ const App = defineComponent ( {
403
+ setup ( _ , { expose } ) {
404
+ expose ( {
405
+ msg : 'Test'
406
+ } )
407
+
408
+ return ( ) =>
409
+ withDirectives ( h ( 'p' , 'Lore Ipsum' ) , [
410
+ [
411
+ {
412
+ mounted ( el , { instance } ) {
413
+ res = ( instance as any ) . msg as string
414
+ }
415
+ }
416
+ ]
417
+ ] )
418
+ }
419
+ } )
420
+ const root = nodeOps . createElement ( 'div' )
421
+ render ( h ( App ) , root )
422
+ expect ( res ! ) . toBe ( 'Test' )
423
+ } )
398
424
} )
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ return withDirectives(h(comp), [
14
14
import { VNode } from './vnode'
15
15
import { isFunction , EMPTY_OBJ , makeMap } from '@vue/shared'
16
16
import { warn } from './warning'
17
- import { ComponentInternalInstance , Data } from './component'
17
+ import { ComponentInternalInstance , Data , getExposeProxy } from './component'
18
18
import { currentRenderingInstance } from './componentRenderContext'
19
19
import { callWithAsyncErrorHandling , ErrorCodes } from './errorHandling'
20
20
import { ComponentPublicInstance } from './componentPublicInstance'
@@ -93,7 +93,9 @@ export function withDirectives<T extends VNode>(
93
93
__DEV__ && warn ( `withDirectives can only be used inside render functions.` )
94
94
return vnode
95
95
}
96
- const instance = internalInstance . proxy
96
+ const instance =
97
+ ( getExposeProxy ( internalInstance ) as ComponentPublicInstance ) ||
98
+ internalInstance . proxy
97
99
const bindings : DirectiveBinding [ ] = vnode . dirs || ( vnode . dirs = [ ] )
98
100
for ( let i = 0 ; i < directives . length ; i ++ ) {
99
101
let [ dir , value , arg , modifiers = EMPTY_OBJ ] = directives [ i ]
You can’t perform that action at this time.
0 commit comments