Search in sources :

Example 66 with ParseTree

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

the class Parser method parseReturnStatement.

// 12.9 The return Statement
private ParseTree parseReturnStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.RETURN);
    ParseTree expression = null;
    if (!peekImplicitSemiColon()) {
        expression = parseExpression();
    }
    eatPossiblyImplicitSemiColon();
    return new ReturnStatementTree(getTreeLocation(start), expression);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ReturnStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ReturnStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 67 with ParseTree

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

the class Parser method parseSetAccessor.

private ParseTree parseSetAccessor(PartialClassElement partial) {
    eatPredefinedString(PredefinedName.SET);
    if (peekPropertyName(0)) {
        Token propertyName = eatObjectLiteralPropertyName();
        FormalParameterListTree parameter = parseSetterParameterList();
        BlockTree body = parseFunctionBody();
        recordFeatureUsed(Feature.SETTER);
        return new SetAccessorTree(getTreeLocation(partial.start), propertyName, partial.isStatic, parameter, body);
    } else {
        ParseTree property = parseComputedPropertyName();
        FormalParameterListTree parameter = parseSetterParameterList();
        BlockTree body = parseFunctionBody();
        recordFeatureUsed(Feature.SETTER);
        return new ComputedPropertySetterTree(getTreeLocation(partial.start), property, partial.isStatic, parameter, body);
    }
}
Also used : SetAccessorTree(com.google.javascript.jscomp.parsing.parser.trees.SetAccessorTree) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ComputedPropertySetterTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertySetterTree)

Example 68 with ParseTree

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

the class Parser method parseExponentiationExpression.

private ParseTree parseExponentiationExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseUnaryExpression();
    if (peek(TokenType.STAR_STAR)) {
        // -x**y is a syntax error
        if (left.type == ParseTreeType.UNARY_EXPRESSION) {
            reportError("Unary operator '%s' requires parentheses before '**'", left.asUnaryExpression().operator);
        }
        Token operator = nextToken();
        ParseTree right = parseExponentiationExpression();
        return new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    } else {
        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 69 with ParseTree

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

the class Parser method parsePropertyAssignmentGenerator.

private ParseTree parsePropertyAssignmentGenerator() {
    TokenType type = peekType(1);
    if (type == TokenType.STRING || type == TokenType.NUMBER || type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) {
        // parseMethodDeclaration will consume the '*'.
        return parseMethodDeclaration();
    } else {
        SourcePosition start = getTreeStartLocation();
        eat(TokenType.STAR);
        ParseTree name = parseComputedPropertyName();
        FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION);
        parseFunctionTail(builder, FunctionFlavor.GENERATOR);
        ParseTree value = builder.build(getTreeLocation(start));
        return new ComputedPropertyMethodTree(getTreeLocation(start), name, value);
    }
}
Also used : FunctionDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ComputedPropertyMethodTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMethodTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 70 with ParseTree

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

the class Parser method completeArrowFunctionParseAtArrow.

private ParseTree completeArrowFunctionParseAtArrow(ParseTree leftOfArrow, Expression expressionIn) {
    FormalParameterListTree arrowFormalParameters = transformToArrowFormalParameters(leftOfArrow);
    if (peekImplicitSemiColon()) {
        reportError("No newline allowed before '=>'");
    }
    eat(TokenType.ARROW);
    ParseTree arrowFunctionBody = parseArrowFunctionBody(expressionIn, FunctionFlavor.NORMAL);
    FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.ARROW).setFormalParameterList(arrowFormalParameters).setFunctionBody(arrowFunctionBody);
    return builder.build(getTreeLocation(arrowFormalParameters.location.start));
}
Also used : FunctionDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) 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