Search in sources :

Example 1 with TypePair

use of com.google.javascript.rhino.jstype.JSType.TypePair in project closure-compiler by google.

the class SemanticReverseAbstractInterpreter method caseEquality.

@CheckReturnValue
private FlowScope caseEquality(Node left, Node right, FlowScope blindScope, Function<TypePair, TypePair> merging) {
    // left type
    JSType leftType = getTypeIfRefinable(left, blindScope);
    boolean leftIsRefineable;
    if (leftType != null) {
        leftIsRefineable = true;
    } else {
        leftIsRefineable = false;
        leftType = left.getJSType();
    }
    // right type
    JSType rightType = getTypeIfRefinable(right, blindScope);
    boolean rightIsRefineable;
    if (rightType != null) {
        rightIsRefineable = true;
    } else {
        rightIsRefineable = false;
        rightType = right.getJSType();
    }
    // merged types
    TypePair merged = merging.apply(new TypePair(leftType, rightType));
    // creating new scope
    if (merged != null) {
        return maybeRestrictTwoNames(blindScope, left, leftType, leftIsRefineable ? merged.typeA : null, right, rightType, rightIsRefineable ? merged.typeB : null);
    }
    return blindScope;
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) TypePair(com.google.javascript.rhino.jstype.JSType.TypePair) CheckReturnValue(com.google.errorprone.annotations.CheckReturnValue)

Example 2 with TypePair

use of com.google.javascript.rhino.jstype.JSType.TypePair in project closure-compiler by google.

the class JSTypeTest method testGetTypeUnderEquality.

private void testGetTypeUnderEquality(JSType t1, JSType t2, JSType t1Eq, JSType t2Eq) {
    // creating the pairs
    TypePair p12 = t1.getTypesUnderEquality(t2);
    TypePair p21 = t2.getTypesUnderEquality(t1);
    // t1Eq
    assertTypeEquals(t1Eq, p12.typeA);
    assertTypeEquals(t1Eq, p21.typeB);
    // t2Eq
    assertTypeEquals(t2Eq, p12.typeB);
    assertTypeEquals(t2Eq, p21.typeA);
}
Also used : TypePair(com.google.javascript.rhino.jstype.JSType.TypePair)

Example 3 with TypePair

use of com.google.javascript.rhino.jstype.JSType.TypePair in project closure-compiler by google.

the class JSTypeTest method testGetTypesUnderInequality.

private void testGetTypesUnderInequality(JSType t1, JSType t2, JSType t1Eq, JSType t2Eq) {
    // creating the pairs
    TypePair p12 = t1.getTypesUnderInequality(t2);
    TypePair p21 = t2.getTypesUnderInequality(t1);
    // t1Eq
    assertTypeEquals(t1Eq, p12.typeA);
    assertTypeEquals(t1Eq, p21.typeB);
    // t2Eq
    assertTypeEquals(t2Eq, p12.typeB);
    assertTypeEquals(t2Eq, p21.typeA);
}
Also used : TypePair(com.google.javascript.rhino.jstype.JSType.TypePair)

Aggregations

TypePair (com.google.javascript.rhino.jstype.JSType.TypePair)3 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 JSType (com.google.javascript.rhino.jstype.JSType)1