11import type { VueConstructor } from 'vue'
2- import {
3- ComponentInstance ,
4- SetupContext ,
5- SetupFunction ,
6- Data ,
7- } from './component'
2+ import { ComponentInstance , SetupFunction , Data } from './component'
83import { isRef , isReactive , toRefs , isRaw } from './reactivity'
94import {
105 isPlainObject ,
@@ -24,7 +19,11 @@ import {
2419 resolveScopedSlots ,
2520 asVmProperty ,
2621} from './utils/instance'
27- import { getVueConstructor } from './runtimeContext'
22+ import {
23+ getVueConstructor ,
24+ SetupContext ,
25+ toVue3ComponentInstance ,
26+ } from './runtimeContext'
2827import { createObserver , reactive } from './reactivity/reactive'
2928
3029export function mixin ( Vue : VueConstructor ) {
@@ -53,7 +52,9 @@ export function mixin(Vue: VueConstructor) {
5352 if ( render ) {
5453 // keep currentInstance accessible for createElement
5554 $options . render = function ( ...args : any ) : any {
56- return activateCurrentInstance ( vm , ( ) => render . apply ( this , args ) )
55+ return activateCurrentInstance ( toVue3ComponentInstance ( vm ) , ( ) =>
56+ render . apply ( this , args )
57+ )
5758 }
5859 }
5960
@@ -85,16 +86,17 @@ export function mixin(Vue: VueConstructor) {
8586 function initSetup ( vm : ComponentInstance , props : Record < any , any > = { } ) {
8687 const setup = vm . $options . setup !
8788 const ctx = createSetupContext ( vm )
89+ const instance = toVue3ComponentInstance ( vm )
90+ instance . setupContext = ctx
8891
8992 // fake reactive for `toRefs(props)`
9093 def ( props , '__ob__' , createObserver ( ) )
9194
9295 // resolve scopedSlots and slots to functions
93- // @ts -expect-error
9496 resolveScopedSlots ( vm , ctx . slots )
9597
9698 let binding : ReturnType < SetupFunction < Data , Data > > | undefined | null
97- activateCurrentInstance ( vm , ( ) => {
99+ activateCurrentInstance ( instance , ( ) => {
98100 // make props to be fake reactive, this is for `toRefs(props)`
99101 binding = setup ( props , ctx )
100102 } )
@@ -105,9 +107,8 @@ export function mixin(Vue: VueConstructor) {
105107 const bindingFunc = binding
106108 // keep currentInstance accessible for createElement
107109 vm . $options . render = ( ) => {
108- // @ts -expect-error
109110 resolveScopedSlots ( vm , ctx . slots )
110- return activateCurrentInstance ( vm , ( ) => bindingFunc ( ) )
111+ return activateCurrentInstance ( instance , ( ) => bindingFunc ( ) )
111112 }
112113 return
113114 } else if ( isPlainObject ( binding ) ) {
@@ -228,23 +229,25 @@ export function mixin(Vue: VueConstructor) {
228229 } )
229230 } )
230231
232+ let propsProxy : any
231233 propsReactiveProxy . forEach ( ( key ) => {
232234 let srcKey = `$${ key } `
233235 proxy ( ctx , key , {
234236 get : ( ) => {
235- const data = reactive ( { } )
237+ if ( propsProxy ) return propsProxy
238+ propsProxy = reactive ( { } )
236239 const source = vm [ srcKey ]
237240
238241 for ( const attr of Object . keys ( source ) ) {
239- proxy ( data , attr , {
242+ proxy ( propsProxy , attr , {
240243 get : ( ) => {
241244 // to ensure it always return the latest value
242245 return vm [ srcKey ] [ attr ]
243246 } ,
244247 } )
245248 }
246249
247- return data
250+ return propsProxy
248251 } ,
249252 set ( ) {
250253 __DEV__ &&
0 commit comments