1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

LibJS: Implement update expressions

Note that currently only the non-prefixed variant is supported (i.e i++
not ++i), this variant returns the value of the argument before the
update.
This commit is contained in:
0xtechnobabble 2020-03-12 13:45:45 +02:00 committed by Andreas Kling
parent dc9a702aa8
commit 8557bc56f7
3 changed files with 69 additions and 1 deletions

View file

@ -174,6 +174,12 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
case TokenType::Period:
consume();
return make<MemberExpression>(move(lhs), parse_expression());
case TokenType::PlusPlus:
consume();
return make<UpdateExpression>(UpdateOp::Increment, move(lhs));
case TokenType::MinusMinus:
consume();
return make<UpdateExpression>(UpdateOp::Decrement, move(lhs));
default:
m_has_errors = true;
expected("secondary expression (missing switch case)");
@ -352,7 +358,9 @@ bool Parser::match_secondary_expression() const
|| type == TokenType::LessThan
|| type == TokenType::LessThanEquals
|| type == TokenType::ParenOpen
|| type == TokenType::Period;
|| type == TokenType::Period
|| type == TokenType::PlusPlus
|| type == TokenType::MinusMinus;
}
bool Parser::match_statement() const