Package com.google.caja.parser.js

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


      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


      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

        freeSynthetics.add(global);
      } else {
        nc.declare(global, FilePosition.startOfFile(is));
      }
    }
    Expression renamed = AlphaRenaming.rename(
        synth(jsExpr(fromString(input))), nc, freeSynthetics, mq);
    assertEquals(render(jsExpr(fromString(golden))), render(renamed));
  }
View Full Code Here

                  = rw.sanitizeStringValue(HtmlAttributeRewriter.fromAttr(
                      classAttr, htmlSchema.lookupAttribute(BODY_CLASS),
                      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___"
View Full Code Here

    for (ValidatedStylesheet ss : validatedStylesheets) {
      ArrayConstructor ac = CssDynamicExpressionRewriter.cssToJs(ss.ss);
      List<? extends Expression> children = ac.children();
      if (children.isEmpty()) { continue; }
      FilePosition acPos = ac.getFilePosition();
      Expression child0 = children.get(0);
      // The CssDynamicExpressionRewriter gets to distinguish between static and
      // dynamic. If the output is a single string, then joining it on the
      // idClass would not add any information, so we can put it in the static
      // HTML.
      if (children.size() == 1 && child0 instanceof StringLiteral) {
        css.append('\n').append(((StringLiteral) child0).getUnquotedValue());
        staticPos = staticPos == null
            ? acPos : FilePosition.span(staticPos, acPos);
      } else {
        // Don't just push all onto the list since that would create an
        // extra, spurious separator after they're joined.
        // To avoid the spurious separator, we concatenate the last item
        // already on cssParts with child0.
        int n = cssParts.size();
        if (n == 0) {
          cssParts.addAll(children);
        } else {
          JsConcatenator cat = new JsConcatenator();
          cat.append(cssParts.get(n - 1));
          cat.append(FilePosition.startOf(child0.getFilePosition()), "\n");
          cat.append(child0);
          cssParts.set(n - 1, cat.toExpression(false));
          cssParts.addAll(children.subList(1, children.size()));
        }
        dynamicPos = dynamicPos == null
View Full Code Here

            && !(node instanceof FunctionDeclaration)) {
          if (chain.parent.node instanceof CatchStmt) { return true; }
          Declaration decl = (Declaration) node;
          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);
View Full Code Here

        } else {
          break;
        }
      }
      if (!(first instanceof ExpressionStmt)) { break; }
      Expression e = ((ExpressionStmt) first).getExpression();
      if (!Operation.is(e, Operator.ASSIGN)) { break; }
      Operation op = (Operation) e;
      Expression lhs = op.children().get(0);
      if (!(lhs instanceof Reference)) { break; }
      Reference r = (Reference) lhs;
      if (!unassigned.contains(r.getIdentifier())) { break; }
      // Don't return two with the same name, because we don't want to have
      // multiple var declarations for the same name.
View Full Code Here

      new PrintWriter(System.err), new MessageContext(), true);
  static String normJs(String js, MessageQueue mq) throws ParseException {
    JsLexer lexer = new JsLexer(
        CharProducer.Factory.fromString(js, FilePosition.UNKNOWN));
    JsTokenQueue tq = new JsTokenQueue(lexer, InputSource.UNKNOWN);
    Expression e = new Parser(tq, mq).parseExpression(true);
    tq.expectEmpty();
    StringBuilder sb = new StringBuilder(js.length() + 16);
    RenderContext rc = new RenderContext(new JsMinimalPrinter(sb));
    e.render(rc);
    rc.getOut().noMoreTokens();
    return sb.toString();
  }
View Full Code Here

      this.result = result;
    }
  }

  public SanitizedAttr sanitizeStringValue(AttrValue attr) {
    Expression dynamicValue = null;
    FilePosition pos = attr.valuePos;
    String value = attr.getPlainValue();
    // There are two cases for name handling.
    // 1. For names that have local scope or names that can't be mangled,
    //    we pass them through unchanged, except we deny the '__' suffix
View Full Code Here

    // a value equal to the empty string, which Domado's rewriteTargetAttribute
    // interprets to mean that the guest code did not supply a value.
    FilePosition pos = attr.valuePos;
    boolean unspecified = null !=
        attr.src.getUserData(TemplateCompiler.ATTRIBUTE_VALUE_WAS_UNSPECIFIED);
    Expression value = unspecified
        ? new NullLiteral(pos)
        : new StringLiteral(pos, attr.src.getValue());
    return (Expression) QuasiBuilder.substV(""
        + "IMPORTS___./*@synthetic*/rewriteTargetAttribute___("
        + "    @value, @tagName, @attribName)",
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.