use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method moduleLevelNamesAreCaptured_esExportClassDecl.
@Test
public void moduleLevelNamesAreCaptured_esExportClassDecl() {
GlobalNamespace namespace = parseAndGatherModuleData("export class Foo {}");
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByPath().get("test.js");
Name x = namespace.getNameFromModule(metadata, "Foo");
assertThat(x).isNotNull();
assertNode(x.getDeclaration().getNode().getParent()).hasToken(Token.CLASS);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testThrowPreventsCollapsingChildNames.
@Test
public void testThrowPreventsCollapsingChildNames() {
GlobalNamespace namespace = parse(lines("const X = {Y: 1};", "", "function fn(a) {", // inside an if statement or the thrown value isn't a conditional expression.
" if (a) {", " throw a ? X : {};", " }", "}", "", "console.log(fn(true).Y);"));
Name nameX = namespace.getSlot("X");
assertThat(nameX.canCollapseUnannotatedChildNames()).isFalse();
Name propY = namespace.getSlot("X.Y");
assertThat(propY.canCollapse()).isFalse();
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testCanCollapseAliasedInterfaceProperty_ignoringStaticInheritance.
@Test
public void testCanCollapseAliasedInterfaceProperty_ignoringStaticInheritance() {
GlobalNamespace namespace = parse(lines("/** @interface */", "var Foo = function() {}", "", "Foo.prop = prop;", "use(Foo);"));
Name fooProp = namespace.getSlot("Foo.prop");
// We should still convert Foo.prop -> Foo$prop, even though use(Foo) might read Foo.prop,
// because Foo is a constructor
assertThat(fooProp.canCollapse()).isTrue();
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method removeOneRefOfAPairOfTwins.
@Test
public void removeOneRefOfAPairOfTwins() {
GlobalNamespace namespace = parse(lines(//
"let A;", // A will have twin refs here
"const B = A = 3;"));
Name nameA = namespace.getOwnSlot("A");
// first ref is declaration of A
// second is the SET twin
Ref setTwinRef = Iterables.get(nameA.getRefs(), 1);
// third is the GET twin
Ref getTwinRef = Iterables.get(nameA.getRefs(), 2);
// see confirmTwinsAreCreated() for verification of the original twin relationship
Node oldNode = getTwinRef.getNode();
// confirm that they are both associated with oldNode
assertThat(nameA.getRefsForNode(oldNode)).containsExactly(setTwinRef, getTwinRef);
nameA.removeTwinRefs(setTwinRef);
assertThat(nameA.getRefs()).doesNotContain(setTwinRef);
assertThat(nameA.getRefs()).doesNotContain(getTwinRef);
assertThat(nameA.getRefsForNode(oldNode)).isEmpty();
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method googModule_containsExports_explicitAssign.
@Test
public void googModule_containsExports_explicitAssign() {
GlobalNamespace namespace = parseAndGatherModuleData("goog.module('m'); const x = 0; exports = {x};");
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
Name exports = namespace.getNameFromModule(metadata, "exports");
assertThat(exports.getGlobalSets()).isEqualTo(1);
assertThat(namespace.getNameFromModule(metadata, "x").getGlobalSets()).isEqualTo(1);
}
Aggregations