Search in sources :

Example 1 with FlowScope

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

the class LinkedFlowScopeTest method verifyLongChains.

// Common chain verification for testLongChainN for all N.
private void verifyLongChains(FlowScope chainA, FlowScope chainB) {
    FlowScope joined = join(chainA, chainB);
    for (int i = 0; i < LONG_CHAIN_LENGTH; i++) {
        assertTypeEquals(i % 2 == 0 ? NUMBER_TYPE : BOOLEAN_TYPE, chainA.getSlot("local" + i).getType());
        assertTypeEquals(i % 3 == 0 ? STRING_TYPE : BOOLEAN_TYPE, chainB.getSlot("local" + i).getType());
        JSType joinedSlotType = joined.getSlot("local" + i).getType();
        if (i % 6 == 0) {
            assertTypeEquals(createUnionType(STRING_TYPE, NUMBER_TYPE), joinedSlotType);
        } else if (i % 2 == 0) {
            assertTypeEquals(createUnionType(NUMBER_TYPE, BOOLEAN_TYPE), joinedSlotType);
        } else if (i % 3 == 0) {
            assertTypeEquals(createUnionType(STRING_TYPE, BOOLEAN_TYPE), joinedSlotType);
        } else {
            assertTypeEquals(BOOLEAN_TYPE, joinedSlotType);
        }
    }
    assertScopesDiffer(chainA, chainB);
    assertScopesDiffer(chainA, joined);
    assertScopesDiffer(chainB, joined);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 2 with FlowScope

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

the class LinkedFlowScopeTest method testLongChain3.

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

Example 3 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testSheqCondition1.

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

Example 4 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testSheqCondition2.

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

Example 5 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testShneCondition2.

/**
 * Tests reverse interpretation of a SHNE(NUMBER, NAME) expression.
 */
@SuppressWarnings("unchecked")
public void testShneCondition2() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.SHNE, createNumber(56), createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), 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)

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