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);
}
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);
}
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);
}
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);
}
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("?");
}
Aggregations