Package com.google.caja.parser.js

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


        + " width: @width })",
        "id", literal(id, pos),
        "src", literal(src, pos),
        "height", literal(height, pos),
        "width", literal(width, pos));
    embedder.appendChild(new ExpressionStmt(e));
    return r;
  }
View Full Code Here


        // TODO(felix8a): need to add params and attrs
        "id", literal(id, pos),
        "src", literal(src, pos),
        "height", literal(height, pos),
        "width", literal(width, pos));
    embedder.appendChild(new ExpressionStmt(e));
    return r;
  }
View Full Code Here

  private static Statement makeEmitStaticStmt(Node node) {
    return (Statement) QuasiBuilder.substV(
        "'use strict'; @stmt;",
        "stmt", new TranslatedCode(new Block(
            FilePosition.UNKNOWN,
            Collections.singletonList(new ExpressionStmt(
                (Expression) QuasiBuilder.substV(
                    "IMPORTS___./*@synthetic*/htmlEmitter___"
                        + "./*@synthetic*/emitStatic(@html)",
                    "html", renderDomAsJsStringLiteral(node)))))));
  }
View Full Code Here

  }

  private static void fillOperands(
      Operator op, int operandIdx, Reference[] operands, List<Statement> out) {
    if (operandIdx == operands.length) {
      out.add(new ExpressionStmt(
          FilePosition.UNKNOWN,
          (Expression) QuasiBuilder.substV(
              "requireArrayMember(function () { return @e; });",
              "e", Operation.create(FilePosition.UNKNOWN, op, operands))));
      return;
View Full Code Here

                      source));
              if (sanitized.isSafe) {
                FilePosition pos = Nodes.getFilePositionForValue(classAttr);
                Expression e = sanitized.result;
                if (e == null) { e = StringLiteral.valueOf(pos, identifiers); }
                Statement s = new ExpressionStmt(
                    (Expression) QuasiBuilder.substV(
                         ""
                        + "IMPORTS___.htmlEmitter___"
                        + "    ./*@synthetic*/addBodyClasses(@idents);",
                        "idents", e));
View Full Code Here

        dynamicPos = dynamicPos == null
            ? acPos : FilePosition.span(dynamicPos, acPos);
      }
    }

    ExpressionStmt dynamicCss = null;
    Element staticCss = null;
    // Emit any dynamic CSS.
    if (!cssParts.isEmpty()) {
      // The CSS rule
      //     p { color: purple }
      // is converted to the JavaScript
      //     IMPORTS___.emitCss___(
      //         ['.', ' p { color: purple }']
      //         .join(IMPORTS___.getIdClass___()));
      //
      // If IMPORTS___.getIdClass() returns "g123___", then the resulting
      //     .g123___ p { color: purple }
      // will only make purple paragraphs that are under a node with class
      // g123__.
      dynamicCss = new ExpressionStmt(
          dynamicPos,
          (Expression) QuasiBuilder.substV(
              ReservedNames.IMPORTS
              + ".emitCss___(@cssParts./*@synthetic*/join("
              + ReservedNames.IMPORTS + ".getIdClass___()))",
View Full Code Here

          Identifier id = decl.getIdentifier();
          removedIdents.add(id);
          Expression init = decl.getInitializer();
          Statement replacement;
          if (init != null) {
            replacement = new ExpressionStmt(toAssignment(decl));
          } else if (chain.parent.node instanceof ForEachLoop) {
            replacement = new ExpressionStmt(new Reference(id));
          } else {
            replacement = new Noop(decl.getFilePosition());
          }
          changes.add(Pair.pair(chain.cast(Statement.class), replacement));
          return true;
        } else if (node instanceof MultiDeclaration) {
          List<Expression> replacements = Lists.newArrayList();
          for (Declaration decl : ((MultiDeclaration) node).children()) {
            removedIdents.add(decl.getIdentifier());
            if (decl.getInitializer() == null) { continue; }
            visit(chain.child(decl).child(decl.getInitializer()));
            Expression assign = toAssignment(decl);
            replacements.add(assign);
          }
          Statement replacement;
          if (replacements.isEmpty()) {
            replacement = new Noop(node.getFilePosition());
          } else if (replacements.size() == 1) {
            Expression e = replacements.get(0);
            replacement = new ExpressionStmt(e.getFilePosition(), e);
          } else if (chain.parent.node instanceof Block) {
            List<Statement> stmts = Lists.newArrayList();
            for (Expression e : replacements) {
              stmts.add(new ExpressionStmt(e));
            }
            replacement = new Block(node.getFilePosition(), stmts);
          } else {
            Expression combo = null;
            for (Expression e : replacements) {
              combo = combo == null
                  ? e : Operation.createInfix(Operator.COMMA, combo, e);
            }
            replacement = new ExpressionStmt(node.getFilePosition(), combo);
          }
          changes.add(Pair.pair(chain.cast(Statement.class), replacement));
          return false;
        } else if (node instanceof FunctionConstructor) {
          inners.add((FunctionConstructor) node);
View Full Code Here

    // looks like { (function (a, b) { @rewrittenExpression; }; }
    Block program = (Block) QuasiBuilder.substV(
        "{ (function (@formals*) { @f; }); }",
        "formals", new ParseTreeNodeContainer(
            Lists.newArrayList(rewrittenNames.values())),
        "f", new ExpressionStmt(f));
    MessageQueue sanityCheckMq = DevNullMessageQueue.singleton();
    Set<String> freeIdents = Sets.newLinkedHashSet();
    Scope programScope = Scope.fromProgram(
        program,
        new Rewriter(sanityCheckMq, false, false));
View Full Code Here

public final class QuasiUtil {
  public static Statement quasiStmt(String quasi, Object... args) {
    ParseTreeNode n = QuasiBuilder.substV(quasi, args);
    if (n instanceof Expression) {
      return new ExpressionStmt(FilePosition.UNKNOWN, (Expression) n);
    }
    return (Statement) n;
  }
View Full Code Here

        + " width: @width })",
        "id", literal(id, pos),
        "src", literal(src, pos),
        "height", literal(height, pos),
        "width", literal(width, pos));
    embedder.appendChild(new ExpressionStmt(e));
    return r;
  }
View Full Code Here

TOP

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

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.