Search in sources :

Example 61 with TestExternsBuilder

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

the class ES2022IntegrationTest method publicClassFields_supportedInChecksOnlyMode.

@Test
public void publicClassFields_supportedInChecksOnlyMode() {
    CompilerOptions options = checksOnlyCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    testNoWarnings(options, lines(// 
    "class MyClass {", "  /** @type {number} */", "  x = 2;", "  y;", "}", "console.log(new MyClass().x);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 62 with TestExternsBuilder

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

the class ES2022IntegrationTest method computedPublicClassFields_supportedInChecksOnlyMode2.

@Test
public void computedPublicClassFields_supportedInChecksOnlyMode2() {
    CompilerOptions options = checksOnlyCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    testNoWarnings(options, lines(// 
    "/** @dict */", "class MyClass {", "  ['x'] = 5;", "}", "console.log(new MyClass()['x']);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 63 with TestExternsBuilder

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

the class ES2022IntegrationTest method publicClassFields_supportedInChecksOnlyMode2.

@Test
public void publicClassFields_supportedInChecksOnlyMode2() {
    CompilerOptions options = checksOnlyCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    testNoWarnings(options, lines(// 
    "class MyClass {", "  x = '';", "  y;", "}", "console.log(new MyClass().x);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 64 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method testModififyingDestructuringParamWithoutTranspilation.

@Test
public void testModififyingDestructuringParamWithoutTranspilation() {
    CompilerOptions options = createCompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setLanguageOut(LanguageMode.ECMASCRIPT_2015);
    externs = ImmutableList.of(SourceFile.fromCode("testExterns.js", new TestExternsBuilder().addAlert().build()));
    test(options, lines("function installBaa({ obj }) {", " obj.baa = 'foo';", "}", "", "const obj = {};", "installBaa({ obj });", "alert(obj.baa);"), lines(// 
    "const a = {};", "(function({b}){", "  b.a = 'foo';", "})({b: a});", "alert(a.a);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 65 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method nullishCoalesceChainTranspiledOutput.

@Test
public void nullishCoalesceChainTranspiledOutput() {
    CompilerOptions options = createCompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT_IN);
    options.setLanguageOut(LanguageMode.ECMASCRIPT_2019);
    externs = ImmutableList.of(new TestExternsBuilder().addExtra("var x, y, z").buildExternsFile("externs"));
    test(options, "x ?? y ?? z", "let a, b; null != (b = null != (a = x) ? a : y) ? b : z");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Aggregations

TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)107 Test (org.junit.Test)106 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)58 Node (com.google.javascript.rhino.Node)17 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)17 Compiler (com.google.javascript.jscomp.Compiler)8 SourceFile (com.google.javascript.jscomp.SourceFile)7 Color (com.google.javascript.jscomp.colors.Color)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CodeSubTree (com.google.javascript.jscomp.testing.CodeSubTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 NoninjectingCompiler (com.google.javascript.jscomp.testing.NoninjectingCompiler)1 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)1 SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 File (java.io.File)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1