Search in sources :

Example 96 with ParseTree

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

the class Parser method parseWhileStatement.

// 12.6.2 The while Statement
private ParseTree parseWhileStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.WHILE);
    eat(TokenType.OPEN_PAREN);
    ParseTree condition = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    ParseTree body = parseStatement();
    return new WhileStatementTree(getTreeLocation(start), condition, body);
}
Also used : DoWhileStatementTree(com.google.javascript.jscomp.parsing.parser.trees.DoWhileStatementTree) WhileStatementTree(com.google.javascript.jscomp.parsing.parser.trees.WhileStatementTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 97 with ParseTree

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

the class Parser method parseAsyncArrowFunction.

private ParseTree parseAsyncArrowFunction(Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    eatPredefinedString(ASYNC);
    if (peekImplicitSemiColon()) {
        reportError("No newline allowed between `async` and arrow function parameter list");
    }
    FormalParameterListTree arrowParameterList = null;
    if (peek(TokenType.OPEN_PAREN)) {
        // async (...) =>
        arrowParameterList = parseFormalParameterList();
    } else {
        // async arg =>
        final IdentifierExpressionTree singleParameter = parseIdentifierExpression();
        arrowParameterList = new FormalParameterListTree(singleParameter.location, ImmutableList.<ParseTree>of(singleParameter), /* hasTrailingComma= */
        false, ImmutableList.<SourcePosition>of());
    }
    if (peekImplicitSemiColon()) {
        reportError("No newline allowed before '=>'");
    }
    eat(TokenType.ARROW);
    ParseTree arrowFunctionBody = parseArrowFunctionBody(expressionIn, FunctionFlavor.ASYNCHRONOUS);
    FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.ARROW).setAsync(true).setFormalParameterList(arrowParameterList).setFunctionBody(arrowFunctionBody);
    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) IdentifierExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 98 with ParseTree

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

the class Parser method parseVariableDeclaration.

private VariableDeclarationTree parseVariableDeclaration(final TokenType binding, Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    ParseTree lvalue;
    if (peekPatternStart()) {
        lvalue = parsePattern(PatternKind.INITIALIZER);
    } else {
        lvalue = parseIdentifierExpression();
    }
    ParseTree initializer = null;
    if (peek(TokenType.EQUAL)) {
        initializer = parseInitializer(expressionIn);
    } else if (expressionIn != Expression.NO_IN) {
        // NOTE(blickly): this is a bit of a hack, declarations outside of for statements allow "in",
        // and by chance, also must have initializers for const/destructuring. Vanilla for loops
        // also require intializers, but are handled separately in checkVanillaForInitializers
        maybeReportNoInitializer(binding, lvalue);
    }
    return new VariableDeclarationTree(getTreeLocation(start), lvalue, initializer);
}
Also used : VariableDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.VariableDeclarationTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 99 with ParseTree

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

the class Parser method parseFieldDefinition.

private ParseTree parseFieldDefinition(PartialClassElement partial) {
    ParseTree initializer = null;
    if (peek(TokenType.EQUAL)) {
        initializer = parseInitializer(Expression.NORMAL);
    }
    eatPossiblyImplicitSemiColon();
    if (partial.getName() != null) {
        checkState(partial.getNameExpr() == null);
        return new FieldDeclarationTree(getTreeLocation(partial.start), partial.getName(), partial.isStatic, initializer);
    } else {
        return new ComputedPropertyFieldTree(getTreeLocation(partial.start), partial.getNameExpr(), partial.isStatic, initializer);
    }
}
Also used : FieldDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.FieldDeclarationTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ComputedPropertyFieldTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyFieldTree)

Example 100 with ParseTree

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

the class Parser method parseArrowFunctionBody.

private ParseTree parseArrowFunctionBody(Expression expressionIn, FunctionFlavor functionFlavor) {
    functionContextStack.addLast(functionFlavor);
    ParseTree arrowFunctionBody;
    if (peek(TokenType.OPEN_CURLY)) {
        arrowFunctionBody = parseFunctionBody();
    } else {
        arrowFunctionBody = parseAssignment(expressionIn);
    }
    functionContextStack.removeLast();
    return arrowFunctionBody;
}
Also used : 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