Search in sources :

Example 31 with JSType

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);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Example 32 with JSType

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);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Example 33 with JSType

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"));
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Example 34 with JSType

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"));
}
Also used : ObjectType(com.google.javascript.rhino.jstype.ObjectType) JSType(com.google.javascript.rhino.jstype.JSType) FunctionType(com.google.javascript.rhino.jstype.FunctionType)

Example 35 with JSType

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());
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Aggregations

JSType (com.google.javascript.rhino.jstype.JSType)189 Node (com.google.javascript.rhino.Node)60 FunctionType (com.google.javascript.rhino.jstype.FunctionType)38 ObjectType (com.google.javascript.rhino.jstype.ObjectType)37 JSDocInfo (com.google.javascript.rhino.JSDocInfo)9 FlowScope (com.google.javascript.jscomp.type.FlowScope)7 TemplateType (com.google.javascript.rhino.jstype.TemplateType)6 TemplateTypeMap (com.google.javascript.rhino.jstype.TemplateTypeMap)5 UnionType (com.google.javascript.rhino.jstype.UnionType)4 ArrayList (java.util.ArrayList)4 EnumType (com.google.javascript.rhino.jstype.EnumType)3 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)3 TemplateTypeMapReplacer (com.google.javascript.rhino.jstype.TemplateTypeMapReplacer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Branch (com.google.javascript.jscomp.ControlFlowGraph.Branch)2 Scope (com.google.javascript.jscomp.Scope)2 Token (com.google.javascript.rhino.Token)2 FunctionBuilder (com.google.javascript.rhino.jstype.FunctionBuilder)2 TemplatizedType (com.google.javascript.rhino.jstype.TemplatizedType)2 HashMap (java.util.HashMap)2