11import { defineComponent , type ComponentCustomOptions } from 'vue' ;
2- import { obtainSlot , getSuperSlot } from './utils'
2+ import { obtainSlot , getSuperSlot , getProviderFunction } from './utils'
33import { build as optionSetup } from './option/setup'
44import { build as optionComputed } from './option/computed'
55import { build as optionData } from './option/data'
@@ -8,6 +8,7 @@ import { build as optionRef } from './option/ref'
88import { build as optionWatch } from './option/watch'
99import { build as optionProps } from './option/props'
1010import { build as optionInject } from './option/inject'
11+ import { build as optionProvide } from './option/provide'
1112import { build as optionEmit } from './option/emit'
1213import { build as optionVModel } from './option/vmodel'
1314import { build as optionAccessor } from './option/accessor'
@@ -45,6 +46,10 @@ function ComponentOption(cons: Cons, extend?: any) {
4546 watch : optionBuilder . watch ,
4647 props : optionBuilder . props ,
4748 inject : optionBuilder . inject ,
49+ provide ( ) {
50+ optionProvide ( cons , optionBuilder , this )
51+ return optionBuilder . provide ?? { }
52+ } ,
4853 ...optionBuilder . hooks ,
4954 extends : extend
5055 }
@@ -73,7 +78,7 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
7378 const option = ComponentOption ( cons , extend )
7479 const slot = obtainSlot ( cons . prototype )
7580 Object . keys ( arg ) . reduce < Record < string , any > > ( ( option , name : string ) => {
76- if ( [ 'options' , 'modifier' , 'emits' , 'setup' ] . includes ( name ) ) {
81+ if ( [ 'options' , 'modifier' , 'emits' , 'setup' , 'provide' ] . includes ( name ) ) {
7782 return option
7883 }
7984 option [ name ] = arg [ name as keyof ComponentOption ]
@@ -113,6 +118,13 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
113118 option . setup = setup
114119 }
115120
121+ //merge provide function
122+ const oldProvider = getProviderFunction ( option . provide )
123+ const newProvider = getProviderFunction ( arg . provide )
124+ option . provide = function ( ) {
125+ return Object . assign ( { } , oldProvider . call ( this ) , newProvider . call ( this ) )
126+ }
127+
116128 //custom decorator
117129 const map = slot . getMap ( 'customDecorator' )
118130 if ( map && map . size > 0 ) {
0 commit comments