Search in sources :

Example 11 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method testIsolatePolyfills_noAddedCodeForUnusedSymbol.

@Test
public void testIsolatePolyfills_noAddedCodeForUnusedSymbol() {
    CompilerOptions options = createCompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setLanguageIn(LanguageMode.STABLE_IN);
    options.setLanguageOut(LanguageMode.ECMASCRIPT5);
    options.setRewritePolyfills(true);
    options.setIsolatePolyfills(true);
    options.setGeneratePseudoNames(true);
    externs = ImmutableList.of(SourceFile.fromCode("testExterns.js", new TestExternsBuilder().addArray().addString().addObject().build()));
    test(options, "const unusedOne = Symbol('bar');", "var $$jscomp$propertyToPolyfillSymbol$$={};");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 12 with TestExternsBuilder

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

the class ES2022IntegrationTest method publicClassFields_supportedInOptimizationsMode.

@Test
public void publicClassFields_supportedInOptimizationsMode() {
    CompilerOptions options = fullyOptimizedCompilerOptions();
    options.setPrintSourceAfterEachPass(true);
    externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
    test(options, lines("class C {", "  f1 = 1;", "static f2 = 3;", "  m1() {return this.f1}", "}", "console.log(new C().f1);", "console.log(C.f2);", "console.log(new C().m1());"), lines("console.log(1);", "console.log(3);", "console.log(1);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 13 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method testNoRemoveSuperCallWithWrongArgumentCount.

// GitHub issue #2122: https://github.com/google/closure-compiler/issues/2122
@Test
public void testNoRemoveSuperCallWithWrongArgumentCount() {
    CompilerOptions options = createCompilerOptions();
    options.setCheckTypes(true);
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    // skip the default externs b/c they include Closure base.js,
    // which we want in the srcs.
    externs = ImmutableList.of(new TestExternsBuilder().addFunction().addExtra("var window;").buildExternsFile("externs.js"));
    test(options, lines(TestExternsBuilder.getClosureExternsAsSource(), "/** @constructor */", "var Foo = function() {}", "/**", " * @param {number=} width", " * @param {number=} height", " */", "Foo.prototype.resize = function(width, height) {", "  window.size = width * height;", "}", "/**", " * @constructor", " * @extends {Foo}", " */", "var Bar = function() {}", "goog.inherits(Bar, Foo);", "/** @override */", "Bar.prototype.resize = function(width, height) {", "  Bar.base(this, 'resize', width);", "};", "(new Bar).resize(100, 200);"), lines("function a(){}a.prototype.a=function(b,e){window.c=b*e};", "function d(){}d.b=a.prototype;d.prototype.a=function(b){d.b.a.call(this,b)};", "(new d).a(100, 200);"));
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 14 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method nullishCoalescePassThroughExterns.

@Test
public void nullishCoalescePassThroughExterns() {
    CompilerOptions options = createCompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setLanguage(LanguageMode.ECMASCRIPT_NEXT);
    externs = ImmutableList.of(new TestExternsBuilder().addExtra("var x, y").buildExternsFile("externs"));
    testSame(options, "x ?? y");
}
Also used : CompilerOptions(com.google.javascript.jscomp.CompilerOptions) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) Test(org.junit.Test)

Example 15 with TestExternsBuilder

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

the class AdvancedOptimizationsIntegrationTest method testModififyingDestructuringParamWithTranspilation.

@Test
public void testModififyingDestructuringParamWithTranspilation() {
    CompilerOptions options = createCompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setLanguageOut(LanguageMode.ECMASCRIPT5);
    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);"), "alert('foo');");
}
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