import { IFunctionCall } from './Call/IFunctionCall' ; import { FunctionBodyType , IFunctionCode , ISharedFunction , ISharedFunctionBody , } from './ISharedFunction' ; import { IReadOnlyFunctionParameterCollection } from './Parameter/IFunctionParameterCollection' ; export function createCallerFunction ( name , parameters , callSequence ) { if ( ! callSequence ) { throw new Error ( `undefined call sequence in function "${ name }"` ) ; } if ( ! callSequence . length ) { throw new Error ( `empty call sequence in function "${ name }"` ) ; } return new SharedFunction ( name , parameters , callSequence , FunctionBodyType . Calls ) ; } export function createFunctionWithInlineCode ( name , parameters , code , revertCode ? ) { if ( ! code ) { throw new Error ( `undefined code in function "${ name }"` ) ; } const content = { do : code , revert : revertCode , } ; return new SharedFunction ( name , parameters , content , FunctionBodyType . Code ) ; } class SharedFunction implements ISharedFunction { public readonly body : ISharedFunctionBody ; constructor ( public readonly name , public readonly parameters , content , bodyType ) { if ( ! name ) { throw new Error ( 'undefined function name' ) ; } if ( ! parameters ) { throw new Error ( 'undefined parameters' ) ; } this . body = { type : bodyType , code : bodyType === FunctionBodyType . Code ? content as IFunctionCode : undefined , calls : bodyType === FunctionBodyType . Calls ? content as readonly IFunctionCall [ ] : undefined , } ; } }