use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeInferenceTest method testAssert3.
public void testAssert3() {
JSType startType = createNullableType(OBJECT_TYPE);
assuming("x", startType);
assuming("y", startType);
inFunction("out1 = x; goog.asserts.assert(x && y); out2 = x; out3 = y;");
verify("out1", startType);
verify("out2", OBJECT_TYPE);
verify("out3", OBJECT_TYPE);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeInferenceTest method testAssertInstanceof4.
public void testAssertInstanceof4() {
JSType startType = registry.getNativeType(STRING_OBJECT_TYPE);
assuming("x", startType);
inFunction("out1 = x; goog.asserts.assertInstanceof(x, Object); out2 = x;");
verify("out1", startType);
verify("out2", STRING_OBJECT_TYPE);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypedScopeCreatorTest method testInferredObjectLitProperty1.
public void testInferredObjectLitProperty1() throws Exception {
testSame("var x = {prop: 3};");
TypedVar prop = globalScope.getVar("x.prop");
JSType propType = prop.getType();
assertEquals("number", propType.toString());
assertTrue(prop.isTypeInferred());
assertTrue(ObjectType.cast(globalScope.getVar("x").getType()).isPropertyTypeInferred("prop"));
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypedScopeCreatorTest method testStubsInExterns4.
public void testStubsInExterns4() {
testSame(externs("Extern.prototype.foo;" + "/** @constructor */ function Extern() {}"), srcs(""));
JSType e = globalScope.getVar("Extern").getType();
assertEquals("function(new:Extern): ?", e.toString());
ObjectType externProto = ((FunctionType) e).getPrototype();
assertTrue(globalScope.getRootNode().toStringTree(), externProto.hasOwnProperty("foo"));
assertTrue(externProto.isPropertyTypeInferred("foo"));
assertEquals("?", externProto.getPropertyType("foo").toString());
assertTrue(externProto.isPropertyInExterns("foo"));
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypedScopeCreatorTest method testDeclaredVar.
public void testDeclaredVar() throws Exception {
testSame("/** @type {?number} */ var x = 3; var y = x;");
TypedVar x = globalScope.getVar("x");
assertEquals("(null|number)", x.getType().toString());
assertFalse(x.isTypeInferred());
JSType y = findNameType("y", globalScope);
assertEquals("(null|number)", y.toString());
}
Aggregations