Search in sources :

Example 91 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class RefasterJsScannerTest method testInitialize_duplicateTemplateName.

@Test
public void testInitialize_duplicateTemplateName() throws Exception {
    try {
        Compiler compiler = createCompiler();
        compileTestCode(compiler, "", "");
        createScanner(compiler, "function before_foo() {}; function before_foo() {};");
        fail("RefasterJS templates are not allowed to have the same name.");
    } catch (IllegalStateException expected) {
    }
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Test(org.junit.Test)

Example 92 with Compiler

use of com.google.javascript.jscomp.Compiler in project AngularBeans by bessemHmidi.

the class ClosureCompiler method compile.

public String compile(String code) {
    Compiler compiler = new Compiler();
    compiler.disableThreads();
    SourceFile extern = SourceFile.fromCode("externs.js", "function alert(x) {}");
    SourceFile input = SourceFile.fromCode("input.js", code);
    compiler.compile(extern, input, options);
    return compiler.toSource();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) SourceFile(com.google.javascript.jscomp.SourceFile)

Example 93 with Compiler

use of com.google.javascript.jscomp.Compiler in project zm-mailbox by Zimbra.

the class ZimletResources method compile.

// doGet(HttpServletRequest,HttpServletResponse)
/**
 * @param code JavaScript source code to compile.
 * @return The compiled version of the code.
 */
public static String compile(String code) {
    if (StringUtil.isNullOrEmpty(code)) {
        return null;
    }
    Compiler compiler = new Compiler();
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    SourceFile extern = SourceFile.fromCode("externs.js", "");
    SourceFile input = SourceFile.fromCode("input.js", code);
    WarningLevel.QUIET.setOptionsForWarningLevel(options);
    compiler.compile(extern, input, options);
    return compiler.toSource();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile)

Example 94 with Compiler

use of com.google.javascript.jscomp.Compiler 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 95 with Compiler

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

the class CompilerUtils method makeCompiler.

/**
 * Create a new compiler object, using a given error manager.
 * @param errorManager  The error manager the compiler will be connected to.
 * @return  The new compiler.
 */
public static Compiler makeCompiler(ErrorManager errorManager) {
    Compiler compiler = new Compiler(errorManager);
    compiler.disableThreads();
    return compiler;
}
Also used : AbstractCompiler(com.google.javascript.jscomp.AbstractCompiler) Compiler(com.google.javascript.jscomp.Compiler)

Aggregations

Compiler (com.google.javascript.jscomp.Compiler)172 Test (org.junit.Test)132 Node (com.google.javascript.rhino.Node)116 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)50 SourceFile (com.google.javascript.jscomp.SourceFile)22 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)16 NoninjectingCompiler (com.google.javascript.jscomp.testing.NoninjectingCompiler)9 TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)8 Result (com.google.javascript.jscomp.Result)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 File (java.io.File)4 BlackHoleErrorManager (com.google.javascript.jscomp.BlackHoleErrorManager)3 JSError (com.google.javascript.jscomp.JSError)3 InputId (com.google.javascript.rhino.InputId)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 AbstractCompiler (com.google.javascript.jscomp.AbstractCompiler)2 CompilerInput (com.google.javascript.jscomp.CompilerInput)2 JSChunk (com.google.javascript.jscomp.JSChunk)2 JSModule (com.google.javascript.jscomp.JSModule)2