Search in sources :

Example 31 with SourcePosition

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

the class Parser method parseAsyncFunctionDeclaration.

private ParseTree parseAsyncFunctionDeclaration() {
    SourcePosition start = getTreeStartLocation();
    eatAsyncFunctionStart();
    boolean generator = peek(TokenType.STAR);
    if (generator) {
        eat(TokenType.STAR);
    }
    FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId()).setAsync(true);
    parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
    return builder.build(getTreeLocation(start));
}
Also used : FunctionDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 32 with SourcePosition

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

the class Parser method parsePatternAssignmentTarget.

/**
 * A PatternAssignmentTarget is the location where the assigned value gets stored, including an
 * optional default value.
 *
 * <dl>
 *   <dt>Spec AssignmentElement === PatternAssignmentTarget(PatternKind.ANY)
 *   <dd>Valid in an assignment that is not a formal parameter list or variable declaration.
 *       Sub-patterns and arbitrary left hand side expressions are allowed.
 *   <dt>Spec BindingElement === PatternAssignmentElement(PatternKind.INITIALIZER)
 *   <dd>Valid in a formal parameter list or variable declaration statement. Only sub-patterns and
 *       identifiers are allowed.
 * </dl>
 *
 * Examples:
 *
 * <pre>
 *   <code>
 *     [a, {foo: b = 'default'}] = someArray;          // valid
 *     [x.a, {foo: x.b = 'default'}] = someArray;      // valid
 *
 *     let [a, {foo: b = 'default'}] = someArray;      // valid
 *     let [x.a, {foo: x.b = 'default'}] = someArray;  // invalid
 *
 *     function f([a, {foo: b = 'default'}]) {...}     // valid
 *     function f([x.a, {foo: x.b = 'default'}]) {...} // invalid
 *   </code>
 * </pre>
 */
private ParseTree parsePatternAssignmentTarget(PatternKind patternKind) {
    SourcePosition start = getTreeStartLocation();
    ParseTree assignmentTarget;
    assignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind);
    if (peek(TokenType.EQUAL)) {
        eat(TokenType.EQUAL);
        ParseTree defaultValue = parseAssignmentExpression();
        assignmentTarget = new DefaultParameterTree(getTreeLocation(start), assignmentTarget, defaultValue);
    }
    return assignmentTarget;
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) DefaultParameterTree(com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 33 with SourcePosition

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

the class Parser method parseDoWhileStatement.

// 12.6 Iteration Statements
// 12.6.1 The do-while Statement
private ParseTree parseDoWhileStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.DO);
    ParseTree body = parseStatement();
    eat(TokenType.WHILE);
    eat(TokenType.OPEN_PAREN);
    ParseTree condition = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    // The semicolon after the "do-while" is optional.
    if (peek(TokenType.SEMI_COLON)) {
        eat(TokenType.SEMI_COLON);
    }
    return new DoWhileStatementTree(getTreeLocation(start), body, condition);
}
Also used : DoWhileStatementTree(com.google.javascript.jscomp.parsing.parser.trees.DoWhileStatementTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 34 with SourcePosition

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

the class Parser method parseLogicalOR.

// 11.11 Logical OR
private ParseTree parseLogicalOR(Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseLogicalAND(expressionIn);
    while (peek(TokenType.OR)) {
        Token operator = eat(TokenType.OR);
        ParseTree right = parseLogicalAND(expressionIn);
        left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    }
    return left;
}
Also used : 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)

Example 35 with SourcePosition

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

the class Parser method parsePropertyNameAssignment.

private ParseTree parsePropertyNameAssignment() {
    SourcePosition start = getTreeStartLocation();
    Token name = eatObjectLiteralPropertyName();
    Token colon = eatOpt(TokenType.COLON);
    if (colon == null) {
        if (name.type != TokenType.IDENTIFIER) {
            reportExpectedError(peekToken(), TokenType.COLON);
        } else if (Keywords.isKeyword(name.asIdentifier().value)) {
            reportError(name, "Cannot use keyword in short object literal");
        } else if (peek(TokenType.EQUAL)) {
            IdentifierExpressionTree idTree = new IdentifierExpressionTree(getTreeLocation(start), (IdentifierToken) name);
            eat(TokenType.EQUAL);
            ParseTree defaultValue = parseAssignmentExpression();
            return new DefaultParameterTree(getTreeLocation(start), idTree, defaultValue);
        }
    }
    ParseTree value = colon == null ? null : parseAssignmentExpression();
    return new PropertyNameAssignmentTree(getTreeLocation(start), name, value);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) DefaultParameterTree(com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree) IdentifierExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree) PropertyNameAssignmentTree(com.google.javascript.jscomp.parsing.parser.trees.PropertyNameAssignmentTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

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