import { MemberDescriptor , createDecoratorFactory , isField , defaultFieldAttributes } from '@esfx/decorators-stage1-core' ; export const lazyinit = createDecoratorFactory ( ( member , initializer , attributes = { } ) => { if ( ! isField ( member ) ) throw new TypeError ( `'@lazyinit' is only supported on fields.` ) ; const { target , key } = member ; const { enumerable , configurable , writable } = { ... defaultFieldAttributes , ... attributes } ; const descriptor = { enumerable , configurable : true , get ( this ) { if ( this === target ) return undefined ; const value = Reflect . apply ( initializer , this , [ ] ) ; Object . defineProperty ( this , key , { enumerable , configurable , writable , value } ) ; return value ; } , set : writable ? function ( this , value ) { Object . defineProperty ( this , key , { ... defaultFieldAttributes , value } ) ; } : undefined } ; Object . defineProperty ( target , key , descriptor ) ; } ) ;