Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.Expression


  /** "foo bar baz" -> "foo-suffix___ bar-suffix___ baz-suffix___". */
  private Expression rewriteIdentifiers(FilePosition pos, String names) {
    if ("".equals(names)) { return null; }
    JsConcatenator concat = new JsConcatenator();
    rewriteIdentifiers(pos, names, concat);
    Expression result = concat.toExpression(false);
    ((AbstractExpression) result).setFilePosition(pos);
    return result;
  }
View Full Code Here


    ((AbstractExpression) result).setFilePosition(pos);
    return result;
  }
  private void rewriteIdentifiers(
      FilePosition pos, String names, JsConcatenator concat) {
    Expression idClassExpr;
    String idClass = meta.getIdClass();
    if (idClass != null) {
      idClassExpr = StringLiteral.valueOf(FilePosition.UNKNOWN, idClass);
    } else {
      idClassExpr = (Expression) QuasiBuilder.substV(
View Full Code Here

    if (modules.size() == 1) { return modules.get(0); }

    FilePosition unk = FilePosition.UNKNOWN;
    BuildInfo buildInfo = mgr.getBuildInfo();

    Expression moduleInvocations = null;
    for (CajoledModule module : modules) {
      Expression invocation = (Expression) QuasiBuilder.substV(
              "___.prepareModule(@moduleBody).instantiate___(___, IMPORTS___)",
              "moduleBody", module.getModuleBody());
      moduleInvocations = moduleInvocations != null
          ? Operation.createInfix(Operator.COMMA, moduleInvocations, invocation)
          : invocation;
View Full Code Here

   */
  public static Expression rename(
      Expression e, NameContext<String, ?> renamableExterns,
      Set<String> fixedExterns, MessageQueue mq) {
    // Run the rewriter.
    Expression f = (Expression) new AlphaRenamingRewriter(mq, renamableExterns)
        .expand(e);

    // Performs a sanity check on the output by creating a scope that declares
    // locally everything in renamableExterns, and reruns Scope to make sure
    // that now there are no free variables.
View Full Code Here

    for (Attr a : Nodes.attributesOf(el)) {
      if (!scriptsPerNode.containsKey(a)) { continue; }
      AttribKey attrKey = AttribKey.forAttribute(elKey, a);
      // Keep track of whether there is an ID so that we know whether or
      // not to remove any auto-generated ID later.
      Expression dynamicValue = (Expression) scriptsPerNode.get(a);
      if (ID.ns.uri != attrKey.ns.uri
          || !ID.localName.equals(attrKey.localName)) {
        if (dynamicValue == null
            || dynamicValue instanceof StringLiteral) {
          emitStaticAttr(a, (StringLiteral) dynamicValue, safe);
        } else {
          dynId = makeDynamicId(dynId, pos, bone.source);
          String handlerName = dynamicValue.getAttributes().get(
              HtmlAttributeRewriter.HANDLER_NAME);
          if (handlerName != null
              && handlers.containsKey(handlerName)
              && handlersUsedInModule.add(handlerName)) {
            emitHandler(handlerName);
          }
          emitDynamicAttr(a, dynamicValue, bone.source);
        }
      } else {
        // A previous HTML parsing step should have ensured that each element
        // only has one instance of each attribute.
        assert id == null;
        id = a;
      }
    }
    // Output an ID
    if (id != null) {
      Expression dynamicValue = (Expression) scriptsPerNode.get(id);
      if (dynId == null
          && (dynamicValue == null
              || dynamicValue instanceof StringLiteral)) {
        emitStaticAttr(id, (StringLiteral) dynamicValue, safe);
      } else {
View Full Code Here

      mq.addMessage(Messages.NO_PARENT, Nodes.getFilePositionFor(el));
      return el;
    }
    String id = getPlaceholderId(r);
    FilePosition pos = Nodes.getFilePositionFor(el);
    Expression e = (Expression) QuasiBuilder.substV(
        ""
        + "IMPORTS___.htmlEmitter___."
        + "/*@synthetic*/ handleEmbed({"
        + " id: @id,"
        + " src: @src,"
View Full Code Here

    } else {
      className = id + " " + className;
    }
    el.setAttributeNS(HTML_NS, "class", className);
    FilePosition pos = Nodes.getFilePositionFor(el);
    Expression e = (Expression) QuasiBuilder.substV(
        ""
        + "IMPORTS___.htmlEmitter___."
        + "/*@synthetic*/ handleEmbed({"
        + " id: @id })",
        "id", literal(id, pos));
View Full Code Here

      height = params.get("height");
    }

    String id = getPlaceholderId(r);
    FilePosition pos = Nodes.getFilePositionFor(el);
    Expression e = (Expression) QuasiBuilder.substV(
        ""
        + "IMPORTS___.htmlEmitter___."
        + "/*@synthetic*/ handleEmbed({"
        + " id: @id,"
        + " src: @src,"
View Full Code Here

    foldSideEffectsIntoStringPart(true);
    checkThatOneOperandIsStringLike(mustBeString);
    if (parts.isEmpty()) {
      return StringLiteral.valueOf(FilePosition.UNKNOWN, "");
    }
    Expression e = null;
    for (Part p : parts) {
      Expression pe;
      if (p instanceof StringPart) {
        pe = ((StringPart) p).e;
      } else if (p instanceof SideEffectPart) {
        SideEffectPart sep = (SideEffectPart) p;
        FilePosition epos = sep.e.getFilePosition();
View Full Code Here

        SideEffectPart sep = (SideEffectPart) p;
        Part np = i + 1 < parts.size() ? parts.get(i + 1) : null;
        Part pp = i > 0 ? parts.get(i - 1) : null;
        if (np instanceof StringPart
            && (alwaysFold || pp instanceof StringPart)) {
          Expression se = ((StringPart) np).e;
          StringPart combined = new StringPart(Operation.create(
              FilePosition.UNKNOWN, Operator.COMMA, sep.e, se));
          List<Part> both = parts.subList(i, i + 2);
          both.clear();
          both.add(combined);
View Full Code Here

TOP

Related Classes of com.google.caja.parser.js.Expression

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.