commit a0ef4f658721c0d58fe9da46fc7aab62e69f5bc7
parent 08ce05adcc880071a11bbe3e5b31e2807268adc6
Author: Richard Davison <richard.davison1@gmail.com>
Date: Sun, 5 May 2024 18:46:30 +0200
fix class method with name get (#258)
Co-authored-by: Richard Davison <ridaviso@amazon.com>
Diffstat:
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c
@@ -22567,7 +22567,8 @@ static int __exception js_parse_property_name(JSParseState *s,
if (next_token(s))
goto fail1;
if (s->token.val == ':' || s->token.val == ',' ||
- s->token.val == '}' || s->token.val == '(') {
+ s->token.val == '}' || s->token.val == '(' ||
+ s->token.val == '=' ) {
is_non_reserved_ident = TRUE;
goto ident_found;
}
diff --git a/quickjs/tests/test_language.js b/quickjs/tests/test_language.js
@@ -335,6 +335,11 @@ function test_class()
assert(S.x === 42);
assert(S.y === 42);
assert(S.z === 42);
+
+ class P {
+ get = () => "123"
+ }
+ assert(new P().get() === "123");
};
function test_template()
@@ -362,8 +367,9 @@ function test_template_skip()
function test_object_literal()
{
var x = 0, get = 1, set = 2; async = 3;
- a = { get: 2, set: 3, async: 4 };
- assert(JSON.stringify(a), '{"get":2,"set":3,"async":4}');
+ a = { get: 2, set: 3, async: 4, get a(){ return this.get} };
+ assert(JSON.stringify(a), '{"get":2,"set":3,"async":4,"a":2}');
+ assert(a.a === 2);
a = { x, get, set, async };
assert(JSON.stringify(a), '{"x":0,"get":1,"set":2,"async":3}');