use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class PartialCompilationTest method testUnresolvedBaseClassDoesNotHideFields.
public void testUnresolvedBaseClassDoesNotHideFields() throws Exception {
assertPartialCompilationSucceeds("/** @constructor @extends {MissingBase} */", "var Klass = function () {", " /** @type {string} */", " this.foo;", "};");
TypedVar x = compiler.getTopScope().getSlot("Klass");
JSType type = x.getType();
assertThat(type.isFunctionType()).isTrue();
FunctionType fType = (FunctionType) type;
assertThat(fType.getTypeOfThis().hasProperty("foo")).isTrue();
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeInferenceTest method testAssertObject5.
public void testAssertObject5() {
JSType startType = createNullableType(ALL_TYPE);
assuming("x", startType);
inFunction("out1 = x;" + "out2 = /** @type {!Array} */ (goog.asserts.assertObject(x));");
verify("out1", startType);
verify("out2", ARRAY_TYPE);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeMatchingStrategyTest method assertMatch.
private static void assertMatch(TypeMatchingStrategy typeMatchingStrategy, String templateType, String type, boolean isMatch, boolean isLooseMatch) {
// It's important that the test uses the same compiler to compile the template type and the
// type to be matched. Otherwise, equal types won't be considered equal.
Compiler compiler = new Compiler();
compiler.disableThreads();
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.setCheckTypes(true);
compiler.compile(ImmutableList.of(SourceFile.fromCode("externs", EXTERNS)), ImmutableList.of(SourceFile.fromCode("test", String.format("/** @type {%s} */ var x; /** @type {%s} */ var y;", templateType, type))), options);
Node script = compiler.getRoot().getLastChild().getFirstChild();
Node xNode = script.getFirstChild();
Node yNode = script.getLastChild();
JSType templateJsType = xNode.getFirstChild().getJSType();
JSType jsType = yNode.getFirstChild().getJSType();
MatchResult matchResult = typeMatchingStrategy.match(templateJsType, jsType);
assertEquals(isMatch ? "'" + templateJsType + "' should match '" + jsType + "'" : "'" + templateType + "' should not match '" + type + "'", isMatch, matchResult.isMatch());
assertEquals(isLooseMatch ? "'" + templateType + "' should loosely match '" + type + "'" : "'" + templateType + "' should not loosely match '" + type + "'", isLooseMatch, matchResult.isLooseMatch());
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeInferenceTest method testAssertNumber3.
public void testAssertNumber3() {
// Make sure it ignores expressions.
JSType startType = createNullableType(ALL_TYPE);
assuming("x", startType);
inFunction("out1 = x; out2 = goog.asserts.assertNumber(x + x);");
verify("out1", startType);
verify("out2", NUMBER_TYPE);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeInferenceTest method testAssert5.
public void testAssert5() {
JSType startType = createNullableType(OBJECT_TYPE);
assuming("x", startType);
assuming("y", startType);
inFunction("goog.asserts.assert(x || y); out1 = x; out2 = y;");
verify("out1", startType);
verify("out2", startType);
}
Aggregations