Search in sources :

Example 66 with Compiler

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

the class IntegrationTestCase method test.

/**
 * Asserts that when compiling with the given compiler options,
 * {@code original} is transformed into {@code compiled}.
 */
protected void test(CompilerOptions options, String[] original, String[] compiled) {
    Compiler compiler = compile(options, original);
    Node root = compiler.getRoot().getLastChild();
    // Verify that there are no unexpected errors before checking the compiled output
    assertWithMessage("Expected no warnings or errors\n" + "Errors: \n" + Joiner.on("\n").join(compiler.getErrors()) + "\n" + "Warnings: \n" + Joiner.on("\n").join(compiler.getWarnings())).that(compiler.getErrors().size() + compiler.getWarnings().size()).isEqualTo(0);
    if (compiled != null) {
        Node expectedRoot = parseExpectedCode(compiled, options);
        assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
    }
}
Also used : NoninjectingCompiler(com.google.javascript.jscomp.testing.NoninjectingCompiler) Compiler(com.google.javascript.jscomp.Compiler) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node)

Example 67 with Compiler

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

the class IntegrationTestCase method test.

/**
 * Asserts that when compiling with the given compiler options, there is an error or warning.
 */
protected void test(CompilerOptions options, String[] original, String[] compiled, DiagnosticGroup[] warnings) {
    Compiler compiler = compile(options, original);
    checkUnexpectedErrorsOrWarnings(compiler, warnings.length);
    if (compiled != null) {
        Node root = compiler.getRoot().getLastChild();
        Node expectedRoot = parseExpectedCode(compiled, options);
        assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
    }
    assertThat(ImmutableList.builder().addAll(compiler.getErrors()).addAll(compiler.getWarnings()).build()).comparingElementsUsing(JSCompCorrespondences.OWNING_DIAGNOSTIC_GROUP).containsExactly(warnings);
}
Also used : NoninjectingCompiler(com.google.javascript.jscomp.testing.NoninjectingCompiler) Compiler(com.google.javascript.jscomp.Compiler) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node)

Example 68 with Compiler

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

the class IntegrationTestCase method testNoWarnings.

protected void testNoWarnings(CompilerOptions options, String[] sources) {
    Compiler compiler = compile(options, sources);
    assertThat(compiler.getErrors()).isEmpty();
    assertThat(compiler.getWarnings()).isEmpty();
}
Also used : NoninjectingCompiler(com.google.javascript.jscomp.testing.NoninjectingCompiler) Compiler(com.google.javascript.jscomp.Compiler)

Example 69 with Compiler

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

the class IntegrationTest method testStrictWarningsGuard.

@Test
public void testStrictWarningsGuard() {
    CompilerOptions options = createCompilerOptions();
    options.setCheckTypes(true);
    options.addWarningsGuard(new StrictWarningsGuard());
    Compiler compiler = compile(options, "/** @return {number} */ function f() { return true; }");
    assertThat(compiler.getErrors()).hasSize(1);
    assertThat(compiler.getWarnings()).isEmpty();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) StrictWarningsGuard(com.google.javascript.jscomp.StrictWarningsGuard) Test(org.junit.Test)

Example 70 with Compiler

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

the class TypedAstIntegrationTest method removesRegExpCallsIfUnsafelyReferenced.

@Test
public void removesRegExpCallsIfUnsafelyReferenced() throws IOException {
    precompileLibrary(extern(new TestExternsBuilder().addRegExp().addConsole().build()), code(// 
    "(/abc/gi).exec('');", "console.log(RegExp.$1);"));
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    Compiler compiler = compileTypedAstShards(options);
    Node expectedRoot = parseExpectedCode("(/abc/gi).exec(''); console.log(RegExp.$1);");
    assertNode(compiler.getRoot().getSecondChild()).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

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