Search in sources :

Example 11 with TypeDeclarationNode

use of com.google.javascript.rhino.Node.TypeDeclarationNode in project closure-compiler by google.

the class TypeSyntaxTest method testArrayType.

public void testArrayType() {
    TypeDeclarationNode arrayOfString = arrayType(stringType());
    assertVarType("string[]", arrayOfString, "var foo: string[];");
    parse("var foo: string[][];");
}
Also used : TypeDeclarationNode(com.google.javascript.rhino.Node.TypeDeclarationNode)

Example 12 with TypeDeclarationNode

use of com.google.javascript.rhino.Node.TypeDeclarationNode in project closure-compiler by google.

the class TypeSyntaxTest method testUnionType.

public void testUnionType() {
    parse("var x: string | number[];");
    parse("var x: number[] | string;");
    parse("var x: Array<Foo> | number[];");
    parse("var x: (string | number)[];");
    Node ast = parse("var x: string | number[] | Array<Foo>;");
    TypeDeclarationNode union = (TypeDeclarationNode) (ast.getFirstFirstChild().getProp(Node.DECLARED_TYPE_EXPR));
    assertEquals(3, union.getChildCount());
}
Also used : TypeDeclarationNode(com.google.javascript.rhino.Node.TypeDeclarationNode) NodeSubject.assertNode(com.google.javascript.jscomp.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node) TypeDeclarationNode(com.google.javascript.rhino.Node.TypeDeclarationNode)

Example 13 with TypeDeclarationNode

use of com.google.javascript.rhino.Node.TypeDeclarationNode in project closure-compiler by google.

the class TypeSyntaxTest method testParameterizedType.

public void testParameterizedType() {
    TypeDeclarationNode parameterizedType = parameterizedType(namedType("my.parameterized.Type"), ImmutableList.of(namedType("ns.A"), namedType("ns.B")));
    assertVarType("parameterized type 2 args", parameterizedType, "var x: my.parameterized.Type<ns.A, ns.B>;");
    parse("var x: Foo<Bar<Baz>>;");
    parse("var x: A<B<C<D>>>;");
}
Also used : TypeDeclarationNode(com.google.javascript.rhino.Node.TypeDeclarationNode)

Aggregations

TypeDeclarationNode (com.google.javascript.rhino.Node.TypeDeclarationNode)13 Node (com.google.javascript.rhino.Node)5 NodeSubject.assertNode (com.google.javascript.jscomp.testing.NodeSubject.assertNode)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)2