use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testBug123583793.
@Test
public void testBug123583793() {
// Avoid including the transpilation library
useNoninjectingCompiler = true;
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
CompilationLevel.ADVANCED_OPTIMIZATIONS.setTypeBasedOptimizationOptions(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setRewritePolyfills(true);
options.setPrettyPrint(true);
externs = ImmutableList.of(new TestExternsBuilder().addObject().addConsole().buildExternsFile("externs.js"));
test(options, lines("function foo() {", " const {a, ...rest} = {a: 1, b: 2, c: 3};", " return {a, rest};", "};", "console.log(foo());", ""), lines("var a = console,", " b = a.log,", " c = {a:1, b:2, c:3},", " d = Object.assign({}, c),", " e = c.a,", " f = (delete d.a, d);", "b.call(a, {a:e, d:f});", ""));
assertThat(((NoninjectingCompiler) lastCompiler).getInjected()).contains("es6/object/assign");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testUnusedTaggedTemplateLiteralGetsRemoved.
@Test
public void testUnusedTaggedTemplateLiteralGetsRemoved() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.setPrettyPrint(true);
externs = ImmutableList.of(new TestExternsBuilder().addConsole().addArray().addExtra("var goog;", "", "/**", " * @param {string} msg", " * @return {string}", " * @nosideeffects", " */", "goog.getMsg = function(msg) {};", "", "/**", " * @param {...*} template_args", " * @return {string}", " */", "function $localize(template_args){}", "/**", " * @constructor", " * @extends {Array<string>}", " */", "var ITemplateArray = function() {};", "").buildExternsFile("externs.js"));
test(options, lines("var i18n_7;", "var ngI18nClosureMode = true;", "if (ngI18nClosureMode) {", " /**", " * @desc Some message", " */", " const MSG_A = goog.getMsg(\"test\");", " i18n_7 = MSG_A;", "}", "else {", " i18n_7 = $localize `...`;", "}", "console.log(i18n_7);", ""), lines(// Tagged template literal was correctly removed.
"console.log(goog.getMsg('test'));"));
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testFunctionThatAcceptsAndReturnsBigInt.
@Test
public void testFunctionThatAcceptsAndReturnsBigInt() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguage(LanguageMode.ECMASCRIPT_NEXT);
externs = ImmutableList.of(new TestExternsBuilder().addBigInt().addConsole().buildExternsFile("externs.js"));
test(options, lines("/**", " * @param {bigint} value", " * @return {bigint}", " */", "function bigintTimes3(value){", " return value * 3n;", "}", "console.log(bigintTimes3(5n));"), "console.log(15n);");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testRewritePolyfills_noAddedCodeForUnusedPolyfill.
@Test
public void testRewritePolyfills_noAddedCodeForUnusedPolyfill() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageIn(LanguageMode.STABLE_IN);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setRewritePolyfills(true);
options.setGeneratePseudoNames(true);
externs = ImmutableList.of(SourceFile.fromCode("testExterns.js", new TestExternsBuilder().addArray().addString().addObject().build()));
test(options, "const unused = 'foo'.startsWith('bar');", "");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class ES2021IntegrationTest method logicalAsssignmentsSimpleCastType_supportedOnlyWithoutTranspilation.
@Test
public void logicalAsssignmentsSimpleCastType_supportedOnlyWithoutTranspilation() {
CompilerOptions options = optimizedWithoutTranspilationCompilerOptions();
externs = ImmutableList.of(new TestExternsBuilder().addExtra("let x").buildExternsFile("externs"));
test(options, "/** @type {?} */ (x) ||= 's'", "x ||= 's'");
}
Aggregations