Search in sources :

Example 76 with JSType

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

the class TypeInferenceTest method testAssert8.

@Test
public void testAssert8() {
    JSType startType = createNullableType(OBJECT_TYPE);
    assuming("x", startType);
    inFunction("out1 = x; out2 = goog.asserts.assert(x != null);");
    verify("out1", startType);
    verify("out2", BOOLEAN_TYPE);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Test(org.junit.Test)

Example 77 with JSType

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

the class TypeInferenceTest method testAssertNumber_narrowsAllTypeToNumber.

@Test
public void testAssertNumber_narrowsAllTypeToNumber() {
    JSType startType = createNullableType(ALL_TYPE);
    includeGoogAssertionFn("assertNumber", getNativeType(NUMBER_TYPE));
    assuming("x", startType);
    inFunction("out1 = x; goog.asserts.assertNumber(x); out2 = x;");
    verify("out1", startType);
    verify("out2", NUMBER_TYPE);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Test(org.junit.Test)

Example 78 with JSType

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

the class TypeInferenceTest method testDynamicImport.

@Test
public void testDynamicImport() {
    inScript("const foo = import('foo');");
    JSType promiseOfUnknownType = registry.createTemplatizedType(registry.getNativeObjectType(JSTypeNative.PROMISE_TYPE), registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));
    assertType(getType("foo")).isSubtypeOf(promiseOfUnknownType);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Test(org.junit.Test)

Example 79 with JSType

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

the class TypeInferenceTest method testPrimitiveAssertTruthy_narrowsNullableObjectToObject.

@Test
public void testPrimitiveAssertTruthy_narrowsNullableObjectToObject() {
    JSType startType = createNullableType(OBJECT_TYPE);
    includePrimitiveTruthyAssertionFunction("assertTruthy");
    assuming("x", startType);
    inFunction("out1 = x; assertTruthy(x); out2 = x;");
    verify("out1", startType);
    verify("out2", OBJECT_TYPE);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Test(org.junit.Test)

Example 80 with JSType

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

the class TypeInferenceTest method testObjectDestructuringDeclarationInferenceWithUnknownProperty.

@Test
public void testObjectDestructuringDeclarationInferenceWithUnknownProperty() {
    JSType recordType = registry.createRecordType(ImmutableMap.of());
    assuming("obj", recordType);
    inFunction(lines(// preserve newline
    "let {x} = obj; ", "X: x;"));
    assertTypeOfExpression("X").toStringIsEqualTo("?");
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Test(org.junit.Test)

Aggregations

JSType (com.google.javascript.rhino.jstype.JSType)447 Test (org.junit.Test)182 Node (com.google.javascript.rhino.Node)158 FunctionType (com.google.javascript.rhino.jstype.FunctionType)71 ObjectType (com.google.javascript.rhino.jstype.ObjectType)71 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)30 JSDocInfo (com.google.javascript.rhino.JSDocInfo)19 TemplateType (com.google.javascript.rhino.jstype.TemplateType)14 FlowScope (com.google.javascript.jscomp.type.FlowScope)13 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)11 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)9 UnionType (com.google.javascript.rhino.jstype.UnionType)9 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)8 TemplateTypeMap (com.google.javascript.rhino.jstype.TemplateTypeMap)8 LinkedHashMap (java.util.LinkedHashMap)8 ImmutableList (com.google.common.collect.ImmutableList)7 Color (com.google.javascript.jscomp.colors.Color)7 StaticTypedSlot (com.google.javascript.rhino.jstype.StaticTypedSlot)7 ArrayList (java.util.ArrayList)7 ImmutableMap (com.google.common.collect.ImmutableMap)6