Package com.google.template.soy.jssrc.restricted

Examples of com.google.template.soy.jssrc.restricted.JsExpr


      // For 'stringbuilder' code style, pass the current output var to collect the call's output.
      genCallCodeUtils.genAndAppendCallStmt(jsCodeBuilder, node, localVarTranslations);

    } else {
      // For 'concat' code style, we simply add the call's result to the current output var.
      JsExpr callExpr = genCallCodeUtils.genCallExpr(node, localVarTranslations);
      jsCodeBuilder.addToOutputVar(ImmutableList.of(callExpr));
    }
  }
View Full Code Here


   */
  @Override protected void visitLogNode(LogNode node) {

    if (isComputableAsJsExprsVisitor.execOnChildren(node)) {
      List<JsExpr> logMsgJsExprs = genJsExprsVisitor.execOnChildren(node);
      JsExpr logMsgJsExpr = JsExprUtils.concatJsExprs(logMsgJsExprs);
      jsCodeBuilder.appendLine("window.console.log(", logMsgJsExpr.getText(), ");");

    } else {
      // Must build log msg in a local var logMsg_s##.
      localVarTranslations.push(Maps.<String, JsExpr>newHashMap());
      jsCodeBuilder.pushOutputVar("logMsg_s" + node.getId());
View Full Code Here

                   commaSeparatedJsExprsSb.toString(), ");");
        setOutputVarInited();
      }

    } else // CodeStyle.CONCAT
      JsExpr concatenatedJsExprs = JsExprUtils.concatJsExprs(jsExprs);

      if (currOutputVarIsInited) {
        // output += AAA + BBB + CCC;
        appendLine(currOutputVarName, " += ", concatenatedJsExprs.getText(), ";");
      } else {
        // var output = AAA + BBB + CCC;
        appendLine("var ", currOutputVarName, " = ", concatenatedJsExprs.getText(), ";");
        setOutputVarInited();
      }
    }
  }
View Full Code Here

    // Note: There is a JavaScript language quirk that requires all Unicode Foramt characters
    // (Unicode category "Cf") to be escaped in JS strings. Therefore, we call
    // JsSrcUtils.escapeUnicodeFormatChars() on the expression text in case it contains JS strings.
    jsExprText = JsSrcUtils.escapeUnicodeFormatChars(jsExprText);
    int jsExprPrec = guessJsExprPrecedence(jsExprText);
    return new JsExpr(jsExprText, jsExprPrec);
  }
View Full Code Here

   */
  private static String getLocalVarTranslation(
      String ident, Deque<Map<String, JsExpr>> localVarTranslations) {

    for (Map<String, JsExpr> localVarTranslationsFrame : localVarTranslations) {
      JsExpr translation = localVarTranslationsFrame.get(ident);
      if (translation != null) {
        if (translation.getPrecedence() != Integer.MAX_VALUE) {
          return "(" + translation.getText() + ")";
        } else {
          return translation.getText();
        }
      }
    }

    return null;
View Full Code Here

  public void testComputeForJsSrc() {

    RoundFunction roundFunction = new RoundFunction();

    JsExpr floatExpr = new JsExpr("FLOAT_JS_CODE", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.round(FLOAT_JS_CODE)", Integer.MAX_VALUE),
                 roundFunction.computeForJsSrc(ImmutableList.of(floatExpr)));

    JsExpr numDigitsAfterPtExpr = new JsExpr("0", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.round(FLOAT_JS_CODE)", Integer.MAX_VALUE),
                 roundFunction.computeForJsSrc(
                     ImmutableList.of(floatExpr, numDigitsAfterPtExpr)));

    numDigitsAfterPtExpr = new JsExpr("4", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.round(FLOAT_JS_CODE * 10000) / 10000",
                            Operator.DIVIDE_BY.getPrecedence()),
                 roundFunction.computeForJsSrc(
                     ImmutableList.of(floatExpr, numDigitsAfterPtExpr)));

    numDigitsAfterPtExpr = new JsExpr("-2", Operator.NEGATIVE.getPrecedence());
    assertEquals(new JsExpr("Math.round(FLOAT_JS_CODE / 100) * 100",
                            Operator.TIMES.getPrecedence()),
                 roundFunction.computeForJsSrc(
                     ImmutableList.of(floatExpr, numDigitsAfterPtExpr)));

    numDigitsAfterPtExpr = new JsExpr("NUM_DIGITS_JS_CODE", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.round(FLOAT_JS_CODE * Math.pow(10, NUM_DIGITS_JS_CODE)) /" +
                            " Math.pow(10, NUM_DIGITS_JS_CODE)",
                            Operator.DIVIDE_BY.getPrecedence()),
                 roundFunction.computeForJsSrc(
                     ImmutableList.of(floatExpr, numDigitsAfterPtExpr)));
  }
View Full Code Here


  public void testComputeForJsSrc() {

    FloorFunction floorFunction = new FloorFunction();
    JsExpr expr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.floor(JS_CODE)", Integer.MAX_VALUE),
                 floorFunction.computeForJsSrc(ImmutableList.of(expr)));
  }
View Full Code Here


  public void testComputeForJsSrc() {

    MaxFunction maxFunction = new MaxFunction();
    JsExpr expr0 = new JsExpr("JS_CODE_0", Integer.MAX_VALUE);
    JsExpr expr1 = new JsExpr("JS_CODE_1", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.max(JS_CODE_0, JS_CODE_1)", Integer.MAX_VALUE),
                 maxFunction.computeForJsSrc(ImmutableList.of(expr0, expr1)));
  }
View Full Code Here


  public void testComputeForJsSrc() {

    LengthFunction lengthFunction = new LengthFunction();
    JsExpr expr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertEquals(new JsExpr("JS_CODE.length", Integer.MAX_VALUE),
                 lengthFunction.computeForJsSrc(ImmutableList.of(expr)));
  }
View Full Code Here


  public void testComputeForJsSrc() {

    CeilingFunction ceilingFunction = new CeilingFunction();
    JsExpr expr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertEquals(new JsExpr("Math.ceil(JS_CODE)", Integer.MAX_VALUE),
                 ceilingFunction.computeForJsSrc(ImmutableList.of(expr)));
  }
View Full Code Here

TOP

Related Classes of com.google.template.soy.jssrc.restricted.JsExpr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.