Search in sources :

Example 1 with ArgumentListTree

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

the class Parser method parseArguments.

private ArgumentListTree parseArguments() {
    // ArgumentList :
    // AssignmentOrSpreadExpression
    // ArgumentList , AssignmentOrSpreadExpression
    // 
    // AssignmentOrSpreadExpression :
    // ... AssignmentExpression
    // AssignmentExpression
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> arguments = ImmutableList.builder();
    eat(TokenType.OPEN_PAREN);
    while (peekAssignmentOrSpread()) {
        arguments.add(parseAssignmentOrSpread());
        if (!peek(TokenType.CLOSE_PAREN)) {
            Token comma = eat(TokenType.COMMA);
            if (peek(TokenType.CLOSE_PAREN)) {
                features = features.with(Feature.TRAILING_COMMA_IN_PARAM_LIST);
                if (!config.atLeast8) {
                    reportError(comma, "Invalid trailing comma in arguments list");
                }
            }
        }
    }
    eat(TokenType.CLOSE_PAREN);
    return new ArgumentListTree(getTreeLocation(start), arguments.build());
}
Also used : ArgumentListTree(com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 2 with ArgumentListTree

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

the class Parser method parseLeftHandSideExpression.

// 11.2 Left hand side expression
// 
// Also inlines the call expression productions
@SuppressWarnings("incomplete-switch")
private ParseTree parseLeftHandSideExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree operand = parseNewExpression();
    // this test is equivalent to is member expression
    if (!(operand instanceof NewExpressionTree) || ((NewExpressionTree) operand).arguments != null) {
        // The Call expression productions
        while (peekCallSuffix()) {
            switch(peekType()) {
                case OPEN_PAREN:
                    ArgumentListTree arguments = parseArguments();
                    operand = new CallExpressionTree(getTreeLocation(start), operand, arguments);
                    break;
                case OPEN_SQUARE:
                    eat(TokenType.OPEN_SQUARE);
                    ParseTree member = parseExpression();
                    eat(TokenType.CLOSE_SQUARE);
                    operand = new MemberLookupExpressionTree(getTreeLocation(start), operand, member);
                    break;
                case PERIOD:
                    eat(TokenType.PERIOD);
                    IdentifierToken id = eatIdOrKeywordAsId();
                    operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
                    break;
                case NO_SUBSTITUTION_TEMPLATE:
                case TEMPLATE_HEAD:
                    operand = parseTemplateLiteral(operand);
                    break;
                default:
                    throw new AssertionError("unexpected case: " + peekType());
            }
        }
    }
    return operand;
}
Also used : CallExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.CallExpressionTree) ArgumentListTree(com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) MemberExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MemberExpressionTree) NewExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.NewExpressionTree) MemberLookupExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MemberLookupExpressionTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)2 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)2 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)2 ImmutableList (com.google.common.collect.ImmutableList)1 CallExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.CallExpressionTree)1 MemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.MemberExpressionTree)1 MemberLookupExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.MemberLookupExpressionTree)1 NewExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.NewExpressionTree)1