import { ICompilerResult , ICompilerMessageDetail } from './type' ; export class CompilerErrorResult { _messageDetails ! : ICompilerMessageDetail [ ] ; constructor ( initErrorResult ? ) { this . init ( initErrorResult ) ; } init ( initErrorResult ? ) { this . _messageDetails = initErrorResult ?. messageDetails || [ ] ; } update ( messageDetails ) { for ( const messageDetail of messageDetails ) { const addError = ! this . _messageDetails . some ( detail => { if ( detail . filename === messageDetail . filename ) { detail . content = messageDetail . content ; return true ; } return false ; } ) ; if ( addError ) { this . _messageDetails . push ( messageDetail ) ; } } } removeByFileName ( filename ) { this . _messageDetails = this . _messageDetails . filter ( detail => detail . filename !== filename ) ; } get value ( ) : ICompilerResult { return { code : 1 , message : `Compilation failure ${ this . _messageDetails ?. length } files with Babel.` , messageDetails : this . _messageDetails , } ; } checkExistError ( ) { return this . _messageDetails . length > 0 ; } }