Search in sources :

Example 1 with ObjectRestTree

use of com.google.javascript.jscomp.parsing.parser.trees.ObjectRestTree 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)

Aggregations

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