From be3b4a68d223ae8d92a15d6dc89ff7c7b9f947bf Mon Sep 17 00:00:00 2001 From: davidot Date: Sun, 25 Jul 2021 11:50:12 +0200 Subject: [PATCH] LibJS: Allow class methods named "get", "set" or "static" --- Userland/Libraries/LibJS/Parser.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 5c259e7332..01ef13272a 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -721,7 +721,23 @@ NonnullRefPtr Parser::parse_class_expression(bool expect_class_ // It is a Syntax Error if PropName of MethodDefinition is "prototype". if (is_static && name == "prototype"sv) syntax_error("Classes may not have a static property named 'prototype'"); - + } else if (match(TokenType::ParenOpen) && (is_static || method_kind != ClassMethod::Kind::Method)) { + switch (method_kind) { + case ClassMethod::Kind::Method: + VERIFY(is_static); + name = "static"; + is_static = false; + break; + case ClassMethod::Kind::Getter: + name = "get"; + method_kind = ClassMethod::Kind::Method; + break; + case ClassMethod::Kind::Setter: + name = "set"; + method_kind = ClassMethod::Kind::Method; + break; + } + property_key = create_ast_node({ m_state.current_token.filename(), rule_start.position(), position() }, name); } else { expected("property key"); } @@ -741,7 +757,7 @@ NonnullRefPtr Parser::parse_class_expression(bool expect_class_ if (match(TokenType::ParenOpen)) { u8 parse_options = FunctionNodeParseOptions::AllowSuperPropertyLookup; - if (!super_class.is_null()) + if (!super_class.is_null() && !is_static && is_constructor) parse_options |= FunctionNodeParseOptions::AllowSuperConstructorCall; if (method_kind == ClassMethod::Kind::Getter) parse_options |= FunctionNodeParseOptions::IsGetterFunction;