Package com.google.javascript.jscomp

Examples of com.google.javascript.jscomp.Compiler


  private String compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS.toString();

  public void compile(List<File> filesToCompile, String destFileName){
    File destFile = prepareDestFile(destFileName);

    Compiler compiler = new Compiler();
    Result results = compiler.compile(getExterns(), getInputs(filesToCompile), getCompilerOptions());

    logger.debug(results.debugLog);
    for(JSError error : results.errors){
      logger.error("Closure Minifier Error:  " + error.sourceName + "  Description:  " +  error.description);
    }
    for(JSError warning : results.warnings){
      logger.info("Closure Minifier Warning:  " + warning.sourceName + "  Description:  " +  warning.description);
    }

    if (results.success) {
      try {
        Files.write(compiler.toSource(), destFile, Charsets.UTF_8);
      } catch (IOException e) {
        throw new ClosureException("Failed to write minified file to " + destFile, e);
      }
    }else{
      throw new ClosureException("Closure Compiler Failed - See error messages on System.err");
View Full Code Here


    return compiler;
  }

  private Compiler createCompiler(List<SourceFile> inputs, List<SourceFile> externs) {
    CompilerOptions options = getCompilerOptions();
    Compiler compiler = new Compiler();
    compiler.disableThreads();
    compiler.compile(externs, inputs, options);
    return compiler;
  }
View Full Code Here

        before
        + googRequire
        + "\n"
        + "/** @private */\n"
        + "function foo_() {};\n";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
    SuggestedFix fix = new SuggestedFix.Builder()
        .removeGoogRequire(match, "abc.def")
        .build();
View Full Code Here

    String input =
        "goog.require('abc.def');\n"
        + "\n"
        + "/** @private */\n"
        + "function foo_() {};\n";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Match match = new Match(root.getFirstChild(), new NodeMetadata(compiler));
    SuggestedFix fix = new SuggestedFix.Builder()
        .removeGoogRequire(match, "fakefake")
        .build();
View Full Code Here

    // of that is the Script node.
    return root.getLastChild().getFirstChild();
  }

  private Compiler getCompiler(String jsInput) {
    Compiler compiler = new Compiler();
    CompilerOptions options = RefactoringDriver.getCompilerOptions();
    compiler.init(
        ImmutableList.<SourceFile>of(), // Externs
        ImmutableList.of(SourceFile.fromCode("test", jsInput)),
        options);
    compiler.parse();
    return compiler;
  }
View Full Code Here

        + "/** @constructor */\n"
        + "function Foo() {};\n"
        + "/** @constructor */\n"
        + "function Bar() {};";
    String input = "var foo = new Foo();";
    Compiler compiler = getCompiler(externs, input);
    NodeMetadata metadata = new NodeMetadata(compiler);
    Node root = compileToScriptRoot(compiler);
    Node varNode = root.getFirstChild();
    Node newNode = varNode.getFirstChild().getFirstChild();
    assertTrue(newNode.isNew());
View Full Code Here

        + "/** @constructor */\n"
        + "function Foo() {};\n"
        + "Foo.prototype.bar = function() {};\n"
        + "Foo.prototype.baz = function() {};\n";
    String input = "var foo = new Foo(); foo.bar();";
    Compiler compiler = getCompiler(externs, input);
    NodeMetadata metadata = new NodeMetadata(compiler);
    Node root = compileToScriptRoot(compiler);
    Node fnCall = root.getLastChild().getFirstChild();
    assertTrue(fnCall.isCall());
    assertTrue(Matchers.functionCall("Foo.prototype.bar").matches(fnCall, metadata));
View Full Code Here

  }

  @Test
  public void testEnumOfType() {
    String input = "/** @enum {string} */ var foo = {BAR: 'baz'};";
    Compiler compiler = getCompiler(input);
    Node root = compileToScriptRoot(compiler);
    Node enumNode = root.getFirstChild().getFirstChild();
    assertTrue(Matchers.enumDefinitionOfType("string").matches(
        enumNode, new NodeMetadata(compiler)));
    assertFalse(Matchers.enumDefinitionOfType("number").matches(
View Full Code Here

    String externs = ""
        + "var goog = {};\n"
        + "goog.number = function() {};\n"
        + "var someObj = {};\n";
    String input = "someObj.foo = goog.number();";
    Compiler compiler = getCompiler(externs, input);
    Node root = compileToScriptRoot(compiler);
    Node assignNode = root.getFirstChild().getFirstChild();
    assertTrue(
        Matchers.assignmentWithRhs(Matchers.functionCall("goog.number")).matches(assignNode, null));
    assertFalse(
View Full Code Here

    String input = ""
        + "/** @constructor */\n"
        + "function Foo() {}\n"
        + "Foo.prototype.bar = 3;\n"
        + "Foo.prototype.baz = function() {};\n";
    Compiler compiler = getCompiler(input);
    NodeMetadata metadata = new NodeMetadata(compiler);
    Node root = compileToScriptRoot(compiler);
    Node prototypeVarAssign = root.getFirstChild().getNext().getFirstChild();
    Node prototypeFnAssign = root.getLastChild().getFirstChild();

View Full Code Here

TOP

Related Classes of com.google.javascript.jscomp.Compiler

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.