import { Node , ESTree } from "../../Node" ; import { BaseClosure , } from '../../Closure' ; import { Messages } from '../../Message' ; import { Interpreter } from '../../../interpreter/main' ; import { EmptyStatementReturn } from '../../Symbols' ; import Scope , { createScope } from "../../Scope" ; export function ifStatementHandler ( this , node ) { this . blockDeclareStart ( ) ; const testClosure = this . createClosure ( node . test ) ; const consequentClosure = this . createClosure ( node . consequent ) ; const alternateClosure = node . alternate ? this . createClosure ( node . alternate ) : ( ) => EmptyStatementReturn ; let lexDeclared = this . blockDeclareEnd ( ) ; return ( ) => { let prevScope ; let newScope ; if ( lexDeclared ) { newScope = createScope ( this . getCurrentScope ( ) , `BScope(if)` , "block" ) ; newScope . lexDeclared = lexDeclared ; prevScope = this . entryBlockScope ( newScope ) ; } let res = testClosure ( ) ? consequentClosure ( ) : alternateClosure ( ) ; if ( lexDeclared ) { this . setCurrentScope ( prevScope ! ) ; } return res ; } ; }