Search in sources :

Example 6 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testShneCondition1.

/**
 * Tests reverse interpretation of a SHNE(NAME, NUMBER) expression.
 */
@SuppressWarnings("unchecked")
public void testShneCondition1() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.SHNE, createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), createNumber(56), ImmutableSet.of(new TypedName("a", createUnionType(STRING_TYPE, NUMBER_TYPE))), ImmutableSet.of(new TypedName("a", NUMBER_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 7 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testEqCondition1.

/**
 * Tests reverse interpretation of a EQ(NAME, NULL) expression.
 */
@SuppressWarnings("unchecked")
public void testEqCondition1() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.EQ, createVar(blind, "a", createUnionType(BOOLEAN_TYPE, VOID_TYPE)), createNull(), ImmutableSet.of(new TypedName("a", VOID_TYPE)), ImmutableSet.of(new TypedName("a", BOOLEAN_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 8 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testInstanceOf3.

@SuppressWarnings("unchecked")
public void testInstanceOf3() {
    FlowScope blind = newScope();
    testBinop(blind, Token.INSTANCEOF, createVar(blind, "x", OBJECT_TYPE), createVar(blind, "s", STRING_OBJECT_FUNCTION_TYPE), ImmutableSet.of(new TypedName("x", STRING_OBJECT_TYPE), new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)), ImmutableSet.of(new TypedName("x", OBJECT_TYPE), new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 9 with FlowScope

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

the class LinkedFlowScopeTest method testLongChain2.

/**
 * Create a long chain of flow scopes where each link in the chain
 * contains 7 slots.
 */
public void testLongChain2() {
    FlowScope chainA = localEntry.createChildFlowScope();
    FlowScope chainB = localEntry.createChildFlowScope();
    for (int i = 0; i < LONG_CHAIN_LENGTH * 7; i++) {
        localScope.declare("local" + i, null, null, null);
        chainA.inferSlotType("local" + i, i % 2 == 0 ? NUMBER_TYPE : BOOLEAN_TYPE);
        chainB.inferSlotType("local" + i, i % 3 == 0 ? STRING_TYPE : BOOLEAN_TYPE);
        if (i % 7 == 0) {
            chainA = chainA.createChildFlowScope();
            chainB = chainB.createChildFlowScope();
        }
    }
    verifyLongChains(chainA, chainB);
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 10 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testEqCondition2.

/**
 * Tests reverse interpretation of a NE(NULL, NAME) expression.
 */
@SuppressWarnings("unchecked")
public void testEqCondition2() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.NE, createNull(), createVar(blind, "a", createUnionType(BOOLEAN_TYPE, VOID_TYPE)), ImmutableSet.of(new TypedName("a", BOOLEAN_TYPE)), ImmutableSet.of(new TypedName("a", VOID_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

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