Search in sources :

Example 6 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class CompilerTestCase method createTypeCheck.

/**
 * Returns a newly created TypeCheck.
 */
private static TypeCheck createTypeCheck(Compiler compiler) {
    ReverseAbstractInterpreter rai = new SemanticReverseAbstractInterpreter(compiler.getTypeRegistry());
    TypeCheck typeChecker = new TypeCheck(compiler, rai, compiler.getTypeRegistry());
    compiler.setTypeCheckingHasRun(true);
    return typeChecker;
}
Also used : ReverseAbstractInterpreter(com.google.javascript.jscomp.type.ReverseAbstractInterpreter) SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)

Example 7 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class TypeCheckTest method testTypeCheckStandaloneAST.

@Test
public void testTypeCheckStandaloneAST() {
    Node externs = IR.root();
    Node firstScript = compiler.parseTestCode("function Foo() { }");
    typeCheck(firstScript);
    Node root = IR.root(externs, IR.root(firstScript.detach()));
    TypedScopeCreator scopeCreator = new TypedScopeCreator(compiler);
    TypedScope topScope = scopeCreator.createScope(root, null);
    Node secondScript = compiler.parseTestCode("new Foo");
    firstScript.replaceWith(secondScript);
    new TypeCheck(compiler, new SemanticReverseAbstractInterpreter(registry), registry, topScope, scopeCreator).process(externs, secondScript.getParent());
    assertThat(compiler.getWarningCount()).isEqualTo(1);
    assertThat(compiler.getWarnings().get(0).getDescription()).isEqualTo("cannot instantiate non-constructor");
}
Also used : SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Aggregations

SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)7 Node (com.google.javascript.rhino.Node)4 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)3 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)3 HashSet (java.util.HashSet)2 TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)1 ChainableReverseAbstractInterpreter (com.google.javascript.jscomp.type.ChainableReverseAbstractInterpreter)1 ReverseAbstractInterpreter (com.google.javascript.jscomp.type.ReverseAbstractInterpreter)1 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)1 Before (org.junit.Before)1 Test (org.junit.Test)1