mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
LibJS: Extend class 'extends' RHS expression parsing
Instead of only parsing a primary expression, we should also allow member expressions, call expressions, and tagged template literals (and optional chains, which we don't have yet). In the spec, all of this is covered by `LeftHandSideExpression` (https://tc39.es/ecma262/#prod-LeftHandSideExpression).
This commit is contained in:
parent
b975a74a1d
commit
08a303172d
2 changed files with 34 additions and 0 deletions
|
@ -559,6 +559,22 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
|
|||
if (match(TokenType::Extends)) {
|
||||
consume();
|
||||
auto [expression, should_continue_parsing] = parse_primary_expression();
|
||||
|
||||
// Basically a (much) simplified parse_secondary_expression().
|
||||
for (;;) {
|
||||
if (match(TokenType::TemplateLiteralStart)) {
|
||||
auto template_literal = parse_template_literal(true);
|
||||
expression = create_ast_node<TaggedTemplateLiteral>({ m_state.current_token.filename(), rule_start.position(), position() }, move(expression), move(template_literal));
|
||||
continue;
|
||||
}
|
||||
if (match(TokenType::BracketOpen) || match(TokenType::Period) || match(TokenType::ParenOpen)) {
|
||||
auto precedence = g_operator_precedence.get(m_state.current_token.type());
|
||||
expression = parse_secondary_expression(move(expression), precedence);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super_class = move(expression);
|
||||
(void)should_continue_parsing;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue