Search in sources :

Example 16 with SoyNode

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

the class IsComputableAsJsExprsVisitorTest method runTestHelper.

/**
 * @param indicesToNode Series of indices for walking down to the node we want to test.
 */
private static void runTestHelper(String soyCode, boolean expectedResult, int... indicesToNode) {
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
    SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
    assertThat(new IsComputableAsJsExprsVisitor().exec(node)).isEqualTo(expectedResult);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Example 17 with SoyNode

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

the class SoyNodeCompiler method visitIfNode.

@Override
protected Statement visitIfNode(IfNode node) {
    List<IfBlock> ifs = new ArrayList<>();
    Optional<Statement> elseBlock = Optional.absent();
    for (SoyNode child : node.getChildren()) {
        if (child instanceof IfCondNode) {
            IfCondNode icn = (IfCondNode) child;
            SoyExpression cond = exprCompiler.compile(icn.getExpr()).coerceToBoolean();
            Statement block = visitChildrenInNewScope(icn);
            ifs.add(IfBlock.create(cond, block));
        } else {
            IfElseNode ien = (IfElseNode) child;
            elseBlock = Optional.of(visitChildrenInNewScope(ien));
        }
    }
    return ControlFlow.ifElseChain(ifs, elseBlock);
}
Also used : IfElseNode(com.google.template.soy.soytree.IfElseNode) SoyNode(com.google.template.soy.soytree.SoyNode) IfCondNode(com.google.template.soy.soytree.IfCondNode) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Statement(com.google.template.soy.jbcsrc.restricted.Statement) ArrayList(java.util.ArrayList) IfBlock(com.google.template.soy.jbcsrc.ControlFlow.IfBlock)

Example 18 with SoyNode

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

the class GenJsExprsVisitorTest method generateChunks.

private static List<CodeChunk.WithValue> generateChunks(String soyCode, int... indicesToNode) {
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
    SoyNode node = SharedTestUtils.getNode(soyTree, indicesToNode);
    UniqueNameGenerator nameGenerator = JsSrcNameGenerators.forLocalVariables();
    GenJsExprsVisitor visitor = JsSrcTestUtils.createGenJsExprsVisitorFactory().create(TranslationContext.of(SoyToJsVariableMappings.startingWith(LOCAL_VAR_TRANSLATIONS), CodeChunk.Generator.create(nameGenerator), nameGenerator), AliasUtils.IDENTITY_ALIASES, boom);
    return visitor.exec(node);
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) UniqueNameGenerator(com.google.template.soy.base.internal.UniqueNameGenerator)

Example 19 with SoyNode

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

the class IsComputableAsPyExprVisitorTest method runTestHelper.

private static void runTestHelper(String soyNodeCode, boolean expectedResult) {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyNodeCode).parse().fileSet();
    SoyNode node = SharedTestUtils.getNode(soyTree, 0);
    assertThat(new IsComputableAsPyExprVisitor().exec(node)).isEqualTo(expectedResult);
}
Also used : SoyNode(com.google.template.soy.soytree.SoyNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Aggregations

SoyNode (com.google.template.soy.soytree.SoyNode)19 ParentSoyNode (com.google.template.soy.soytree.SoyNode.ParentSoyNode)9 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)6 IfCondNode (com.google.template.soy.soytree.IfCondNode)5 IfElseNode (com.google.template.soy.soytree.IfElseNode)5 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)4 ArrayList (java.util.ArrayList)4 ErrorReporter (com.google.template.soy.error.ErrorReporter)3 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)3 ImmutableList (com.google.common.collect.ImmutableList)2 UniqueNameGenerator (com.google.template.soy.base.internal.UniqueNameGenerator)2 IfBlock (com.google.template.soy.jbcsrc.ControlFlow.IfBlock)2 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)2 Statement (com.google.template.soy.jbcsrc.restricted.Statement)2 PyStringExpr (com.google.template.soy.pysrc.restricted.PyStringExpr)2 RawTextNode (com.google.template.soy.soytree.RawTextNode)2 SwitchCaseNode (com.google.template.soy.soytree.SwitchCaseNode)2 SwitchDefaultNode (com.google.template.soy.soytree.SwitchDefaultNode)2 Supplier (com.google.common.base.Supplier)1 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)1