private void attemptPreeval ( ExprNode node ) { // Note that we need to catch RenderException because preevaluation may fail, e.g. when // (a) the expression uses a bidi function that needs bidiGlobalDir to be in scope, but the // apiCallScope is not currently active, // (b) the expression uses an external function (Soy V1 syntax), // (c) other cases I haven't thought up. SoyValue preevalResult ; try { preevalResult = preevalVisitor . exec ( node ) ; } catch ( RenderException e ) { return ; // failed to preevaluate } PrimitiveNode newNode = InternalValueUtils . convertPrimitiveDataToExpr ( ( PrimitiveData ) preevalResult , node . getSourceLocation ( ) ) ; if ( newNode != null ) { node . getParent ( ) . replaceChild ( node , newNode ) ; } }
Attempts to preevaluate a node . If successful the node is replaced with a new constant node in the tree . If unsuccessful the tree is not changed .