Search in sources :

Example 56 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method testInequalitiesCondition3.

/**
 * Tests reverse interpretation of a COMPARE(NUMBER-untyped, NAME) expression, where COMPARE can
 * be LE, LT, GE or GT.
 */
@Test
public void testInequalitiesCondition3() {
    for (Token op : Arrays.asList(Token.LT, Token.GT, Token.LE, Token.GE)) {
        FlowScope[] blind = newScope();
        testBinop(blind, op, createUntypedNumber(8), createVar(blind, "a", createUnionType(getNativeStringType(), getNativeVoidType())), ImmutableSet.of(new TypedName("a", getNativeStringType())), ImmutableSet.of(new TypedName("a", createUnionType(getNativeStringType(), getNativeVoidType()))));
    }
}
Also used : Token(com.google.javascript.rhino.Token) FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 57 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method newScope.

private FlowScope[] newScope() {
    TypedScope globalScope = TypedScope.createGlobalScope(new Node(Token.ROOT));
    functionScope = new TypedScope(globalScope, new Node(Token.FUNCTION));
    return new FlowScope[] { LinkedFlowScope.createEntryLattice(compiler, functionScope) };
}
Also used : Node(com.google.javascript.rhino.Node) FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 58 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class LinkedFlowScopeTest method testJoin3.

@Test
public void testJoin3() {
    localScope.declare("localC", null, getNativeStringType(), null, true);
    localScope.declare("localD", null, getNativeStringType(), null, true);
    FlowScope childA = localEntry.inferSlotType("localC", getNativeNumberType());
    FlowScope childB = localEntry.inferSlotType("localD", getNativeBooleanType());
    FlowScope joined = join(childB, childA);
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeNumberType()), joined.getSlot("localC").getType());
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localD").getType());
    joined = join(childA, childB);
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeNumberType()), joined.getSlot("localC").getType());
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localD").getType());
    assertWithMessage("Join should be symmetric").that(join(childA, childB)).isEqualTo(join(childB, childA));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 59 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class LinkedFlowScopeTest method testJoin1.

@Test
public void testJoin1() {
    FlowScope childA = localEntry.inferSlotType("localB", getNativeNumberType());
    FlowScope childAB = childA.inferSlotType("localB", getNativeStringType());
    FlowScope childB = localEntry.inferSlotType("localB", getNativeBooleanType());
    assertTypeEquals(getNativeStringType(), childAB.getSlot("localB").getType());
    assertTypeEquals(getNativeBooleanType(), childB.getSlot("localB").getType());
    assertThat(childB.getSlot("localA").getType()).isNull();
    FlowScope joined = join(childB, childAB);
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localB").getType());
    assertThat(joined.getSlot("localA").getType()).isNull();
    joined = join(childAB, childB);
    assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localB").getType());
    assertThat(joined.getSlot("localA").getType()).isNull();
    assertWithMessage("Join should be symmetric").that(join(childAB, childB)).isEqualTo(join(childB, childAB));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 60 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class LinkedFlowScopeTest method testDiffer2.

@Test
public void testDiffer2() {
    FlowScope childA = localEntry.inferSlotType("localA", getNativeNumberType());
    FlowScope childB = localEntry.inferSlotType("localA", getNativeNoType());
    assertScopesDiffer(childA, childB);
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Aggregations

FlowScope (com.google.javascript.jscomp.type.FlowScope)60 Node (com.google.javascript.rhino.Node)20 Test (org.junit.Test)16 JSType (com.google.javascript.rhino.jstype.JSType)12 Token (com.google.javascript.rhino.Token)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 Branch (com.google.javascript.jscomp.ControlFlowGraph.Branch)1 AbstractScopedCallback (com.google.javascript.jscomp.NodeTraversal.AbstractScopedCallback)1 DiGraphEdge (com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge)1 Module (com.google.javascript.jscomp.modules.Module)1 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)1 ReverseAbstractInterpreter (com.google.javascript.jscomp.type.ReverseAbstractInterpreter)1 JSTypeResolver (com.google.javascript.rhino.jstype.JSTypeResolver)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1 StaticTypedScope (com.google.javascript.rhino.jstype.StaticTypedScope)1 TemplateType (com.google.javascript.rhino.jstype.TemplateType)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1