@@ -30,16 +30,10 @@ function ComponentOption(cons: Cons, extend?: any) {
3030 optionInject ( cons , optionBuilder )
3131 optionEmit ( cons , optionBuilder )
3232 optionRef ( cons , optionBuilder ) //after Computed
33- optionMethodsAndHooks ( cons , optionBuilder ) //after Ref Computed
3433 optionAccessor ( cons , optionBuilder )
35-
36-
37- const setupFunction : OptionSetupFunction | undefined = optionBuilder . setup ? function ( props , ctx ) {
38- return optionBuilder . setup ! ( props , ctx )
39- } : undefined
40-
34+ optionMethodsAndHooks ( cons , optionBuilder ) //the last one
4135 const raw = {
42- setup : setupFunction ,
36+ setup : optionBuilder . setup ,
4337 data ( ) {
4438 delete optionBuilder . data
4539 optionData ( cons , optionBuilder , this )
@@ -71,7 +65,9 @@ type ComponentOption = {
7165 mixins ?: any [ ]
7266 setup ?: ComponentSetupFunction
7367}
68+
7469type ComponentConsOption = Cons | ComponentOption
70+
7571function buildComponent ( cons : Cons , arg : ComponentOption , extend ?: any ) : any {
7672 const option = ComponentOption ( cons , extend )
7773 const slot = obtainSlot ( cons . prototype )
@@ -82,21 +78,21 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
8278 option [ name ] = arg [ name as keyof ComponentOption ]
8379 return option
8480 } , option )
81+
82+ //apply event emits
8583 let emits = Array . from ( slot . obtainMap ( 'emits' ) . keys ( ) )
8684 if ( Array . isArray ( arg . emits ) ) {
8785 emits = Array . from ( new Set ( [ ...emits , ...arg . emits ] ) )
8886 }
8987 option . emits = emits
9088
91- arg . setup ??= function ( ) { return { } }
92-
89+ //merge setup function
9390 if ( ! option . setup ) {
94-
9591 option . setup = arg . setup
9692 } else {
9793
9894 const oldSetup : OptionSetupFunction = option . setup
99- const newSetup : ComponentSetupFunction = arg . setup
95+ const newSetup : ComponentSetupFunction = arg . setup ?? function ( ) { return { } }
10096
10197 const setup : ComponentSetupFunction = function ( props , ctx ) {
10298 const newRet = newSetup ( props , ctx )
@@ -116,16 +112,24 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
116112 option . setup = setup
117113 }
118114
119- slot . obtainMap ( 'customDecorator' ) . forEach ( ( v ) => {
120- v . creator . apply ( { } , [ option , v . key ] )
121- } )
115+ //custom decorator
116+ const map = slot . getMap ( 'customDecorator' )
117+ if ( map && map . size > 0 ) {
118+ map . forEach ( ( v ) => {
119+ v . creator . apply ( { } , [ option , v . key ] )
120+ } )
121+ }
122122
123+ //shallow merge options
123124 if ( arg . options ) {
124125 Object . assign ( option , arg . options )
125126 }
127+
128+ //apply modifier
126129 if ( arg . modifier ) {
127130 arg . modifier ( option )
128131 }
132+
129133 return defineComponent ( option )
130134}
131135function build ( cons : Cons , option : ComponentOption ) {
0 commit comments