import { lazy } from './LazyParser' ; import type { Parser } from './ParserInterface' ; const defineReadOnly = < Target , Value > ( target , propName , value ) : Target & { readonly [ name in typeof propName ] : Value ; } => < Target & { readonly [ name in typeof propName ] : Value ; } > Object . defineProperty ( target , propName , { configurable : true , writable : false , enumerable : true , value } ) ; export function makeParserModule < TKind , TResult > ( definitions ) { let parserModule = < { [ K in keyof typeof definitions ] : ReturnType < typeof definitions [ K ] > ; } > Object . create ( null ) ; for ( const [ key , parserThunk ] of Object . entries ( definitions ) ) { parserModule = defineReadOnly ( parserModule , key , lazy ( ( ) => parserThunk ( parserModule ) ) ) ; } return parserModule ; }