Skip to content

Commit 0c8feca

Browse files
authored
Improve class parser (#289)
- accept `class P { async = 1 }}` - accept `class P { static = 1 }}` etc. - Fixes #261
1 parent d9c699f commit 0c8feca

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

quickjs.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -22381,7 +22381,7 @@ static int __exception js_parse_property_name(JSParseState *s,
2238122381
goto fail1;
2238222382
if (s->token.val == ':' || s->token.val == ',' ||
2238322383
s->token.val == '}' || s->token.val == '(' ||
22384-
s->token.val == '=' ) {
22384+
s->token.val == '=') {
2238522385
is_non_reserved_ident = TRUE;
2238622386
goto ident_found;
2238722387
}
@@ -22397,7 +22397,8 @@ static int __exception js_parse_property_name(JSParseState *s,
2239722397
if (next_token(s))
2239822398
goto fail1;
2239922399
if (s->token.val == ':' || s->token.val == ',' ||
22400-
s->token.val == '}' || s->token.val == '(') {
22400+
s->token.val == '}' || s->token.val == '(' ||
22401+
s->token.val == '=') {
2240122402
is_non_reserved_ident = TRUE;
2240222403
goto ident_found;
2240322404
}
@@ -23081,7 +23082,12 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
2308123082
goto fail;
2308223083
continue;
2308323084
}
23084-
is_static = (s->token.val == TOK_STATIC);
23085+
is_static = FALSE;
23086+
if (s->token.val == TOK_STATIC) {
23087+
int next = peek_token(s, TRUE);
23088+
if (!(next == ';' || next == '}' || next == '(' || next == '='))
23089+
is_static = TRUE;
23090+
}
2308523091
prop_type = -1;
2308623092
if (is_static) {
2308723093
if (next_token(s))

tests/test_language.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,13 @@ function test_class()
335335
assert(S.x === 42);
336336
assert(S.y === 42);
337337
assert(S.z === 42);
338-
338+
339339
class P {
340-
get = () => "123"
340+
get = () => "123";
341+
static() { return 42; }
341342
}
342343
assert(new P().get() === "123");
344+
assert(new P().static() === 42);
343345
};
344346

345347
function test_template()

0 commit comments

Comments
 (0)