Package com.google.caja.parser.js

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


        // Rewriter failed to rewrite so returned its input.
        // There should be details on the message queue.
        it.remove();
        continue;
      }
      CajoledModule validated = (CajoledModule) result;
      it.set(env.withJob(Job.cajoledJob(validated)));

      if (env.cacheKeys.iterator().hasNext()) {
        ArrayConstructor deps = validated.getInlinedModules();
        if (deps != null) {
          for (Expression moduleName : deps.children()) {
            String moduleUri = ((StringLiteral) moduleName).getUnquotedValue();
            JobCache.Keys forUri = keys.get(moduleUri);
            if (forUri == null) {
View Full Code Here


                        CharProducer cp,
                        String jsonpCallback,
                        Appendable output,
                        boolean pretty,
                        MessageQueue mq) {
    CajoledModule cajoledModule = null;
    try {
      Block input = (Block) new ParserContext(mq)
          .withInput(new InputSource(inputUri))
          .withInput(ContentType.JS)
          .withInput(cp)
View Full Code Here

  public boolean apply(Jobs jobs) {
    // Consolidate JS.
    List<JobEnvelope> jsJobs = jobs.getJobsByType(ContentType.JS);
    List<CajoledModule> modules = Lists.newArrayList();
    for (JobEnvelope env : jsJobs) {
      CajoledModule module = (CajoledModule) env.job.getRoot();
      if (module.getSrc() == null) {
        // Is top level.  Not a loaded module from ValidateJavaScriptStage.
        modules.add(module);
      }
    }
    jobs.getJobs().removeAll(jsJobs);
View Full Code Here

    FilePosition unk = FilePosition.UNKNOWN;

    FilePosition pos = bone.body.getFilePosition();
    String sourcePath = mc.abbreviate(pos.source());
    if (bone.source.fromCache) {
      CajoledModule scriptFromCache = (CajoledModule) bone.body;
      finishBlock();
      this.js.add(new SafeJsChunk(bone.source, scriptFromCache));
    } else {
      Block scriptToWrapAndProcess = (Block) bone.body;
      emitStatement(quasiStmt(
View Full Code Here

  }

  private int runOnce(boolean writeFiles) {
    boolean success = false;
    MessageContext mc = null;
    CajoledModule compiledJsOutput = null;
    Node compiledDomOutput = null;
    String compiledHtmlOutput = null;
    File fileLimitAncestor = config.getFetcherBase();

    File jsOutputDest = config.getOutputJsFile();
View Full Code Here

    Element el = (Element) node;
    String tagName = Strings.lower(el.getLocalName());
    if ("script".equals(tagName)) {
      String src = getAttr(el, "src");
      if (src != null && src.length() != 0) {
        CajoledModule pre = precajoleMap.lookupUri(src, minify);
        if (pre != null) {
          replaceScript(jobs, el, pre);
          return true;
        }
      }
View Full Code Here

      throw new SomethingWidgyHappenedError(e);
    }
  };

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

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

    assertTrue(QuasiBuilder.match(
        "  ({"
        + "  instantiate: @instantiate,"
        + "  cajolerName: @cajolerName,"
        + "  cajolerVersion: @cajolerVersion,"
        + "  cajoledDate: @cajoledDate"
        + "})",
        trivialCajoledModule.getModuleBody(),
        bindings));

    assertTrue(bindings.get("instantiate") instanceof FunctionConstructor);

    assertTrue(bindings.get("cajolerName") instanceof StringLiteral);
View Full Code Here

    ObjectConstructor oc = (ObjectConstructor) QuasiBuilder.substV(
        "  ({"
        + "  instantiate: function() {},"
        + "  foo: 42"
        + "})");
    return new CajoledModule(
        FilePosition.UNKNOWN,
        null,
        Arrays.asList(oc));
  }
View Full Code Here

          Job j = env.job;
          if (env.fromCache || j.getType() != ContentType.JS) { continue; }
          if (!(j.getRoot() instanceof CajoledModule)) {
            throw new IllegalStateException("Some content not cajoled");
          }
          CajoledModule m = (CajoledModule) j.getRoot();
          Statement body = m.getInstantiateMethod().getBody();
          it.set(env.withJob(Job.jsJob(body, j.getBaseUri())));
        }
        return true;
      }
    });
View Full Code Here

    boolean failed = !compiler.run();

    if (failed) {
      fail();
    } else {
      CajoledModule jsTree = compiler.getJavascript();
      Node htmlTree = compiler.getStaticHtml();
      String staticHtml = htmlTree != null
          ? Nodes.render(htmlTree, MarkupRenderMode.HTML) : "";
      String js = jsTree != null ? render(jsTree) : "";
View Full Code Here

TOP

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

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.