Example #1
0
 public void traverse(JsVisitor v, JsContext ctx) {
   if (v.visit(this, ctx)) {
     expr = v.accept(expr);
     v.acceptWithInsertRemove(cases);
   }
   v.endVisit(this, ctx);
 }
 public void traverse(JsVisitor v, JsContext ctx) {
   if (v.visit(this, ctx)) {
     qualifier = v.accept(qualifier);
     v.acceptList(args);
   }
   v.endVisit(this, ctx);
 }
  /**
   * Optimize a JS program.
   *
   * @param program the source program
   * @param toExec a list of classes that implement <code>static void exec(JsProgram)</code>
   * @return optimized JS
   */
  protected String optimize(JsProgram program, Class<?>... toExec) throws Exception {

    for (Class<?> clazz : toExec) {
      Method m = clazz.getMethod("exec", JsProgram.class);
      m.invoke(null, program);
    }

    TextOutput text = new DefaultTextOutput(true);
    JsVisitor generator = new JsSourceGenerationVisitor(text);

    generator.accept(program);
    return text.toString();
  }
Example #4
0
 private static String serializeJs(JsVisitable node) {
   TextOutput text = new DefaultTextOutput(true);
   JsVisitor generator = new JsSourceGenerationVisitor(text);
   generator.accept(node);
   return text.toString();
 }