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);
}
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);
}
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);
}
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);
}
Aggregations