Package com.google.caja.parser.js

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


        obj, "props",
        mapToJsArray(
            data.properties,
            new Function<CssPropBit, Expression>() {
              public Expression apply(CssPropBit bit) {
                return new Reference(new Identifier(unk, bit.name()));
              }
            }),
        ignoreKeys);
    appendIfNotEmptyOrIgnored(
        obj, "fns",
View Full Code Here


  private static Statement export(String key, Expression e) {
    FilePosition unk = FilePosition.UNKNOWN;
    // The html4[@k] assignment is an explicit export for Closure Compiler
    return (Statement) QuasiBuilder.substV(
            "{ html4.@i = @e; html4[@k] = html4.@i; }",
            "i", new Reference(new Identifier(unk, key)),
            "k", new StringLiteral(unk, key),
            "e", e);
  }
View Full Code Here

      keys.add(new StringLiteral(unk, quoted));
      values.add(new IntegerLiteral(unk, valueMaker.apply(e)));
    }
    return export(key, (Expression) QuasiBuilder.substV(
        "({ @k*: @v* })",
        "i", new Reference(new Identifier(unk, key)),
        "k", new ParseTreeNodeContainer(keys),
        "v", new ParseTreeNodeContainer(values)));
  }
View Full Code Here

        // TODO(mikesamuel): choose a guaranteed non-interfering name.
        String name = "$_$__litpool__" + decls.size() + "$_$";
        decls.add(new Declaration(
            pos, new Identifier(pos, name), v.uses.get(0).node));
        for (AncestorChain<Literal> use : v.uses) {
          Reference ref = new Reference(
              new Identifier(use.node.getFilePosition(), name));
          use.parent.cast(MutableParseTreeNode.class).node
              .replaceChild(ref, use.node);
        }
      }
View Full Code Here

  private int longestKeyLength = 0;

  private static final FilePosition UNK = FilePosition.UNKNOWN;

  public ParseTreeKB() {
    addFactInt(new Reference(new Identifier(UNK, "undefined")), Fact.UNDEFINED);
    addFactInt(new Reference(new Identifier(UNK, "this")), Fact.GLOBAL);
  }
View Full Code Here

      boolean throwsOnUndefined, Result out) {
    StringBuilder sb = new StringBuilder();
    sb.append('(');
    Expression obj = ma.children().get(0);
    optimize(s, obj, false, false, false, false, out);
    Reference prop = (Reference) ma.children().get(1);
    if (out.node != obj) {
      ma = Operation.createInfix(
          Operator.MEMBER_ACCESS, (Expression) out.node, prop);
    }
    sb = addDigest(out.digest, sb);
    int objDigestEnd = sb != null ? sb.length() : -1;
    if (sb != null) {
      nodeDigest(ma.children().get(1), sb);
      nodeTail(ma, sb);
    }
    String digest = sb != null ? sb.toString() : null;
    out.node = ma;
    out.digest = digest;
    if (digest != null) {
      if (!isLhs) {
        Fact f = getFact(digest);
        if (f != null && f.isSubstitutable(isFuzzy)) {
          out.node = f.value.clone();
          out.digest = nodeDigest(out.node);
          return;
        }
      }
      // window.addEventListener -> addEventListener
      String objDigest = digest.substring(1, objDigestEnd);
      Pair<Expression, Fact> objFe = facts.get(objDigest);
      if (objFe != null && objFe.b.isGlobal()
          && s.isOuter(prop.getIdentifierName())) {
        String propDigest = nodeDigest(prop);
        boolean canSimplify = false;
        if (isLhs || throwsOnUndefined) {
          // If it's being set, we don't need to worry about undefined global
          // errors, and we don't need to worry if the containing expression
View Full Code Here

  }

  private static Expression withTopRef(Expression e, String lhs) {
    if (e instanceof Reference) {
      return Operation.createInfix(
          Operator.MEMBER_ACCESS, new Reference(new Identifier(UNK, lhs)), e);
    } else {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      return Operation.create(
          e.getFilePosition(), op.getOperator(),
View Full Code Here

                  pos, xoper, xoperands.get(0),
                  optimizeExpressionFlow(
                      Operation.createTernary(
                          c, xoperands.get(1), yoperands.get(1))));
            } else {
              Reference xref = (Reference) xoperands.get(1);
              Reference yref = (Reference) yoperands.get(1);
              StringLiteral xname = StringLiteral.valueOf(
                  xref.getFilePosition(), xref.getIdentifierName());
              StringLiteral yname = StringLiteral.valueOf(
                  yref.getFilePosition(), yref.getIdentifierName());
              return Operation.create(
                  pos, Operator.SQUARE_BRACKET,
                  xoperands.get(0),
                  optimizeExpressionFlow(
                       Operation.createTernary(
View Full Code Here

        "id", id));
    return id;
  }

  public Reference declareStartOfScopeTemp() {
    return new Reference(declareStartOfScopeTempVariable());
  }
View Full Code Here

            continue;
          }
        }
        QuasiNode keyQuasi = build(
            keyIdent != null
            ? new Reference(new Identifier(FilePosition.UNKNOWN, keyIdent))
            : key);
        propQuasis.add(new SinglePropertyQuasi(keyQuasi, build(value)));
      } else {
        // TODO: support getters and setters in object quasis
        throw new UnsupportedOperationException(prop.getClass().getName());
View Full Code Here

TOP

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

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.