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$$={};");
}
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);"));
}
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);"));
}
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");
}
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');");
}
Aggregations