use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testExtendFunction1.
@Test
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(getNativeNumberType(), type);
}
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();
assertHasXMorePropertiesThanNativeObject(goog, 1);
JSType googA = goog.getPropertyType("A");
assertThat(googA).isNotNull();
assertThat(googA).isInstanceOf(FunctionType.class);
FunctionType googAFunction = (FunctionType) googA;
ObjectType classA = googAFunction.getInstanceType();
assertHasXMorePropertiesThanNativeObject(classA, 1);
checkObjectType(classA, "m1", getNativeNumberType());
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testExtendFunction2.
@Test
public void testExtendFunction2() {
Node n = parseAndTypeCheck("/**@return {number}*/Function.prototype.f = " + "function() { return 1; };\n" + "(function() {}).f();");
JSType type = n.getLastChild().getLastChild().getJSType();
assertTypeEquals(getNativeNumberType(), type);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeCheckTest method testDontAddMethodsIfNoConstructor.
@Test
public void testDontAddMethodsIfNoConstructor() {
Node js1Node = parseAndTypeCheck("function A() {}" + "A.prototype = {m1: 5, m2: true}");
JSType functionAType = js1Node.getFirstChild().getJSType();
assertThat(functionAType.toString()).isEqualTo("function(): undefined");
assertTypeEquals(getNativeUnknownType(), getNativeFunctionType().getPropertyType("m1"));
assertTypeEquals(getNativeUnknownType(), getNativeFunctionType().getPropertyType("m2"));
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypedScopeCreatorTest method testInferredObjectLitProperty2.
@Test
public void testInferredObjectLitProperty2() {
testSame("var x = {prop: function(){}};");
TypedVar prop = globalScope.getVar("x.prop");
JSType propType = prop.getType();
assertThat(propType.toString()).isEqualTo("function(): undefined");
assertThat(prop.isTypeInferred()).isTrue();
assertThat(ObjectType.cast(globalScope.getVar("x").getType()).isPropertyTypeInferred("prop")).isTrue();
}
Aggregations