Search in sources :

Example 6 with CallParamValueNode

use of com.google.template.soy.soytree.CallParamValueNode in project closure-templates by google.

the class SoyNodeCompiler method prepareParamsHelper.

private Expression prepareParamsHelper(CallNode node, Label reattachPoint) {
    if (node.numChildren() == 0) {
        // Easy, just use the data attribute
        return getDataExpression(node, reattachPoint);
    } else {
        // Otherwise we need to build a dictionary from {param} statements.
        Expression paramStoreExpression = getParamStoreExpression(node, reattachPoint);
        for (CallParamNode child : node.getChildren()) {
            String paramKey = child.getKey().identifier();
            Expression valueExpr;
            if (child instanceof CallParamContentNode) {
                valueExpr = lazyClosureCompiler.compileLazyContent("param", (CallParamContentNode) child, paramKey);
            } else {
                valueExpr = lazyClosureCompiler.compileLazyExpression("param", child, paramKey, ((CallParamValueNode) child).getExpr());
            }
            // ParamStore.setField return 'this' so we can just chain the invocations together.
            paramStoreExpression = MethodRef.PARAM_STORE_SET_FIELD.invoke(paramStoreExpression, BytecodeUtils.constant(paramKey), valueExpr);
        }
        return paramStoreExpression;
    }
}
Also used : SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression) CallParamContentNode(com.google.template.soy.soytree.CallParamContentNode) CallParamNode(com.google.template.soy.soytree.CallParamNode) CallParamValueNode(com.google.template.soy.soytree.CallParamValueNode)

Aggregations

CallParamContentNode (com.google.template.soy.soytree.CallParamContentNode)6 CallParamValueNode (com.google.template.soy.soytree.CallParamValueNode)6 CallParamNode (com.google.template.soy.soytree.CallParamNode)4 FunctionNode (com.google.template.soy.exprtree.FunctionNode)2 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)1 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)1 SoyRecord (com.google.template.soy.data.SoyRecord)1 SoyValue (com.google.template.soy.data.SoyValue)1 AugmentedParamStore (com.google.template.soy.data.internal.AugmentedParamStore)1 BasicParamStore (com.google.template.soy.data.internal.BasicParamStore)1 ParamStore (com.google.template.soy.data.internal.ParamStore)1 Expression (com.google.template.soy.jbcsrc.restricted.Expression)1 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)1 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)1 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)1 PyListExpr (com.google.template.soy.pysrc.restricted.PyListExpr)1 PyStringExpr (com.google.template.soy.pysrc.restricted.PyStringExpr)1