use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class ExpressionDecomposerTest method processForTypecheck.
private void processForTypecheck(AbstractCompiler compiler, Node jsRoot) {
Node scriptRoot = IR.root(jsRoot);
compiler.setMostRecentTypechecker(MostRecentTypechecker.OTI);
JSTypeRegistry registry = compiler.getTypeRegistry();
(new TypeCheck(compiler, new SemanticReverseAbstractInterpreter(registry), registry)).processForTesting(null, scriptRoot.getFirstChild());
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class TypeValidatorTest method testFunctionMismatch.
public void testFunctionMismatch() throws Exception {
testWarning("/** \n" + " * @param {function(string): number} x \n" + " * @return {function(boolean): string} \n" + " */ function f(x) { return x; }", TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = getLastCompiler().getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(string, bool);
assertMismatches(ImmutableList.of(new TypeMismatch(firstFunction, secondFunction, null), fromNatives(STRING_TYPE, BOOLEAN_TYPE), fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class ClosureCodingConventionTest method testApplySubclassRelationship.
public void testApplySubclassRelationship() {
JSTypeRegistry registry = new JSTypeRegistry(null);
Node nodeA = new Node(Token.FUNCTION);
FunctionType ctorA = registry.createConstructorType("A", nodeA, new Node(Token.PARAM_LIST), null, null, false);
Node nodeB = new Node(Token.FUNCTION);
FunctionType ctorB = registry.createConstructorType("B", nodeB, new Node(Token.PARAM_LIST), null, null, false);
conv.applySubclassRelationship(new NominalTypeBuilderOti(ctorA, ctorA.getInstanceType()), new NominalTypeBuilderOti(ctorB, ctorB.getInstanceType()), SubclassType.INHERITS);
assertTrue(ctorB.getPrototype().hasOwnProperty("constructor"));
assertEquals(nodeB, ctorB.getPrototype().getPropertyNode("constructor"));
assertTrue(ctorB.hasOwnProperty("superClass_"));
assertEquals(nodeB, ctorB.getPropertyNode("superClass_"));
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class NodeTest method testCheckTreeTypeAwareEqualsDifferent.
public void testCheckTreeTypeAwareEqualsDifferent() {
TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
Node node1 = Node.newString(Token.NAME, "f");
node1.setJSType(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
Node node2 = Node.newString(Token.NAME, "f");
node2.setJSType(registry.getNativeType(JSTypeNative.STRING_TYPE));
assertFalse(node1.isEquivalentToTyped(node2));
}
Aggregations