11import { Metadata } from 'facing-metadata'
2- import { Base } from './index'
32import type { Identity } from './identity'
43import type { InjectConfig } from "./option/inject" ;
54import type { EmitConfig } from "./option/emit" ;
@@ -11,7 +10,9 @@ import type { SetupConfig } from './option/setup'
1110import type { Record as CustomDecoratorRecord } from './custom/custom'
1211import type { RefConfig } from './option/ref' ;
1312import type { ProvideConfig } from './option/provide' ;
14- import { compatibleMemberDecorator } from './deco3/utils' ;
13+ import { compatibleMemberDecorator , compatibleClassDecorator } from './deco3/utils' ;
14+ import { type VueCons , Base } from './class' ;
15+
1516
1617const SlotSymbol = Symbol ( 'vue-facing-decorator-slot' )
1718
@@ -62,7 +63,7 @@ export function makeSlot(obj: any, defaultSlot?: Slot): Slot {
6263 defaultSlot . master = obj
6364 }
6465 const slot = defaultSlot ?? new Slot ( obj )
65- metadata . create ( obj , slot )
66+ metadata . create ( obj , slot )
6667 return slot
6768}
6869
@@ -152,25 +153,50 @@ export function getValidNames(obj: any, filter: (des: PropertyDescriptor, name:
152153}
153154
154155export function optionNullableMemberDecorator < T > ( handler : { ( proto : any , name : string , option ?: T ) : any } ) {
155- function decorator ( option ?: T ) : any
156- function decorator ( proto : Identity , name : any ) : any
156+ function decorator ( ) : any
157+ function decorator ( option : T ) : any //option
158+ function decorator ( proto : Identity , name : any ) : any //deco stage 2
157159 function decorator ( value : any , ctx : ClassMemberDecoratorContext ) : any //deco stage 3
158- function decorator ( optionOrProto ?: T | Identity | any , name ?: string | ClassMemberDecoratorContext ) : any {
159- if ( name ) {
160+ function decorator ( optionOrProtoOrValue ?: T | Identity | any , nameOrCtx ?: string | ClassMemberDecoratorContext ) : any {
161+ if ( nameOrCtx ) { //no option
162+ const protoOrValue = optionOrProtoOrValue as Identity | any
160163 compatibleMemberDecorator ( function ( proto : any , name : any ) {
161164 handler ( proto , name )
162- } ) ( optionOrProto , name )
165+ } ) ( protoOrValue , nameOrCtx )
163166 }
164- else {
167+ else { //with option
168+ const option = optionOrProtoOrValue as T
165169 return compatibleMemberDecorator ( function ( proto : any , name : any ) {
166- handler ( proto , name , optionOrProto as T | undefined )
170+ handler ( proto , name , option as T | undefined )
167171 } )
168172 }
169173 }
170174
171175 return decorator
172176}
173177
178+ export function optionNullableClassDecorator < T > ( handler : { ( cons : VueCons , option ?: T ) : any } ) {
179+ function decorator ( ) : any
180+ function decorator ( option : T ) : any //option
181+ function decorator ( cons : VueCons ) : any //deco stage 2
182+ function decorator ( cons : VueCons , ctx : ClassDecoratorContext ) : any //deco stage 3
183+ function decorator ( optionOrCons ?: T | VueCons , ctx ?: ClassDecoratorContext ) {
184+ if ( typeof optionOrCons === 'function' ) {
185+ const cons = optionOrCons as VueCons
186+ compatibleClassDecorator ( function ( cons : VueCons ) {
187+ handler ( cons )
188+ } ) ( cons , ctx )
189+
190+ } else {
191+ const option = optionOrCons as T
192+ return compatibleClassDecorator ( function ( cons : VueCons ) {
193+ handler ( cons , option )
194+ } )
195+ }
196+ }
197+ return decorator
198+ }
199+
174200export function getProviderFunction ( provide : any ) : ( ) => { } {
175201 if ( typeof provide === 'function' ) return provide
176202 return function ( ) { return provide || { } }
0 commit comments