]> git.kaiwu.me - quickjs.git/commitdiff
fix class method with name get (#258)
authorRichard Davison <richard.davison1@gmail.com>
Sun, 5 May 2024 16:46:30 +0000 (18:46 +0200)
committerGitHub <noreply@github.com>
Sun, 5 May 2024 16:46:30 +0000 (18:46 +0200)
Co-authored-by: Richard Davison <ridaviso@amazon.com>
quickjs.c
tests/test_language.js

index 283419539fc6d0c472717ac9e3e63214af94d443..798d5090e9a47e495b22fae8df1c9f1d4d7fce11 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -22380,7 +22380,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;
             }
index 0e9bb31eb08f0a71552cd3a01379fd47a1593b62..f00c4be0b28150af90330371e708f14b23c06506 100644 (file)
@@ -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}');