import { Node , ESTree } from "../../Node" ; import { BaseClosure , } from '../../Closure' ; import { Messages } from '../../Message' ; import { Interpreter } from '../../../interpreter/main' ; import { isSymbol } from '../../Symbols' ; export function unaryExpressionHandler ( this , node ) { switch ( node . operator ) { case "delete" : const objectGetter = this . createObjectGetter ( node . argument ) ; const nameGetter = this . createNameGetter ( node . argument ) ; return ( ) => { let obj = objectGetter ( ) ; const name = nameGetter ( ) ; return delete obj [ name ] ; } ; default : let expression ; if ( node . operator === "typeof" && node . argument . type === "Identifier" ) { const objectGetter = this . createObjectGetter ( node . argument ) ; const nameGetter = this . createNameGetter ( node . argument ) ; expression = ( ) => objectGetter ( ) [ nameGetter ( ) ] ; } else { expression = this . createClosure ( node . argument ) ; } return ( ) => { const value = expression ( ) ; switch ( node . operator ) { case "-" : return - value ; case "+" : return + value ; case "!" : return ! value ; case "~" : return ~ value ; case "void" : return void value ; case "typeof" : if ( isSymbol ( value ) ) { return 'symbol' ; } return typeof value ; default : throw this . createInternalThrowError ( Messages . UnaryOperatorSyntaxError , node . operator , node ) ; } } ; } }