Package com.google.caja.parser.js

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


  public ParseTreeNode sanitize(ParseTreeNode input) {
    MessageQueue mq = mgr.getMessageQueue();
    ParseTreeNode result = null;
    if (input instanceof UncajoledModule) {
      Block body = ((UncajoledModule) input).getModuleBody();
      if (body.children().size() == 2
          && body.children().get(0) instanceof DirectivePrologue
          && ((DirectivePrologue) body.children().get(0))
              .hasDirective("use strict")
          && body.children().get(1) instanceof TranslatedCode) {
        result = input;
      }
    }
    result = newES53Rewriter(mgr).expand(input);
    if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
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)",
 
View Full Code Here

    }
  };

  public final void testCajoledModuleContents() {
    CajoledModule trivialCajoledModule = (CajoledModule) makeRewriter().expand(
        new UncajoledModule(new Block()));
    assertNoErrors();

    Map<String, ParseTreeNode> bindings = Maps.newHashMap();

    assertTrue(QuasiBuilder.match(
View Full Code Here

  }

  private void assertOptimized(String golden, String input)
      throws ParseException {
    Block prog = js(fromString(input));
    assertEquals(render(js(fromString(golden))),
                 render(ConstantPooler.optimize(prog)));
  }
View Full Code Here

    Statement optimized = opt.optimize();
    assertEquals(renderProgram(golden), renderProgram(optimized));
  }

  private static Block emptyProgram() {
    return new Block(FilePosition.UNKNOWN, Collections.<Statement>emptyList());
  }
View Full Code Here

    return render(jsExpr(fromString(code)));
  }

  private void assertSimplified(List<String> expected, List<String> input)
      throws ParseException {
    Block expectedStmt = js(fromString(Join.join("\n", expected)));
    Statement inputStmt = js(fromString(Join.join("\n", input)));
    ParseTreeNode optimized = StatementSimplifier.optimize(inputStmt, mq);
    assertEquals(renderBody(expectedStmt), renderStmt((Statement) optimized));
  }
View Full Code Here

        + "}");
  }

  private void assertOptimized(String golden, String input)
      throws ParseException {
    Block program = js(fromString(input));
    VarCollector.optimize(program);
    assertEquals(render(js(fromString(golden))), render(program));
  }
View Full Code Here

                + "  return g;"
                + "}")))));
  }

  public final void testIdentityOfOutput() throws Exception {
    Block canOptimize = js(fromString(
        ""
        + "function f() {"
        + "  var x = true;"
        + "  return x;"
        + "}"));
    Block cannotOptimize = js(fromString(
        ""
        + "function f() {"
        + "  return true;"
        + "}"));
    assertSame(cannotOptimize, ConstLocalOptimization.optimize(cannotOptimize));
    Block optimized = ConstLocalOptimization.optimize(canOptimize);
    assertEquals(render(cannotOptimize), render(optimized));
    assertFalse(canOptimize == optimized);
    assertSame(optimized, ConstLocalOptimization.optimize(optimized));
  }
View Full Code Here

  public final void testEmptyModule() throws Exception {
    assertSafeHtml(
        htmlFragment(fromString("")),
        htmlFragment(fromString("")),
        new Block());
  }
View Full Code Here

  public final void testTopLevelTextNodes() throws Exception {
    assertSafeHtml(
        htmlFragment(fromString("Hello, <b title=howdy>World</b>!!!")),
        htmlFragment(fromString("Hello, <b title=howdy>World</b>!!!")),
        new Block());
  }
View Full Code Here

TOP

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

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.