mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Allow defining class fields with "keyword" names
This commit is contained in:
parent
cbbfcd35e7
commit
e491fc0e81
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/e491fc0e816 Pull-request: https://github.com/SerenityOS/serenity/pull/11088 Issue: https://github.com/SerenityOS/serenity/issues/11078 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
|
@ -945,8 +945,12 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
|
|||
}
|
||||
|
||||
if (match(TokenType::Async)) {
|
||||
consume();
|
||||
is_async = true;
|
||||
auto lookahead_token = next_token();
|
||||
if (lookahead_token.type() != TokenType::Semicolon && lookahead_token.type() != TokenType::CurlyClose
|
||||
&& !lookahead_token.trivia_contains_line_terminator()) {
|
||||
consume();
|
||||
is_async = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (match(TokenType::Asterisk)) {
|
||||
|
@ -1042,7 +1046,7 @@ 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) || match(TokenType::Equals)) && (is_static || is_async || method_kind != ClassMethod::Kind::Method)) {
|
||||
} else if ((match(TokenType::ParenOpen) || match(TokenType::Equals) || match(TokenType::Semicolon) || match(TokenType::CurlyClose)) && (is_static || is_async || method_kind != ClassMethod::Kind::Method)) {
|
||||
switch (method_kind) {
|
||||
case ClassMethod::Kind::Method:
|
||||
if (is_async) {
|
||||
|
|
|
@ -85,3 +85,45 @@ test("with super class", () => {
|
|||
b.arrow_ref_super();
|
||||
expect(b.super_field).toBe(4);
|
||||
});
|
||||
|
||||
describe("class fields with a 'special' name", () => {
|
||||
test("static", () => {
|
||||
class A {
|
||||
static;
|
||||
}
|
||||
expect("static" in new A()).toBeTrue();
|
||||
|
||||
class B {
|
||||
static;
|
||||
}
|
||||
expect("static" in new B()).toBeTrue();
|
||||
|
||||
class C {
|
||||
static a;
|
||||
}
|
||||
expect("static" in new C()).toBeFalse();
|
||||
expect("a" in new C()).toBeFalse();
|
||||
|
||||
expect("a" in C).toBeTrue();
|
||||
expect("static" in C).toBeFalse();
|
||||
});
|
||||
|
||||
test("async", () => {
|
||||
class A {
|
||||
async;
|
||||
}
|
||||
expect("async" in new A()).toBeTrue();
|
||||
|
||||
class B {
|
||||
async;
|
||||
}
|
||||
expect("async" in new B()).toBeTrue();
|
||||
|
||||
class C {
|
||||
async;
|
||||
a;
|
||||
}
|
||||
expect("async" in new C()).toBeTrue();
|
||||
expect("a" in new C()).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue