Search in sources :

Example 6 with JSTypeRegistry

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());
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) NodeSubject.assertNode(com.google.javascript.jscomp.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node)

Example 7 with JSTypeRegistry

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

Example 8 with JSTypeRegistry

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_"));
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) NominalTypeBuilderOti(com.google.javascript.rhino.jstype.NominalTypeBuilderOti) Node(com.google.javascript.rhino.Node) FunctionType(com.google.javascript.rhino.jstype.FunctionType)

Example 9 with JSTypeRegistry

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

Aggregations

JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)9 JSType (com.google.javascript.rhino.jstype.JSType)3 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)3 Node (com.google.javascript.rhino.Node)2 NodeSubject.assertNode (com.google.javascript.jscomp.testing.NodeSubject.assertNode)1 SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 NominalTypeBuilderOti (com.google.javascript.rhino.jstype.NominalTypeBuilderOti)1