use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testDoubleLhsCastInAssignment_doesNotCrash.
@Test
public void testDoubleLhsCastInAssignment_doesNotCrash() {
// The type of the cast doesn't matter.
// Casting is only legal JS syntax in simple assignments, not with destructuring or declaration.
GlobalNamespace namespace = parse(lines("const ns = {};", " const b = 5;", " /** @type {*} */ (/** @type {*} */ (ns.a)) = b;"));
Name ns = namespace.getSlot("ns");
assertThat(ns.getGlobalSets()).isEqualTo(1);
assertThat(ns.getTotalGets()).isEqualTo(0);
Name nsA = namespace.getSlot("ns.a");
// TODO(b/127505242): Should be 1.
assertThat(nsA.getGlobalSets()).isEqualTo(0);
// TODO(b/127505242): Should be 0.
assertThat(nsA.getTotalGets()).isEqualTo(1);
Name b = namespace.getSlot("b");
assertThat(b.getGlobalSets()).isEqualTo(1);
assertThat(b.getAliasingGets()).isEqualTo(1);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testGoogProvideNamespace_noExplicitAssignment.
@Test
public void testGoogProvideNamespace_noExplicitAssignment() {
GlobalNamespace namespace = parse("goog.provide('a.b');");
Name a = namespace.getSlot("a");
assertThat(a).isNotNull();
assertThat(a.getGlobalSets()).isEqualTo(0);
Name ab = namespace.getSlot("a.b");
assertThat(ab).isNotNull();
assertThat(ab.getGlobalSets()).isEqualTo(0);
assertThat(a.getDeclaration()).isNull();
assertThat(ab.getDeclaration()).isNull();
assertThat(ab.getParent()).isEqualTo(a);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testObjectPatternRestAliasInAssign.
@Test
public void testObjectPatternRestAliasInAssign() {
GlobalNamespace namespace = parse("const ns = {a: 3}; const x = {}; ({a, ...x.y} = ns);");
Name ns = namespace.getSlot("ns");
assertThat(ns.getGlobalSets()).isEqualTo(1);
assertThat(ns.getAliasingGets()).isEqualTo(1);
Name nsA = namespace.getSlot("ns.a");
assertThat(nsA.getGlobalSets()).isEqualTo(1);
assertThat(nsA.getAliasingGets()).isEqualTo(1);
Name xY = namespace.getSlot("x.y");
// TODO(b/117673791): this should be 1
assertThat(xY.getGlobalSets()).isEqualTo(0);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method googLoadModule_capturesQualifiedNames.
@Test
public void googLoadModule_capturesQualifiedNames() {
GlobalNamespace namespace = parseAndGatherModuleData(lines("goog.loadModule(function(exports) {", " goog.module('m');", " class Foo {}", " Foo.Bar = class {};", " return exports;", "});"));
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
Name foo = namespace.getNameFromModule(metadata, "Foo");
Name fooBar = namespace.getNameFromModule(metadata, "Foo.Bar");
assertThat(fooBar.getParent()).isEqualTo(foo);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testClassStaticAndPrototypePropWithSameName.
@Test
public void testClassStaticAndPrototypePropWithSameName() {
GlobalNamespace ns = parse("class C { x() {} static x() {} }");
Name c = ns.getSlot("C");
Name cDotX = ns.getSlot("C.x");
assertThat(c.getGlobalSets()).isEqualTo(1);
assertThat(c.props).containsExactly(cDotX);
assertThat(cDotX.getGlobalSets()).isEqualTo(1);
assertThat(cDotX.getParent()).isEqualTo(c);
}
Aggregations