Search in sources :

Example 26 with JSType

use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.

the class TypeCheckTest method testGatherProperyWithoutAnnotation1.

public void testGatherProperyWithoutAnnotation1() {
    Node n = parseAndTypeCheck("/** @constructor */ var T = function() {};" + "/** @type {!T} */var t; t.x; t;");
    JSType type = n.getLastChild().getLastChild().getJSType();
    assertFalse(type.isUnknownType());
    assertThat(type).isInstanceOf(ObjectType.class);
    ObjectType objectType = (ObjectType) type;
    assertFalse(objectType.hasProperty("x"));
}
Also used : ObjectType(com.google.javascript.rhino.jstype.ObjectType) JSType(com.google.javascript.rhino.jstype.JSType) Node(com.google.javascript.rhino.Node)

Example 27 with JSType

use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.

the class TypeInferenceTest method testAssertNumber2.

public void testAssertNumber2() {
    // Make sure it ignores expressions.
    JSType startType = createNullableType(ALL_TYPE);
    assuming("x", startType);
    inFunction("goog.asserts.assertNumber(x + x); out1 = x;");
    verify("out1", startType);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Example 28 with JSType

use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.

the class TypeInferenceTest method testAssert8.

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

Example 29 with JSType

use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.

the class TypeInferenceTest method testIsDefAndNoResolvedType.

public void testIsDefAndNoResolvedType() {
    JSType startType = createUndefinableType(NO_RESOLVED_TYPE);
    assuming("x", startType);
    inFunction("out1 = x;" + "if (goog.isDef(x)) { out2a = x; out2b = x.length; out2c = x; }" + "out3 = x;" + "if (goog.isDef(x)) { out4 = x; }");
    verify("out1", startType);
    verify("out2a", NO_RESOLVED_TYPE);
    verify("out2b", CHECKED_UNKNOWN_TYPE);
    verify("out2c", NO_RESOLVED_TYPE);
    verify("out3", startType);
    verify("out4", NO_RESOLVED_TYPE);
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType)

Example 30 with JSType

use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.

the class TypeInferenceTest method testAssertElement.

public void testAssertElement() {
    JSType elementType = registry.createObjectType("Element", registry.getNativeObjectType(OBJECT_TYPE));
    assuming("x", elementType);
    inFunction("out1 = x; goog.asserts.assertElement(x); out2 = x;");
    verify("out1", elementType);
}
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