Search in sources :

Example 51 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseFunctionTypeExpression.

private ParseTree parseFunctionTypeExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree typeExpression = null;
    if (peekFunctionTypeExpression()) {
        FormalParameterListTree formalParameterList;
        formalParameterList = parseFormalParameterList(ParamContext.IMPLEMENTATION);
        eat(TokenType.ARROW);
        ParseTree returnType = parseType();
        typeExpression = new FunctionTypeTree(getTreeLocation(start), formalParameterList, returnType);
    } else {
        typeExpression = parseArrayTypeExpression();
    }
    return typeExpression;
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) FunctionTypeTree(com.google.javascript.jscomp.parsing.parser.trees.FunctionTypeTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)

Example 52 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseArrayTypeExpression.

private ParseTree parseArrayTypeExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree typeExpression = parseParenTypeExpression();
    while (!peekImplicitSemiColon() && peek(TokenType.OPEN_SQUARE)) {
        eat(TokenType.OPEN_SQUARE);
        eat(TokenType.CLOSE_SQUARE);
        typeExpression = new ArrayTypeTree(getTreeLocation(start), typeExpression);
    }
    return typeExpression;
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ArrayTypeTree(com.google.javascript.jscomp.parsing.parser.trees.ArrayTypeTree)

Example 53 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method maybeParseGenericTypes.

private GenericTypeListTree maybeParseGenericTypes() {
    if (!peek(TokenType.OPEN_ANGLE)) {
        return null;
    }
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_ANGLE);
    scanner.incTypeParameterLevel();
    LinkedHashMap<IdentifierToken, ParseTree> types = new LinkedHashMap<>();
    do {
        IdentifierToken name = eatId();
        ParseTree bound = null;
        if (peek(TokenType.EXTENDS)) {
            eat(TokenType.EXTENDS);
            bound = parseType();
        }
        types.put(name, bound);
        if (peek(TokenType.COMMA)) {
            eat(TokenType.COMMA);
        }
    } while (peekId());
    eat(TokenType.CLOSE_ANGLE);
    scanner.decTypeParameterLevel();
    return new GenericTypeListTree(getTreeLocation(start), types);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseTypeReference.

private ParseTree parseTypeReference() {
    SourcePosition start = getTreeStartLocation();
    TypeNameTree typeName = parseTypeName();
    if (!peek(TokenType.OPEN_ANGLE)) {
        return typeName;
    }
    return parseTypeArgumentList(start, typeName);
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 55 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseIndexSignature.

private IndexSignatureTree parseIndexSignature() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_SQUARE);
    IdentifierToken name = eatIdOrKeywordAsId();
    eat(TokenType.COLON);
    // must be 'string' or 'number'
    ParseTree indexType = parseTypeName();
    eat(TokenType.CLOSE_SQUARE);
    eat(TokenType.COLON);
    ParseTree declaredType = parseType();
    ParseTree nameTree = new MemberVariableTree(getTreeLocation(start), name, false, false, null, indexType);
    return new IndexSignatureTree(getTreeLocation(start), nameTree, declaredType);
}
Also used : IndexSignatureTree(com.google.javascript.jscomp.parsing.parser.trees.IndexSignatureTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ComputedPropertyMemberVariableTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMemberVariableTree) MemberVariableTree(com.google.javascript.jscomp.parsing.parser.trees.MemberVariableTree)

Aggregations

SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)112 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)81 ImmutableList (com.google.common.collect.ImmutableList)15 BinaryOperatorTree (com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree)13 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)7 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)6 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)5 ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)4 BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)4 IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)4 MissingPrimaryExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree)4 OptionalMemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberExpressionTree)4 OptionalMemberLookupExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberLookupExpressionTree)4 ArrayLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ArrayLiteralExpressionTree)3 GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)3 ObjectLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ObjectLiteralExpressionTree)3 OptChainCallExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptChainCallExpressionTree)3 TemplateLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.TemplateLiteralExpressionTree)3 VariableDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.VariableDeclarationTree)3 FormatString (com.google.errorprone.annotations.FormatString)2