Search in sources :

Example 1 with IdentifierExpressionTree

use of com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree 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) && !Keywords.isTypeScriptSpecificKeyword(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)

Example 2 with IdentifierExpressionTree

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

the class Parser method parseIdentifierExpression.

private IdentifierExpressionTree parseIdentifierExpression() {
    SourcePosition start = getTreeStartLocation();
    IdentifierToken identifier = eatId();
    return new IdentifierExpressionTree(getTreeLocation(start), identifier);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) IdentifierExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)

Example 3 with IdentifierExpressionTree

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

the class Parser method parseObjectPatternField.

private ParseTree parseObjectPatternField(PatternKind kind) {
    SourcePosition start = getTreeStartLocation();
    if (peekType() == TokenType.OPEN_SQUARE) {
        ParseTree key = parseComputedPropertyName();
        eat(TokenType.COLON);
        ParseTree value = parsePatternAssignmentTarget(kind);
        return new ComputedPropertyDefinitionTree(getTreeLocation(start), key, value);
    }
    Token name;
    if (peekIdOrKeyword()) {
        name = eatIdOrKeywordAsId();
        if (!peek(TokenType.COLON)) {
            IdentifierToken idToken = (IdentifierToken) name;
            if (Keywords.isKeyword(idToken.value) && !Keywords.isTypeScriptSpecificKeyword(idToken.value)) {
                reportError("cannot use keyword '%s' here.", name);
            }
            if (peek(TokenType.EQUAL)) {
                IdentifierExpressionTree idTree = new IdentifierExpressionTree(getTreeLocation(start), idToken);
                eat(TokenType.EQUAL);
                ParseTree defaultValue = parseAssignmentExpression();
                return new DefaultParameterTree(getTreeLocation(start), idTree, defaultValue);
            }
            return new PropertyNameAssignmentTree(getTreeLocation(start), name, null);
        }
    } else {
        name = parseLiteralExpression().literalToken;
    }
    eat(TokenType.COLON);
    ParseTree value = parsePatternAssignmentTarget(kind);
    return new PropertyNameAssignmentTree(getTreeLocation(start), name, value);
}
Also used : ComputedPropertyDefinitionTree(com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyDefinitionTree) 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)

Example 4 with IdentifierExpressionTree

use of com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree 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(ParamContext.IMPLEMENTATION);
    } else {
        // async arg =>
        final IdentifierExpressionTree singleParameter = parseIdentifierExpression();
        arrowParameterList = new FormalParameterListTree(singleParameter.location, ImmutableList.<ParseTree>of(singleParameter));
    }
    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)

Aggregations

IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)4 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)4 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)3 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)2 PropertyNameAssignmentTree (com.google.javascript.jscomp.parsing.parser.trees.PropertyNameAssignmentTree)2 ComputedPropertyDefinitionTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyDefinitionTree)1 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)1 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)1