Search in sources :

Example 61 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class MinFunction method computeForJsSrc.

@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
    JsExpr arg0 = args.get(0);
    JsExpr arg1 = args.get(1);
    return new JsExpr("Math.min(" + arg0.getText() + ", " + arg1.getText() + ")", Integer.MAX_VALUE);
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr)

Example 62 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class IsNonnullFunction method computeForJsSrc.

@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
    JsExpr arg = args.get(0);
    JsExpr nullJsExpr = new JsExpr("null", Integer.MAX_VALUE);
    // Note: In JavaScript, "x != null" is equivalent to "x !== undefined && x !== null".
    return SoyJsPluginUtils.genJsExprUsingSoySyntax(Operator.NOT_EQUAL, Lists.<JsExpr>newArrayList(arg, nullJsExpr));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr)

Example 63 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class V1JsExprTranslatorTest method runTestHelper.

private static void runTestHelper(String soyExpr, String expectedJsExpr) {
    JsExpr actualJsExpr = V1JsExprTranslator.translateToJsExpr(soyExpr, SourceLocation.UNKNOWN, SoyToJsVariableMappings.startingWith(LOCAL_VAR_TRANSLATIONS), ErrorReporter.exploding());
    assertThat(actualJsExpr.getText()).isEqualTo("(" + expectedJsExpr + ")");
    assertThat(actualJsExpr.getPrecedence()).isEqualTo(Integer.MAX_VALUE);
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr)

Example 64 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class VeLogFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    VeLogFunction function = VeLogFunction.INSTANCE;
    JsExpr idExpr = new JsExpr("1", Integer.MAX_VALUE);
    JsExpr dataExpr = new JsExpr("null", Integer.MAX_VALUE);
    assertThat(function.computeForJsSrc(ImmutableList.of(idExpr, dataExpr))).isEqualTo(new JsExpr("soy.velog.$$getLoggingAttribute('1', null, false)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Aggregations

JsExpr (com.google.template.soy.jssrc.restricted.JsExpr)64 Test (org.junit.Test)42 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)3 ImmutableList (com.google.common.collect.ImmutableList)2 RequiresCollector (com.google.template.soy.jssrc.dsl.CodeChunk.RequiresCollector)2 SoyLibraryAssistedJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyLibraryAssistedJsSrcPrintDirective)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 SanitizedContent (com.google.template.soy.data.SanitizedContent)1 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)1 SoyValue (com.google.template.soy.data.SoyValue)1 UnsafeSanitizedContentOrdainer (com.google.template.soy.data.UnsafeSanitizedContentOrdainer)1 SoyString (com.google.template.soy.data.restricted.SoyString)1 StringData (com.google.template.soy.data.restricted.StringData)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 WithValue (com.google.template.soy.jssrc.dsl.CodeChunk.WithValue)1 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)1