use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class ClosureIntegrationTest method testDuplicateClosureNamespacesError.
@Test
public void testDuplicateClosureNamespacesError() {
CompilerOptions options = createCompilerOptions();
options.setClosurePass(true);
externs = ImmutableList.<SourceFile>builder().addAll(externs).add(SourceFile.fromCode("closure_externs.js", new TestExternsBuilder().addClosureExterns().build())).build();
ImmutableList<String> namespaces = ImmutableList.of("goog.provide('a.b.c');", "goog.module('a.b.c');", "goog.declareModuleId('a.b.c'); export {};", "goog.module('a.b.c'); goog.module.declareLegacyNamespace();");
for (String firstNs : namespaces) {
for (String secondNs : namespaces) {
test(options, new String[] { firstNs, secondNs }, DiagnosticGroups.DUPLICATE_NAMESPACES);
}
}
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class ES2022IntegrationTest method publicClassFields_supportedInOptimizationsMode2.
@Test
public void publicClassFields_supportedInOptimizationsMode2() {
CompilerOptions options = fullyOptimizedCompilerOptions();
externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
test(options, lines("/** @dict */", //
"class MyClass {", " ['f1'] = 2;", " 'f2' = 'hi';", " 2 = 4;", " ['m1']() { return this['f1']; }", "}", "console.log(new MyClass()['f1']);", "console.log(new MyClass()[2]);", "console.log(new MyClass()['m1']());"), lines(//
"class a {", " f1 = 2;", " f2= 'hi';", " 2 = 4;", " m1() { return this.f1; }", "}", "console.log((new a).f1);", "console.log((new a)[2]);", "console.log((new a).m1());"));
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class ES2022IntegrationTest method computedPublicClassFields_supportedInChecksOnlyMode.
@Test
public void computedPublicClassFields_supportedInChecksOnlyMode() {
CompilerOptions options = checksOnlyCompilerOptions();
externs = ImmutableList.of(new TestExternsBuilder().addConsole().buildExternsFile("externs"));
testNoWarnings(options, lines(//
"/** @dict */", "class MyClass {", " [3 + 4] = 5;", " [6];", " 'x' = 2;", "}", "console.log(new MyClass()[6]);"));
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AstFactoryTest method testCreateArgumentsReference_colors.
@Test
public void testCreateArgumentsReference_colors() {
Node root = parseAndAddColors(new TestExternsBuilder().addArguments().build(), "function f() { arguments; }");
AstFactory astFactory = createTestAstFactoryWithColors();
Node block = NodeUtil.getFunctionBody(root.getFirstFirstChild());
Node argumentsReferenceNode = block.getFirstFirstChild();
Color argumentsReferenceColor = argumentsReferenceNode.getColor();
Node argumentsNode = astFactory.createArgumentsReference();
assertNode(argumentsNode).matchesName("arguments");
assertNode(argumentsNode).hasColorThat().isEqualTo(argumentsReferenceColor);
}
use of com.google.javascript.jscomp.testing.TestExternsBuilder in project closure-compiler by google.
the class AstFactoryTest method testCreateArgumentsReference_jstypes.
@Test
public void testCreateArgumentsReference_jstypes() {
// Make sure the compiler's type registry includes the standard externs definition for
// Arguments.
parseAndAddTypes(new TestExternsBuilder().addArguments().build(), "");
AstFactory astFactory = createTestAstFactory();
Node argumentsNode = astFactory.createArgumentsReference();
assertNode(argumentsNode).matchesName("arguments");
assertType(argumentsNode.getJSType()).isEqualTo(getRegistry().getGlobalType("Arguments"));
}
Aggregations