import { createDecoratorOrDecoratorFactory , MemberDescriptor , ClassDescriptor , isMethod , isAccessor , AccessorMemberDescriptor , MethodMemberDescriptor } from "@esfx/decorators-stage1-core" ; import { isFunction } from "@esfx/internal-guards" ; function formatClassDeprecationMessage ( descriptor , message = `This class will be removed in a future revision.` ) { return `DEPRECATION ${ descriptor . target . name }: ${ message }` ; } function formatMemberDeprecationMessage ( descriptor , message = `This member will be removed in a future revision.` ) { const containerName = isFunction ( descriptor . target ) ? `${ descriptor . target . name }.` : `${ descriptor . target . constructor . name }#` ; const memberName = descriptor . key . toString ( ) ; return `DEPRECATION ${ containerName }${ memberName }: ${ message }` ; } function formatDeprecationMessage ( descriptor , message ? ) { return descriptor . kind === "class" ? formatClassDeprecationMessage ( descriptor , message ) : formatMemberDeprecationMessage ( descriptor , message ) ; } function handleDeprecation ( deprecation , descriptor , message ? , error ? ) { const deprecationMessage = formatDeprecationMessage ( descriptor , message ) ; if ( error ) throw TypeError ( deprecationMessage ) ; if ( ! deprecation . set ) { deprecation . set = true ; if ( typeof "console" !== undefined ) { if ( typeof console . warn === "function" ) { console . warn ( deprecationMessage ) ; } else if ( typeof console . log === "function" ) { console . log ( deprecationMessage ) ; } } } } function obsoleteClass ( descriptor , message ? , error ? ) { const deprecation = { set : false } ; const name = descriptor . target . name ; return { [ name ] : class extends ( descriptor . target as any ) { constructor ( ... args ) { handleDeprecation ( deprecation , descriptor , message , error ) ; super ( ... args ) ; } } } [ name ] ; } function obsoleteAccessor ( member , message ? , error ? ) { const deprecation = { set : false } ; if ( member . descriptor . get ) { const getter = member . descriptor . get ; member . descriptor . get = function ( ) { handleDeprecation ( deprecation , member , message , error ) ; return Reflect . apply ( getter , this , arguments ) ; } ; } if ( member . descriptor . set ) { const setter = member . descriptor . set ; member . descriptor . set = function ( ) { handleDeprecation ( deprecation , member , message , error ) ; return Reflect . apply ( setter , this , arguments ) ; } ; } return member . descriptor ; } function obsoleteMethod ( member , message ? , error ? ) { const deprecation = { set : false } ; const method = member . descriptor . value ; member . descriptor . value = { [ member . key ] : function ( ) { handleDeprecation ( deprecation , member , message , error ) ; return Reflect . apply ( method , this , arguments ) ; } } [ member . key as any ] ; return member . descriptor ; } function obsoleteMember ( member , message ? , error ? ) { if ( isAccessor ( member ) ) return obsoleteAccessor ( member , message , error ) ; if ( isMethod ( member ) ) return obsoleteMethod ( member , message , error ) ; throw new TypeError ( `'obsolete' is only supported on a class, method, or accessor.` ) ; } function obsoleteDecorator ( descriptor , message ? , error ? ) ; function obsoleteDecorator ( descriptor , message ? , error ? ) ; function obsoleteDecorator ( descriptor , message ? , error ? ) { if ( descriptor . kind === "class" ) return obsoleteClass ( descriptor , message , error ) ; if ( descriptor . kind === "member" ) return obsoleteMember ( descriptor , message , error ) ; throw new TypeError ( `'obsolete' is only supported on a class, method, or accessor.` ) ; } /**
 * Makes a member obsolete.
 */ export const obsolete = createDecoratorOrDecoratorFactory ( obsoleteDecorator ) ; export { obsolete as deprecate } ;