Search in sources :

Example 76 with ParseTree

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

the class Parser method parseObjectPattern.

// Pattern ::= "{" (Field ("," Field)* ","?)? "}" | ...
private ParseTree parseObjectPattern(PatternKind kind) {
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> fields = ImmutableList.builder();
    eat(TokenType.OPEN_CURLY);
    while (peekObjectPatternField()) {
        fields.add(parseObjectPatternField(kind));
        if (peek(TokenType.COMMA)) {
            // Consume the comma separator
            eat(TokenType.COMMA);
        } else {
            // Otherwise we must be done
            break;
        }
    }
    if (peek(TokenType.ELLIPSIS)) {
        recordFeatureUsed(Feature.OBJECT_PATTERN_REST);
        SourcePosition restStart = getTreeStartLocation();
        eat(TokenType.ELLIPSIS);
        ParseTree patternAssignmentTarget = parseRestAssignmentTarget(kind);
        fields.add(new ObjectRestTree(getTreeLocation(restStart), patternAssignmentTarget));
    }
    eat(TokenType.CLOSE_CURLY);
    return new ObjectPatternTree(getTreeLocation(start), fields.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ObjectRestTree(com.google.javascript.jscomp.parsing.parser.trees.ObjectRestTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ObjectPatternTree(com.google.javascript.jscomp.parsing.parser.trees.ObjectPatternTree)

Example 77 with ParseTree

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

the class Parser method parseComprehensionFor.

private ParseTree parseComprehensionFor() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.FOR);
    eat(TokenType.OPEN_PAREN);
    ParseTree initializer;
    if (peekId()) {
        initializer = parseIdentifierExpression();
    } else {
        initializer = parsePattern(PatternKind.ANY);
    }
    eatPredefinedString(PredefinedName.OF);
    ParseTree collection = parseAssignmentExpression();
    eat(TokenType.CLOSE_PAREN);
    return new ComprehensionForTree(getTreeLocation(start), initializer, collection);
}
Also used : ComprehensionForTree(com.google.javascript.jscomp.parsing.parser.trees.ComprehensionForTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 78 with ParseTree

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

the class Parser method parseForInStatement.

// 12.6.4 The for-in Statement
private ParseTree parseForInStatement(SourcePosition start, ParseTree initializer) {
    eat(TokenType.IN);
    ParseTree collection = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    ParseTree body = parseStatement();
    return new ForInStatementTree(getTreeLocation(start), initializer, collection, body);
}
Also used : ForInStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ForInStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 79 with ParseTree

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

the class Parser method parseIfStatement.

// 12.5 If Statement
private IfStatementTree parseIfStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.IF);
    eat(TokenType.OPEN_PAREN);
    ParseTree condition = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    ParseTree ifClause = parseStatement();
    ParseTree elseClause = null;
    if (peek(TokenType.ELSE)) {
        eat(TokenType.ELSE);
        elseClause = parseStatement();
    }
    return new IfStatementTree(getTreeLocation(start), condition, ifClause, elseClause);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) IfStatementTree(com.google.javascript.jscomp.parsing.parser.trees.IfStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 80 with ParseTree

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

the class Parser method parseAssignment.

private ParseTree parseAssignment(Expression expressionIn) {
    if (peek(TokenType.YIELD) && inGeneratorContext()) {
        return parseYield(expressionIn);
    }
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseConditional(expressionIn);
    if (isStartOfAsyncArrowFunction(left)) {
        // re-evaluate as an async arrow function.
        resetScanner(left);
        return parseAsyncArrowFunction(expressionIn);
    }
    if (peek(TokenType.ARROW)) {
        return completeAssignmentExpressionParseAtArrow(left, expressionIn);
    }
    if (peekAssignmentOperator()) {
        left = transformLeftHandSideExpression(left);
        if (!left.isValidAssignmentTarget()) {
            reportError("invalid assignment target");
            return new MissingPrimaryExpressionTree(getTreeLocation(getTreeStartLocation()));
        }
        Token operator = nextToken();
        ParseTree right = parseAssignment(expressionIn);
        return new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    }
    return left;
}
Also used : MissingPrimaryExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BinaryOperatorTree(com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)100 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)81 ImmutableList (com.google.common.collect.ImmutableList)15 BinaryOperatorTree (com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree)14 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)9 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)6 BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)5 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)5 SourceRange (com.google.javascript.jscomp.parsing.parser.util.SourceRange)5 ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)4 ComputedPropertyMethodTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMethodTree)4 OptionalMemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberExpressionTree)4 OptionalMemberLookupExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberLookupExpressionTree)4 ComputedPropertyMemberVariableTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMemberVariableTree)3 GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)3 IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)3 NullTree (com.google.javascript.jscomp.parsing.parser.trees.NullTree)3 OptChainCallExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptChainCallExpressionTree)3 CommaExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree)2 DoWhileStatementTree (com.google.javascript.jscomp.parsing.parser.trees.DoWhileStatementTree)2