Search in sources :

Example 21 with VarRefNode

use of com.google.template.soy.exprtree.VarRefNode in project closure-templates by google.

the class ResolveNamesVisitorTest method testMultipleLocals.

@Test
public void testMultipleLocals() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $la: 1 /}", "{let $lb: $la /}", "{let $lc: $lb /}")).parse().fileSet();
    new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
    TemplateNode n = soyTree.getChild(0).getChild(0);
    // 3 because each new $la binding is a 'new variable'
    assertThat(n.getMaxLocalVariableTableSize()).isEqualTo(3);
    LetValueNode firstLet = (LetValueNode) n.getChild(0);
    LetValueNode secondLet = (LetValueNode) n.getChild(1);
    LetValueNode thirdLet = (LetValueNode) n.getChild(2);
    assertThat(firstLet.getVar().localVariableIndex()).isEqualTo(0);
    assertThat(secondLet.getVar().localVariableIndex()).isEqualTo(1);
    assertThat(thirdLet.getVar().localVariableIndex()).isEqualTo(2);
    assertThat(((VarRefNode) secondLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(firstLet.getVar());
    assertThat(((VarRefNode) thirdLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(secondLet.getVar());
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) LetValueNode(com.google.template.soy.soytree.LetValueNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 22 with VarRefNode

use of com.google.template.soy.exprtree.VarRefNode in project closure-templates by google.

the class ResolveNamesVisitorTest method testLetReferencedInsideAttributeValue.

@Test
public void testLetReferencedInsideAttributeValue() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $t: 1 /}<{$t}>")).parse().fileSet();
    TemplateNode n = soyTree.getChild(0).getChild(0);
    VarRefNode node = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(n, VarRefNode.class));
    assertThat(node.getDefnDecl().kind()).isEqualTo(VarDefn.Kind.LOCAL_VAR);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Aggregations

VarRefNode (com.google.template.soy.exprtree.VarRefNode)22 Test (org.junit.Test)9 SourceLocation (com.google.template.soy.base.SourceLocation)5 ExprNode (com.google.template.soy.exprtree.ExprNode)4 FieldAccessNode (com.google.template.soy.exprtree.FieldAccessNode)4 IntegerNode (com.google.template.soy.exprtree.IntegerNode)4 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)4 SoyDataException (com.google.template.soy.data.SoyDataException)3 PrintNode (com.google.template.soy.soytree.PrintNode)3 TemplateNode (com.google.template.soy.soytree.TemplateNode)3 LoopVar (com.google.template.soy.soytree.defn.LoopVar)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 ParentExprNode (com.google.template.soy.exprtree.ExprNode.ParentExprNode)2 FunctionNode (com.google.template.soy.exprtree.FunctionNode)2 GlobalNode (com.google.template.soy.exprtree.GlobalNode)2 ItemAccessNode (com.google.template.soy.exprtree.ItemAccessNode)2 StringNode (com.google.template.soy.exprtree.StringNode)2 IfCondNode (com.google.template.soy.soytree.IfCondNode)2 IfNode (com.google.template.soy.soytree.IfNode)2