@@ -16,12 +16,10 @@ import type { SetupContext } from 'vue';
1616import type { OptionBuilder } from './optionBuilder'
1717import type { VueCons } from './class'
1818import * as DecoratorCompatible from './deco3/utils'
19- export type Cons = VueCons
20-
2119type SetupFunction < T > = ( this : void , props : Readonly < any > , ctx : SetupContext < any > ) => T | Promise < T >
2220export type OptionSetupFunction = SetupFunction < any >
2321export type ComponentSetupFunction = SetupFunction < Record < string , any > >
24- function ComponentOption ( cons : Cons , extend ?: any ) {
22+ function ComponentOption ( cons : VueCons , extend ?: any ) {
2523 const optionBuilder : OptionBuilder = { }
2624 optionSetup ( cons , optionBuilder )
2725 optionVModel ( cons , optionBuilder )
@@ -73,9 +71,9 @@ type ComponentOption = {
7371 methods ?: MethodOptions
7472}
7573
76- type ComponentConsOption = Cons | ComponentOption
74+ type ComponentConsOption = VueCons | ComponentOption
7775
78- function buildComponent ( cons : Cons , arg : ComponentOption , extend ?: any ) : any {
76+ function buildComponent ( cons : VueCons , arg : ComponentOption , extend ?: any ) : any {
7977 const option = ComponentOption ( cons , extend )
8078 const slot = obtainSlot ( cons . prototype )
8179 Object . keys ( arg ) . reduce < Record < string , any > > ( ( option , name : string ) => {
@@ -95,7 +93,7 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
9593
9694 //merge methods
9795 if ( 'object' === typeof arg . methods && ! Array . isArray ( arg . methods ) && arg . methods !== null ) {
98- option . methods ??= { }
96+ option . methods ??= { }
9997 Object . assign ( option . methods , arg . methods ) ;
10098 }
10199
@@ -124,15 +122,15 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
124122 //merge provide function
125123 const oldProvider = getProviderFunction ( option . provide )
126124 const newProvider = getProviderFunction ( arg . provide )
127- option . provide = function ( ) {
125+ option . provide = function ( ) {
128126 return Object . assign ( { } , oldProvider . call ( this ) , newProvider . call ( this ) )
129127 }
130128
131129 //custom decorator
132130 const map = slot . getMap ( 'customDecorator' )
133131 if ( map && map . size > 0 ) {
134132 map . forEach ( ( v ) => {
135- v . forEach ( ite => ite . creator . apply ( { } , [ option , ite . key ] ) )
133+ v . forEach ( ite => ite . creator . apply ( { } , [ option , ite . key ] ) )
136134 } )
137135 }
138136
@@ -148,7 +146,7 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
148146
149147 return defineComponent ( option )
150148}
151- function build ( cons : Cons , option : ComponentOption ) {
149+ function build ( cons : VueCons , option : ComponentOption ) {
152150 const slot = obtainSlot ( cons . prototype )
153151 slot . inComponent = true
154152 const superSlot = getSuperSlot ( cons . prototype )
@@ -165,26 +163,25 @@ function build(cons: Cons, option: ComponentOption) {
165163 slot . cachedVueComponent = component ;
166164 ( cons as any ) . __vccOpts = component
167165}
168- function _Component ( cb : ( cons : Cons , option : ComponentOption ) => any , arg : ComponentConsOption , ctx ?: ClassDecoratorContext ) {
166+
167+ export function ComponentBase ( arg : ComponentConsOption , ctx ?: ClassDecoratorContext ) : any {
168+ function process ( cons : VueCons , option : ComponentOption ) {
169+ build ( cons , option )
170+ return cons
171+ }
169172 if ( typeof arg === 'function' ) {
170- return DecoratorCompatible . compatibleClassDecorator ( function ( cons : Cons ) {
171- return cb ( cons , { } )
173+ return DecoratorCompatible . compatibleClassDecorator ( function ( cons : VueCons ) {
174+ return process ( cons , { } )
172175 } ) ( arg , ctx )
173176 }
174- return DecoratorCompatible . compatibleClassDecorator ( function ( cons : Cons ) {
175- return cb ( cons , arg )
177+ return DecoratorCompatible . compatibleClassDecorator ( function ( cons : VueCons ) {
178+ return process ( cons , arg )
176179 } )
177180}
178- export function ComponentBase ( arg : ComponentConsOption , ctx ?: ClassDecoratorContext ) : any {
179- return _Component ( function ( cons : Cons , option : ComponentOption ) {
180- build ( cons , option )
181- return cons
182- } , arg , ctx )
183- }
184181
185182
186183
187- export function toNative < T extends Cons > ( cons : T ) : T {
184+ export function toNative < T extends VueCons > ( cons : T ) : T {
188185 const slot = obtainSlot ( cons . prototype )
189186 if ( ! slot . inComponent ) {
190187 throw 'to native 1'
0 commit comments