Search in sources :

Example 26 with TestExternsBuilder

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

the class ES2021IntegrationTest method logicalAsssignmentsSimpleCastType_supportedWithTranspilation.

@Test
public void logicalAsssignmentsSimpleCastType_supportedWithTranspilation() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addExtra("let x").buildExternsFile("externs"));
    test(options, "/** @type {?} */ (x) ||= 's'", "x || (x = 's')");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 27 with TestExternsBuilder

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

the class ES2021IntegrationTest method logicalAssignmentSimpleTranspiledOutput3.

@Test
public void logicalAssignmentSimpleTranspiledOutput3() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addExtra("let w, x, y, z").buildExternsFile("externs"));
    test(options, "w ||= (x &&= (y ??= z))", "w || (w = x && (x = y ?? (y = z)));");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 28 with TestExternsBuilder

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

the class ES2021IntegrationTest method logicalAssignmentSimpleTranspiledOutputRHSNotExecuted.

@Test
public void logicalAssignmentSimpleTranspiledOutputRHSNotExecuted() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs.js"));
    test(options, lines(// 
    "let n = null;", "n &&= foo();", "function foo() {", " console.log('should not be executed');", "}"), "");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 29 with TestExternsBuilder

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

the class ES2021IntegrationTest method logicalAsssignmentsPropRefWithElementCastType_supportedOnlyWithoutTranspilation.

@Test
public void logicalAsssignmentsPropRefWithElementCastType_supportedOnlyWithoutTranspilation() {
    CompilerOptions options = optimizedWithoutTranspilationCompilerOptions();
    externs = ImmutableList.of(new TestExternsBuilder().addExtra("let foo, x").buildExternsFile("externs"));
    test(options, "/** @type {number} */ (foo[x]) ??= 5", lines(// 
    "let a, b;", "(a = foo)[b = x] ?? (a[b] = 5)"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 30 with TestExternsBuilder

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

the class ES2022IntegrationTest method publicClassFields_supportedInOptimizationsMode1.

@Test
public void publicClassFields_supportedInOptimizationsMode1() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    options.setPrintSourceAfterEachPass(true);
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    test(options, lines(// 
    "class MyClass {", "  /** @type {number} */", "  f1 = 2;", "  /** @type {string} */", "  f2 = 'hi';", "  f3 = function() { return this.f1 };", "  m1() { return this.f2; }", "}", "console.log(new MyClass().f1);", "console.log(new MyClass().f2);", "console.log(new MyClass().f3());", "console.log(new MyClass().m1());"), lines("console.log(2);", "console.log('hi');", "console.log(2);", "console.log('hi');"));
}
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