Uri contextUri = req.getUri();
InputSource is = new InputSource(contextUri.toJavaUri());
PluginMeta pluginMeta = new PluginMeta(
proxyFetcher(req, contextUri), proxyUriPolicy(req));
PluginCompiler compiler = new PluginCompiler(BuildInfo.getInstance(),
pluginMeta, mq);
compiler.setMessageContext(mc);
// Parse the javascript
try {
StringReader strReader = new StringReader(resp.getContent());
CharProducer cp = CharProducer.Factory.create(strReader, is);
JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), is);
ParseTreeNode input = new Parser(tq, mq).parse();
tq.expectEmpty();
compiler.addInput(AncestorChain.instance(input).node, contextUri.toJavaUri());
} catch (ParseException e) {
// Don't bother continuing.
resp.setContent("");
return;
}
try {
if (RewriterUtils.isJavascript(req, resp)) {
compiler.setGoals(
compiler.getGoals().without(PipelineMaker.HTML_SAFE_STATIC));
}
passed = compiler.run();
CajoledModule outputJs = passed ? compiler.getJavascript() : null;
StringBuilder jsOut = new StringBuilder();
TokenConsumer printer;
if ("1".equals(req.getParam("debug"))) {
printer = new JsPrettyPrinter(new Concatenator(jsOut));