Skip to content

Commit 79fd540

Browse files
author
Robert Fancsik
authored
Fix duplicated private identifier lookup (#4947)
This patch fixes #4921. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 85c7987 commit 79fd540

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

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

+16-11
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,21 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
638638
continue;
639639
}
640640

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

646-
bool is_constructor_literal = context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p);
647+
if (is_private)
648+
{
649+
if (is_constructor_literal && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
650+
{
651+
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
652+
}
647653

648-
if (is_private && is_constructor_literal && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
649-
{
650-
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
654+
parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER);
655+
}
651656
}
652657

653658
if (!is_static && is_constructor_literal)
@@ -809,9 +814,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
809814
lexer_expect_object_literal_id (context_p, ident_opts);
810815
}
811816

812-
if (is_private)
817+
if (is_private && context_p->token.type == LEXER_LITERAL)
813818
{
814-
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
819+
if (parser_is_constructor_literal (context_p))
815820
{
816821
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
817822
}
@@ -836,9 +841,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
836841

837842
status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD;
838843

839-
if (is_private)
844+
if (is_private && context_p->token.type == LEXER_LITERAL)
840845
{
841-
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
846+
if (parser_is_constructor_literal (context_p))
842847
{
843848
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
844849
}

tests/jerry/es.next/private_fields.js

+7
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)