public void testDataRef() { assertTranslation("$boo", new JsExpr("opt_data.boo", Integer.MAX_VALUE)); assertTranslation("$boo.goo", new JsExpr("opt_data.boo.goo", Integer.MAX_VALUE)); assertTranslation("$goo", new JsExpr("gooData8", Integer.MAX_VALUE)); assertTranslation("$goo.boo", new JsExpr("gooData8.boo", Integer.MAX_VALUE)); assertTranslation("$boo.0.1.foo.2", new JsExpr("opt_data.boo[0][1].foo[2]", Integer.MAX_VALUE)); assertTranslation("$boo[0].1", new JsExpr("opt_data.boo[0][1]", Integer.MAX_VALUE)); assertTranslation( "$boo[$foo][$goo+1]", new JsExpr("opt_data.boo[opt_data.foo][gooData8 + 1]", Integer.MAX_VALUE)); assertTranslation("$class", new JsExpr("opt_data['class']", Integer.MAX_VALUE)); assertTranslation("$boo.yield", new JsExpr("opt_data.boo['yield']", Integer.MAX_VALUE)); assertTranslation( "$boo?.goo", new JsExpr( "(opt_data.boo == null) ? null : opt_data.boo.goo", Operator.CONDITIONAL.getPrecedence())); assertTranslation( "$goo?.boo", new JsExpr( "(gooData8 == null) ? null : gooData8.boo", Operator.CONDITIONAL.getPrecedence())); assertTranslation( "$boo?[0]?.1", new JsExpr( "(opt_data.boo == null) ? null : (opt_data.boo[0] == null) ? null : opt_data.boo[0][1]", Operator.CONDITIONAL.getPrecedence())); }
@Override public JsExpr computeForJsSrc(List<JsExpr> args) { BidiGlobalDir bidiGlobalDir = bidiGlobalDirProvider.get(); if (bidiGlobalDir.isStaticValue()) { return new JsExpr( (bidiGlobalDir.getStaticValue() < 0) ? "'right'" : "'left'", Integer.MAX_VALUE); } return new JsExpr( "(" + bidiGlobalDir.getCodeSnippet() + ") < 0 ? 'right' : 'left'", Operator.CONDITIONAL.getPrecedence()); }
public void testBlocks() { String soyNodeCode = "{if $boo}\n" + " Blah {$boo} bleh.\n" + "{/if}\n"; String expectedJsExprText = "(opt_data.boo) ? 'Blah ' + opt_data.boo + ' bleh.' : ''"; assertGeneratedJsExprs( soyNodeCode, ImmutableList.of(new JsExpr(expectedJsExprText, Operator.CONDITIONAL.getPrecedence()))); soyNodeCode = "{call some.func}" + " {param goo}{lb}{index($goo)}{rb} is {$goo.moo}{/param}" + "{/call}"; expectedJsExprText = "some.func({goo: '{' + gooIndex8 + '} is ' + gooData8.moo})"; assertGeneratedJsExprs( soyNodeCode, ImmutableList.of(new JsExpr(expectedJsExprText, Integer.MAX_VALUE))); }
public void testIf() { String soyNodeCode = "{if $boo}\n" + " Blah\n" + "{elseif not isFirst($goo)}\n" + " Bleh\n" + "{else}\n" + " Bluh\n" + "{/if}\n"; String expectedJsExprText = "(opt_data.boo) ? 'Blah' : (! (gooIndex8 == 0)) ? 'Bleh' : 'Bluh'"; assertGeneratedJsExprs( soyNodeCode, ImmutableList.of(new JsExpr(expectedJsExprText, Operator.CONDITIONAL.getPrecedence()))); }