use of com.google.javascript.rhino.jstype.JSType 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);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testAddingMethodsUsingPrototypeIdiomComplexNamespace.
private void testAddingMethodsUsingPrototypeIdiomComplexNamespace(TypeCheckResult p) {
ObjectType goog = (ObjectType) p.scope.getVar("goog").getType();
assertEquals(NATIVE_PROPERTIES_COUNT + 2, goog.getPropertiesCount());
JSType googA = goog.getPropertyType("A");
assertNotNull(googA);
assertThat(googA).isInstanceOf(FunctionType.class);
FunctionType googAFunction = (FunctionType) googA;
ObjectType classA = googAFunction.getInstanceType();
assertEquals(NATIVE_PROPERTIES_COUNT + 2, classA.getPropertiesCount());
checkObjectType(classA, "m1", NUMBER_TYPE);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testTemplatizedTypeSubtypes2.
public void testTemplatizedTypeSubtypes2() {
JSType arrayOfNumber = createTemplatizedType(ARRAY_TYPE, NUMBER_TYPE);
JSType arrayOfString = createTemplatizedType(ARRAY_TYPE, STRING_TYPE);
assertFalse(arrayOfString.isSubtypeOf(createUnionType(arrayOfNumber, NULL_VOID)));
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testExtendFunction1.
public void testExtendFunction1() {
Node n = parseAndTypeCheck("/**@return {number}*/Function.prototype.f = " + "function() { return 1; };\n" + "(new Function()).f();");
JSType type = n.getLastChild().getLastChild().getJSType();
assertTypeEquals(NUMBER_TYPE, type);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testDontAddMethodsIfNoConstructor.
public void testDontAddMethodsIfNoConstructor() {
Node js1Node = parseAndTypeCheck("function A() {}" + "A.prototype = {m1: 5, m2: true}");
JSType functionAType = js1Node.getFirstChild().getJSType();
assertEquals("function(): undefined", functionAType.toString());
assertTypeEquals(UNKNOWN_TYPE, U2U_FUNCTION_TYPE.getPropertyType("m1"));
assertTypeEquals(UNKNOWN_TYPE, U2U_FUNCTION_TYPE.getPropertyType("m2"));
}
Aggregations