diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 70eda3e757..da6ab77466 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -559,6 +559,22 @@ NonnullRefPtr 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({ 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; } diff --git a/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js b/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js index 421e6a0c95..36c6bd9f2c 100644 --- a/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js +++ b/Userland/Libraries/LibJS/Tests/classes/class-inheritance.js @@ -132,6 +132,24 @@ test("super constructor call from child class with argument", () => { expect(c.x).toBe(10); }); +test("advanced 'extends' RHS", () => { + const foo = { + bar() { + return { + baz() { + return function () { + return function () { + return { quux: Number }; + }; + }; + }, + }; + }, + }; + class Foo extends foo.bar()["baz"]()`qux`().quux {} + expect(new Foo()).toBeInstanceOf(Number); +}); + test("issue #7045, super constructor call from child class in catch {}", () => { class Parent { constructor(x) {