Search in sources :

Example 26 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testTypeof2.

@Test
public void testTypeof2() {
    FlowScope[] blind = newScope();
    testBinop(blind, Token.EQ, new Node(Token.TYPEOF, createVar(blind, "a", getNativeAllType())), Node.newString("function"), ImmutableSet.of(new TypedName("a", getNativeFunctionType())), ImmutableSet.of(new TypedName("a", getNativeAllType())));
}
Also used : Node(com.google.javascript.rhino.Node) FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 27 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testTypeof3.

@Test
public void testTypeof3() {
    FlowScope[] blind = newScope();
    testBinop(blind, Token.EQ, new Node(Token.TYPEOF, createVar(blind, "a", getNativeObjectNumberStringBooleanType())), Node.newString("function"), ImmutableSet.of(new TypedName("a", getNativeFunctionType())), ImmutableSet.of(new TypedName("a", getNativeObjectNumberStringBooleanType())));
}
Also used : Node(com.google.javascript.rhino.Node) FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 28 with FlowScope

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

the class SemanticReverseAbstractInterpreterTest method testTypeof4.

@Test
public void testTypeof4() {
    FlowScope[] blind = newScope();
    testBinop(blind, Token.EQ, new Node(Token.TYPEOF, createVar(blind, "a", createUnionType(getNativeFunctionType(), getNativeNumberStringBooleanType()))), Node.newString("function"), ImmutableSet.of(new TypedName("a", getNativeFunctionType())), ImmutableSet.of(new TypedName("a", getNativeNumberStringBooleanType())));
}
Also used : Node(com.google.javascript.rhino.Node) FlowScope(com.google.javascript.jscomp.type.FlowScope) Test(org.junit.Test)

Example 29 with FlowScope

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

the class TypeInference method traverseTaggedTemplateLit.

private FlowScope traverseTaggedTemplateLit(Node tagTempLitNode, FlowScope originalScope) {
    checkArgument(tagTempLitNode.isTaggedTemplateLit(), tagTempLitNode);
    FlowScope scopeAfterChildren = traverseChildren(tagTempLitNode, originalScope);
    // A tagged template literal is really a special kind of function call.
    FlowScope scopeAfterExecution = setCallNodeTypeAfterChildrenTraversed(tagTempLitNode, scopeAfterChildren);
    if (tagTempLitNode.getJSType() == null) {
        tagTempLitNode.setJSType(unknownType);
    }
    return scopeAfterExecution;
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 30 with FlowScope

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

the class TypeInference method traverseCall.

private FlowScope traverseCall(Node callNode, FlowScope originalScope) {
    checkArgument(callNode.isCall() || callNode.isOptChainCall(), callNode);
    FlowScope scopeAfterChildren = traverseChildren(callNode, originalScope);
    FlowScope scopeAfterExecution = setCallNodeTypeAfterChildrenTraversed(callNode, scopeAfterChildren);
    // e.g. after `goog.assertString(x);` we can infer `x` is a string.
    return tightenTypesAfterAssertions(scopeAfterExecution, callNode);
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Aggregations

FlowScope (com.google.javascript.jscomp.type.FlowScope)60 Node (com.google.javascript.rhino.Node)20 Test (org.junit.Test)16 JSType (com.google.javascript.rhino.jstype.JSType)12 Token (com.google.javascript.rhino.Token)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 Branch (com.google.javascript.jscomp.ControlFlowGraph.Branch)1 AbstractScopedCallback (com.google.javascript.jscomp.NodeTraversal.AbstractScopedCallback)1 DiGraphEdge (com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge)1 Module (com.google.javascript.jscomp.modules.Module)1 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)1 ReverseAbstractInterpreter (com.google.javascript.jscomp.type.ReverseAbstractInterpreter)1 JSTypeResolver (com.google.javascript.rhino.jstype.JSTypeResolver)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1 StaticTypedScope (com.google.javascript.rhino.jstype.StaticTypedScope)1 TemplateType (com.google.javascript.rhino.jstype.TemplateType)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1