Search in sources :

Example 36 with Name

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();
}
Also used : Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 37 with Name

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();
}
Also used : Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 38 with Name

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();
}
Also used : Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 39 with Name

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);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 40 with Name

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));
}
Also used : Ref(com.google.javascript.jscomp.GlobalNamespace.Ref) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Aggregations

Name (com.google.javascript.jscomp.GlobalNamespace.Name)95 Test (org.junit.Test)72 Ref (com.google.javascript.jscomp.GlobalNamespace.Ref)25 Node (com.google.javascript.rhino.Node)22 ModuleMetadata (com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata)12 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)12 JSDocInfo (com.google.javascript.rhino.JSDocInfo)5 AstChange (com.google.javascript.jscomp.GlobalNamespace.AstChange)2 Inlinability (com.google.javascript.jscomp.GlobalNamespace.Inlinability)2 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)2 JSType (com.google.javascript.rhino.jstype.JSType)2 LinkedHashSet (java.util.LinkedHashSet)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 PropagateConstantAnnotationsOverVars (com.google.javascript.jscomp.Normalize.PropagateConstantAnnotationsOverVars)1 Module (com.google.javascript.jscomp.modules.Module)1 FeatureSet (com.google.javascript.jscomp.parsing.parser.FeatureSet)1 QualifiedName (com.google.javascript.rhino.QualifiedName)1 ArrayList (java.util.ArrayList)1