use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testCanCollapseAliasedClassProperty_consideringStaticInheritance.
@Test
public void testCanCollapseAliasedClassProperty_consideringStaticInheritance() {
this.assumeStaticInheritanceIsNotUsed = false;
GlobalNamespace namespace = parse(lines("class Foo {} Foo.prop = prop; use(Foo);"));
Name fooProp = namespace.getSlot("Foo.prop");
assertThat(fooProp.canCollapse()).isFalse();
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testCanCollapse_objectLitProperty_declaredBeforeASpread.
@Test
public void testCanCollapse_objectLitProperty_declaredBeforeASpread() {
GlobalNamespace namespace = parse("var foo = {prop: 0, ...bar}; use(foo.prop);");
Name fooProp = namespace.getSlot("foo.prop");
assertThat(fooProp.canCollapse()).isFalse();
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testGitHubIssue3733.
@Test
public void testGitHubIssue3733() {
GlobalNamespace namespace = parse(lines("const X = {Y: 1};", "", "function fn(a) {", " if (a) {", // for the RETURN node type, so X.Y was incorrectly collapsed.
" return 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 googLoadModule_containsExportsPropertyAssignments.
@Test
public void googLoadModule_containsExportsPropertyAssignments() {
GlobalNamespace namespace = parseAndGatherModuleData(lines("goog.loadModule(function(exports) {", " goog.module('m');", " exports.Foo = class {};", " return exports;", "});"));
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
Name exportsFoo = namespace.getNameFromModule(metadata, "exports.Foo");
assertThat(exportsFoo.getGlobalSets()).isEqualTo(1);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method updateRefNodeCanSetNodeToNullButPreventsFurtherUpdates.
@Test
public void updateRefNodeCanSetNodeToNullButPreventsFurtherUpdates() {
GlobalNamespace namespace = parse("const A = 3;");
Name nameA = namespace.getOwnSlot("A");
Ref refA = nameA.getFirstRef();
Node oldNode = refA.getNode();
assertThat(nameA.getRefsForNode(oldNode)).containsExactly(refA);
nameA.updateRefNode(refA, null);
assertThat(refA.getNode()).isNull();
assertThat(nameA.getRefsForNode(oldNode)).isEmpty();
// cannot get refs for null
assertThrows(NullPointerException.class, () -> nameA.getRefsForNode(null));
// cannot update the node again once it's been set to null
assertThrows(IllegalArgumentException.class, () -> nameA.updateRefNode(refA, null));
assertThrows(IllegalStateException.class, () -> nameA.updateRefNode(refA, oldNode));
}
Aggregations