Search in sources :

Example 1 with JSSourceFile

use of com.google.javascript.jscomp.JSSourceFile in project ow by vtst.

the class MainForDebug method compile.

public static void compile(JSModule module) {
    Compiler compiler = CompilerUtils.makeCompiler(CompilerUtils.makePrintingErrorManager(System.out));
    CompilerOptions options = CompilerUtils.makeOptionsForParsingAndErrorReporting();
    compiler.initOptions(options);
    JSSourceFile extern = JSSourceFile.fromCode("externs.js", "");
    compiler.compile(extern, new JSModule[] { module }, options);
    System.out.println(compiler.toSource());
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) JSSourceFile(com.google.javascript.jscomp.JSSourceFile)

Example 2 with JSSourceFile

use of com.google.javascript.jscomp.JSSourceFile in project ow by vtst.

the class MainForDebug method measureTime.

public static void measureTime() {
    final ArrayList<File> listFiles = new ArrayList<File>();
    final ArrayList<JSSourceFile> listSourceFiles = new ArrayList<JSSourceFile>();
    final ArrayList<AstFactoryFromModifiable> listAsts = new ArrayList<AstFactoryFromModifiable>();
    FileTreeVisitor.Simple<RuntimeException> visitor = new FileTreeVisitor.Simple<RuntimeException>() {

        public void visitFile(File file) {
            if (!CompilerUtils.isJavaScriptFile(file))
                return;
            listFiles.add(file);
            JSSourceFile sourceFile = JSSourceFile.fromFile(file);
            listSourceFiles.add(sourceFile);
        // listAsts.add(new JsAstFactoryFromFile(file));
        }
    };
    visitor.visit(new File("/home/vtst/test/out/goog"));
    System.out.println(listAsts.size());
    long t0 = System.nanoTime();
    long t1 = 0;
    for (int i = 0; i < 10; ++i) {
        if (i == 1)
            t1 = System.nanoTime();
        JSModule module = new JSModule("main");
        for (AstFactoryFromModifiable ast : listAsts) {
            module.add(new CompilerInput(ast.getClone(false)));
        }
        // for (JSSourceFile sourceFile: listSourceFiles) {
        // module.add(new CompilerInput(sourceFile));
        // }
        // for (File file: listFiles) {
        // module.add(new CompilerInput(JSSourceFile.fromFile(file)));
        // }
        Compiler compiler = CompilerUtils.makeCompiler(CompilerUtils.makePrintingErrorManager(System.out));
        CompilerOptions options = CompilerUtils.makeOptionsForParsingAndErrorReporting();
        options.checkTypes = true;
        compiler.compile(new JSSourceFile[] {}, new JSModule[] { module }, options);
        System.out.println(compiler.toSource().length());
    }
    long tf = System.nanoTime();
    System.out.println((tf - t0) * 1e-9);
    System.out.println((tf - t1) * 1e-9);
    System.out.println("DONE");
}
Also used : FileTreeVisitor(net.vtst.ow.closure.compiler.util.FileTreeVisitor) Compiler(com.google.javascript.jscomp.Compiler) ArrayList(java.util.ArrayList) JSSourceFile(com.google.javascript.jscomp.JSSourceFile) CompilerInput(com.google.javascript.jscomp.CompilerInput) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) JSModule(com.google.javascript.jscomp.JSModule) File(java.io.File) JSSourceFile(com.google.javascript.jscomp.JSSourceFile) AstFactoryFromModifiable(net.vtst.ow.closure.compiler.deps.AstFactoryFromModifiable)

Example 3 with JSSourceFile

use of com.google.javascript.jscomp.JSSourceFile in project ow by vtst.

the class JSFileStripper method strip.

/**
 * Run the processor on a JavaScript file.
 * @param input  The input JavaScript file.
 * @param output  The output JavaScript file.
 * @return  The array of errors reported by the JavaScript compiler.
 * @throws IOException
 */
public void strip(File input, File output) throws IOException {
    JSSourceFile jsInput = JSSourceFile.fromFile(input.getAbsolutePath());
    Writer writer = new BufferedWriter(new FileWriter(output));
    setupCompiler(writer);
    compiler.compile(Collections.<JSSourceFile>emptyList(), Collections.singletonList(jsInput), options);
    if (stripCompilerPass.getException() != null)
        throw stripCompilerPass.getException();
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) JSSourceFile(com.google.javascript.jscomp.JSSourceFile) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Aggregations

JSSourceFile (com.google.javascript.jscomp.JSSourceFile)3 Compiler (com.google.javascript.jscomp.Compiler)2 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)2 CompilerInput (com.google.javascript.jscomp.CompilerInput)1 JSModule (com.google.javascript.jscomp.JSModule)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 AstFactoryFromModifiable (net.vtst.ow.closure.compiler.deps.AstFactoryFromModifiable)1 FileTreeVisitor (net.vtst.ow.closure.compiler.util.FileTreeVisitor)1