Search in sources :

Example 1 with UnionTypeTree

use of com.google.javascript.jscomp.parsing.parser.trees.UnionTypeTree in project closure-compiler by google.

the class Parser method parseType.

private ParseTree parseType() {
    SourcePosition start = getTreeStartLocation();
    if (!peekId() && !EnumSet.of(TokenType.VOID, TokenType.OPEN_PAREN, TokenType.OPEN_CURLY, TokenType.TYPEOF).contains(peekType())) {
        reportError("Unexpected token '%s' in type expression", peekType());
        return new TypeNameTree(getTreeLocation(start), ImmutableList.of("error"));
    }
    ParseTree typeExpression = parseFunctionTypeExpression();
    if (!peek(TokenType.BAR)) {
        return typeExpression;
    }
    ImmutableList.Builder<ParseTree> unionType = ImmutableList.builder();
    unionType.add(typeExpression);
    do {
        eat(TokenType.BAR);
        unionType.add(parseArrayTypeExpression());
    } while (peek(TokenType.BAR));
    return new UnionTypeTree(getTreeLocation(start), unionType.build());
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) UnionTypeTree(com.google.javascript.jscomp.parsing.parser.trees.UnionTypeTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)1 TypeNameTree (com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree)1 UnionTypeTree (com.google.javascript.jscomp.parsing.parser.trees.UnionTypeTree)1 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)1