diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-18 00:49:11 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-18 12:34:13 +0200 |
commit | d14ddb6461a14351e92eae9c73e22733ef19ab4e (patch) | |
tree | 1f03ac2d7c8c567f2cf6cfad85cf3d5d707e3675 /Libraries/LibJS/Parser.cpp | |
parent | 1806592d5819212c494146bd478b4c034f33514d (diff) | |
download | serenity-d14ddb6461a14351e92eae9c73e22733ef19ab4e.zip |
LibJS: Implement nullish coalescing operator (??)
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 18a1feecf3..41f9c137dd 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -601,6 +601,9 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre case TokenType::DoublePipe: consume(); return create_ast_node<LogicalExpression>(LogicalOp::Or, move(lhs), parse_expression(min_precedence, associativity)); + case TokenType::DoubleQuestionMark: + consume(); + return create_ast_node<LogicalExpression>(LogicalOp::NullishCoalescing, move(lhs), parse_expression(min_precedence, associativity)); case TokenType::QuestionMark: return parse_conditional_expression(move(lhs)); default: @@ -1039,7 +1042,8 @@ bool Parser::match_secondary_expression() const || type == TokenType::Pipe || type == TokenType::Caret || type == TokenType::DoubleAmpersand - || type == TokenType::DoublePipe; + || type == TokenType::DoublePipe + || type == TokenType::DoubleQuestionMark; } bool Parser::match_statement() const |