Examples of JsExpr


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

    return augmentedMap;
  }


  @Override public JsExpr computeForJsSrc(List<JsExpr> args) {
    JsExpr arg0 = args.get(0);
    JsExpr arg1 = args.get(1);

    String exprText = "soy.$$augmentMap(" + arg0.getText() + ", " + arg1.getText() + ")";
    return new JsExpr(exprText, Integer.MAX_VALUE);
  }
View Full Code Here

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

    // Note: StringNode.toSourceString() produces a Soy string, which is usually a valid JS string.
    // The rare exception is a string containing a Unicode Format character (Unicode category "Cf")
    // because of the JavaScript language quirk that requires all category "Cf" characters to be
    // escaped in JS strings. Therefore, we must call JsSrcUtils.escapeUnicodeFormatChars() on the
    // result.
    return new JsExpr(
        JsSrcUtils.escapeUnicodeFormatChars(node.toSourceString()),
        Integer.MAX_VALUE);
  }
View Full Code Here

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

    // primitives, the result is usually also the correct JS expression.
    // Note: The rare exception to the above note is a StringNode containing a Unicode Format
    // character (Unicode category "Cf") because of the JavaScript language quirk that requires all
    // category "Cf" characters to be escaped in JS strings. Therefore, we have a separate
    // implementation above for visitStringNode(StringNode).
    return new JsExpr(node.toSourceString(), Integer.MAX_VALUE);
  }
View Full Code Here

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

      exprTextSb.append(visit(child).getText());
    }

    exprTextSb.append(']');

    return new JsExpr(exprTextSb.toString(), Integer.MAX_VALUE);
  }
View Full Code Here

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

    } else {
      fullExprText = "(function() { var map_s = {" + strKeysEntriesSnippet.toString() + "};" +
          nonstrKeysEntriesSnippet.toString() + " return map_s; })()";
    }

    return new JsExpr(fullExprText, Integer.MAX_VALUE);
  }
View Full Code Here

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

      refText = "opt_ijData" + genCodeForKeyAccess(firstKey);
      if (node.isNullSafeIjDataRef()) {
        nullSafetyPrefix = "(opt_ijData == null) ? null : ";
      }
    } else {
      JsExpr translation = getLocalVarTranslation(firstKey);
      if (translation != null) {
        // Case 2: In-scope local var.
        refText = translation.getText();
      } else {
        // Case 3: Data reference.
        refText = "opt_data" + genCodeForKeyAccess(firstKey);
      }
    }

    // ------ Translate the rest of the keys, if any. ------
    for (ExprNode child : node.getChildren()) {
      DataRefAccessNode accessNode = (DataRefAccessNode) child;

      if (accessNode.isNullSafe()) {
        // Note: In JavaScript, "x == null" is equivalent to "x === undefined || x === null".
        nullSafetyPrefix += "(" + refText + " == null) ? null : ";
      }

      switch (accessNode.getKind()) {
        case DATA_REF_ACCESS_KEY_NODE:
          refText += genCodeForKeyAccess(((DataRefAccessKeyNode) accessNode).getKey());
          break;
        case DATA_REF_ACCESS_INDEX_NODE:
          refText += "[" + ((DataRefAccessIndexNode) accessNode).getIndex() + "]";
          break;
        case DATA_REF_ACCESS_EXPR_NODE:
          JsExpr keyJsExpr = visit(accessNode.getChild(0));
          refText += "[" + keyJsExpr.getText() + "]";
          break;
        default:
          throw new AssertionError();
      }
    }

    if (nullSafetyPrefix.length() == 0) {
      return new JsExpr(refText, Integer.MAX_VALUE);
    } else {
      return new JsExpr(nullSafetyPrefix + refText, Operator.CONDITIONAL.getPrecedence());
    }
  }
View Full Code Here

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

      "private", "protected", "public", "return", "static", "super", "switch", "this", "throw",
      "true", "try", "typeof", "var", "void", "while", "with", "yield");


  @Override protected JsExpr visitGlobalNode(GlobalNode node) {
    return new JsExpr(node.toSourceString(), Integer.MAX_VALUE);
  }
View Full Code Here

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

   * @return The translated expression for the given variable, or null if not found.
   */
  private JsExpr getLocalVarTranslation(String ident) {

    for (Map<String, JsExpr> localVarTranslationsFrame : localVarTranslations) {
      JsExpr translation = localVarTranslationsFrame.get(ident);
      if (translation != null) {
        return translation;
      }
    }

View Full Code Here

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

    return toSoyData(strArg0.contains(strArg1));
  }


  @Override public JsExpr computeForJsSrc(List<JsExpr> args) {
    JsExpr arg0 = args.get(0);
    JsExpr arg1 = args.get(1);

    String arg0Text = arg0.getPrecedence() == Integer.MAX_VALUE
        ? arg0.getText() : "(" + arg0.getText() + ")";
    String arg1Text = arg1.getText();

    String exprText = arg0Text + ".indexOf(" + arg1Text + ") != -1";

    return new JsExpr(exprText, Operator.NOT_EQUAL.getPrecedence());
  }
View Full Code Here

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

    return toSoyData((int) Math.floor(Math.random() * arg.integerValue()));
  }


  @Override public JsExpr computeForJsSrc(List<JsExpr> args) {
    JsExpr arg = args.get(0);

    JsExpr random = new JsExpr("Math.random()", Integer.MAX_VALUE);
    JsExpr randomTimesArg =
        SoyJsCodeUtils.genJsExprUsingSoySyntax(Operator.TIMES, Lists.newArrayList(random, arg));
    return new JsExpr("Math.floor(" + randomTimesArg.getText() + ")", Integer.MAX_VALUE);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.