import R = require ( './regexes' ) ; /**
 * Regex for replacing of jscc varnames ($1 = prefix, $2 = varname).
 */ const VARS_TO_EVL = RegExp ( `${ R . S_STRINGS }|${ R . S_VARNAMES }` , 'g' ) ; /**
 * Replacing function
 */ const _repVars = function ( this , match , prech , vname ) { return vname ? prech + ( vname in this ? `this.${ vname }` : `global.${ vname }` ) : match ; } ; param ctx param exprStr const evalExpr = function _evalExpr ( ctx , exprStr ) { const values = ctx . values ; const expr = exprStr . replace ( /\n/g , '\\n' ) . replace ( /\r/g , '\\r' ) . replace ( VARS_TO_EVL , _repVars . bind ( values ) ) ; let result ; try { const fn = new Function ( '' , `return (${ expr }\n);` ) ; result = fn . call ( values ) ; } catch ( e ) { result = exprStr ; ctx . errorHandler ( `${ e . message } in expression "${ expr }"` ) ; } return result ; } ; export = evalExpr ;