summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authordavidot <david.tuin@gmail.com>2021-07-25 11:50:12 +0200
committerLinus Groh <mail@linusgroh.de>2021-08-16 23:20:04 +0100
commitbe3b4a68d223ae8d92a15d6dc89ff7c7b9f947bf (patch)
tree2f9799b883883e1fe1d6d249f703294b6d806c25 /Userland/Libraries
parentb16c02d6b4ce1d5cd226314ea268592c56270aaf (diff)
downloadserenity-be3b4a68d223ae8d92a15d6dc89ff7c7b9f947bf.zip
LibJS: Allow class methods named "get", "set" or "static"
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp20
1 files 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<ClassExpression> 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<StringLiteral>({ m_state.current_token.filename(), rule_start.position(), position() }, name);
} else {
expected("property key");
}
@@ -741,7 +757,7 @@ NonnullRefPtr<ClassExpression> 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;