Skip to content

Commit 6c19dda

Browse files
author
Robert Fancsik
committed
Fix duplicated private identifier lookup
This patch fixes #4921. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 49a1a80 commit 6c19dda

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,23 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
638638
continue;
639639
}
640640

641-
if (is_private)
642-
{
643-
parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER);
644-
}
645-
646-
bool is_constructor_literal = context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p);
641+
bool is_constructor_literal = false;
647642

648-
if (is_private && is_constructor_literal && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
643+
if (context_p->token.type == LEXER_LITERAL)
649644
{
650-
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
645+
if (parser_is_constructor_literal (context_p))
646+
{
647+
is_constructor_literal = true;
648+
649+
if (is_private && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
650+
{
651+
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
652+
}
653+
}
654+
else
655+
{
656+
parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER);
657+
}
651658
}
652659

653660
if (!is_static && is_constructor_literal)
@@ -809,9 +816,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
809816
lexer_expect_object_literal_id (context_p, ident_opts);
810817
}
811818

812-
if (is_private)
819+
if (is_private && context_p->token.type == LEXER_LITERAL)
813820
{
814-
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
821+
if (parser_is_constructor_literal (context_p))
815822
{
816823
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
817824
}
@@ -836,9 +843,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
836843

837844
status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD;
838845

839-
if (is_private)
846+
if (is_private && context_p->token.type == LEXER_LITERAL)
840847
{
841-
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
848+
if (parser_is_constructor_literal (context_p))
842849
{
843850
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
844851
}

tests/jerry/es.next/private_fields.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ check_syntax_error("class A { static get #a(){}; set #a(){}; #a; }");
4747
check_syntax_error("class A { static #a(){}; #a; }");
4848
check_syntax_error("class A extends B{ foo(){ super.#a }}");
4949
check_syntax_error("class A extends function() { x = this.#foo; }{ #foo; };");
50+
check_syntax_error("class A { static async *#bar(x) { } #bar }");
51+
check_syntax_error("class A { static async #bar(x) { } #bar }");
52+
check_syntax_error("class A { static *#bar(x) { } #bar }");
53+
check_syntax_error("class A { async *#bar(x) { } #bar }");
54+
check_syntax_error("class A { async #bar(x) { } #bar }");
55+
check_syntax_error("class A { *#bar(x) { } #bar }");
56+
5057

5158
class A {
5259
#a = 1;

0 commit comments

Comments
 (0)