use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testBigIntStringConcatenation.
@Test
public void testBigIntStringConcatenation() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguage(LanguageMode.ECMASCRIPT_NEXT);
externs = ImmutableList.of(new TestExternsBuilder().addBigInt().buildExternsFile("externs.js"));
test(options, "1n + 'asdf'", "'1nasdf'");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method nullishCoalesceTranspiledOutput.
@Test
public void nullishCoalesceTranspiledOutput() {
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").buildExternsFile("externs"));
test(options, "x ?? y", "let a; null != (a = x) ? a : y");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testDisambiguationOfForwardReferencedAliasedInterface.
@Test
public void testDisambiguationOfForwardReferencedAliasedInterface() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageOut(LanguageMode.NO_TRANSPILE);
options.setDisambiguateProperties(true);
options.setPrettyPrint(true);
options.setPreserveTypeAnnotations(true);
externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs.js"));
test(options, lines("", // but it does have a matching `foo()` method.
"class MyBaseClass {", " /** @return {void} */", " foo() {", " console.log('I should exist');", " }", "}", "", // Note that `AliasedInterface` isn't defined yet.
"/** @implements {AliasedInterface} */", "class MyClass extends MyBaseClass {", "}", "", // code doesn't appear to do this.
"/** @record */", "function OriginalInterface() { }", "/** @return {void} */", "OriginalInterface.prototype.foo = function () { };", "", // error.
"/** @const */", "const AliasedInterface = OriginalInterface;", "", // `MyClass.prototype.foo`.
"/** @return {!AliasedInterface} */", "function magicFactory() {", " return new MyClass();", "}", "", "magicFactory().foo();"), // up inlined as the only output statement.
"console.log('I should exist');");
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testBug173319540.
@Test
public void testBug173319540() {
// 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.ECMASCRIPT_2017);
options.setPrettyPrint(true);
options.setGeneratePseudoNames(true);
externs = ImmutableList.of(new TestExternsBuilder().addAsyncIterable().addConsole().addExtra(// fake async iterator to use in the test code
"/** @type {!AsyncIterator<Array<String>>} */", "var asyncIterator;", "", // Externs to take the place of the injected library code
"const $jscomp = {};", "", "/**", " * @param {", " * string|!AsyncIterable<T>|!Iterable<T>|!Iterator<T>|!Arguments", " * } iterable", " * @return {!AsyncIteratorIterable<T>}", " * @template T", " * @suppress {reportUnknownTypes}", " */", "$jscomp.makeAsyncIterator = function(iterable) {};", "").buildExternsFile("externs.js"));
test(options, lines(//
"", "async function foo() {", " for await (const [key, value] of asyncIterator) {", " console.log(key,value);", " }", "}", "foo();"), lines(//
"", "(async function() {", " for (const $$jscomp$forAwait$tempIterator0$$ =", " $jscomp.makeAsyncIterator(asyncIterator);;) {", " const $$jscomp$forAwait$tempResult0$$ =", " await $$jscomp$forAwait$tempIterator0$$.next();", " if ($$jscomp$forAwait$tempResult0$$.done) {", " break;", " }", " const [$key$$, $value$jscomp$2$$] = $$jscomp$forAwait$tempResult0$$.value;", " console.log($key$$, $value$jscomp$2$$);", " }", "})();", ""));
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AdvancedOptimizationsIntegrationTest method testReferenceToInternalClassName.
@Test
public void testReferenceToInternalClassName() {
CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageOut(LanguageMode.NO_TRANSPILE);
// 'use strict'; is just noise here
options.setEmitUseStrict(false);
options.setPrettyPrint(true);
options.setGeneratePseudoNames(true);
externs = ImmutableList.of(new TestExternsBuilder().addExtra("function use(x) {}").buildExternsFile("externs"));
test(options, new String[] { TestExternsBuilder.getClosureExternsAsSource(), lines("goog.module('a.b.c');", "exports = class Foo {", // (CollapseProperties) to get full optimization and avoid generating broken code.
" method() { return Foo.EventType.E1; }", "};", "", "/** @enum {number} */", "exports.EventType = {", " E1: 1,", "};", ""), lines(//
"", "goog.module('a.b.d');", "const Foo = goog.require('a.b.c');", "use(new Foo().method());", "") }, new String[] { "", "", lines(//
"new class {};", "use(1)") });
}
Aggregations