Package com.google.caja.parser

Examples of com.google.caja.parser.ParseTreeNode


        + "  for (var i = arr.length; i > 0;) {\n"
        + "    if (o === arr[--i]) { return i; }\n"
        + "  }\n"
        + "}"));
    ArrayIndexOptimization.optimize(b);
    ParseTreeNode golden = js(fromString(
        ""
        + "function lastIndexOf(arr, o) {\n"
        + "  for (var i = arr.length; i > 0;) {\n"
        + "    if (o === arr[+(--i)]) { return i; }\n"
        + "  }\n"
View Full Code Here


        ""
        + "function cheating(arr) {\n"
        + "  return arr['length' + 'length'];\n"
        + "}"));
    ArrayIndexOptimization.optimize(b);
    ParseTreeNode golden = js(fromString(
        ""
        + "function cheating(arr) {\n"
        + "  return arr['length' + 'length'];\n"
        + "}"));
    assertEquals(render(golden), render(b));
View Full Code Here

  }

  private void assertNotChangedByOptimizer(String jsSrc) throws Exception {
    Block b = js(fromString(jsSrc));
    ArrayIndexOptimization.optimize(b);
    ParseTreeNode golden = js(fromString(jsSrc));
    assertEquals(render(b), render(golden), render(b));
  }
View Full Code Here

  // Handling of synthetic nodes
  ////////////////////////////////////////////////////////////////////////

  public final void testSyntheticIsUntouched() throws Exception {
    String source = "function foo() { this; arguments; }";
    ParseTreeNode input = js(fromString(source));
    syntheticTree(input);
    checkSucceeds(input, js(fromString("var dis___ = IMPORTS___;" + source)));
  }
View Full Code Here

    syntheticTree(input);
    checkSucceeds(input, js(fromString("var dis___ = IMPORTS___;" + source)));
  }

  public final void testSyntheticMemberAccess() throws Exception {
    ParseTreeNode input = js(fromString("({}).foo"));
    syntheticTree(input);
    checkSucceeds(
        input,
        js(fromString("var dis___ = IMPORTS___; ___.iM([]).foo;")));
  }
View Full Code Here

            reason="")
        public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
          Map<String, ParseTreeNode> m = match(node);

          if (m != null) {
            ParseTreeNode x = m.get("x");
            ParseTreeNode y = m.get("y");

            if (!returnUnexpanded) {
              x = expandAll(x, scope);
              y = expandAll(y, scope);
            }
View Full Code Here

  protected void checkSucceeds(
      ParseTreeNode inputNode,
      ParseTreeNode expectedResultNode,
      MessageLevel highest) {
    mq.getMessages().clear();
    ParseTreeNode actualResultNode = getRewriter().expand(inputNode);
    for (Message m : mq.getMessages()) {
      if (m.getMessageLevel().compareTo(highest) >= 0) {
        fail(m.toString());
      }
    }
View Full Code Here

  }

  private static Expression synth(Expression e) {
    e.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        ParseTreeNode n = chain.node;
        if (n instanceof Identifier) {
          Identifier id = (Identifier) n;
          if (id.getName() != null && id.getName().endsWith("___")) {
            SyntheticNodes.s(id);
          }
View Full Code Here

          UriFetcher.NULL_NETWORK, mq);
      UncajoledModule input = uncajoled(text, name, mq);

      // TODO(felix8a): maybe should use compilation pipeline
      ArrayIndexOptimization.optimize(input);
      ParseTreeNode result = new ExpressionSanitizerCaja(mgr, null)
          .sanitize(input);

      if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
        throw new BuildException("Failed to cajole " + name);
      }
View Full Code Here

    private UncajoledModule uncajoled(
        String text, String name, MessageQueue mq)
    {
      String imaginaryUri = "precajole:///" + name;
      try {
        ParseTreeNode node = new ParserContext(mq)
            .withInput(ContentType.JS)
            .withInput(CharProducer.Factory.create(
                new StringReader(text),
                new com.google.caja.lexer.InputSource(new URI(imaginaryUri))))
            .build();
View Full Code Here

TOP

Related Classes of com.google.caja.parser.ParseTreeNode

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.