Skip to content

Commit

Permalink
Fix duplicated private identifier lookup
Browse files Browse the repository at this point in the history
This patch fixes jerryscript-project#4921.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
  • Loading branch information
Robert Fancsik committed Jan 4, 2022
1 parent 49a1a80 commit 6c19dda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 19 additions & 12 deletions jerry-core/parser/js/js-parser-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,23 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
continue;
}

if (is_private)
{
parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER);
}

bool is_constructor_literal = context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p);
bool is_constructor_literal = false;

if (is_private && is_constructor_literal && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
if (context_p->token.type == LEXER_LITERAL)
{
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
if (parser_is_constructor_literal (context_p))
{
is_constructor_literal = true;

if (is_private && lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
}
}
else
{
parser_check_duplicated_private_field (context_p, SCANNER_PRIVATE_FIELD_PROPERTY_GETTER_SETTER);
}
}

if (!is_static && is_constructor_literal)
Expand Down Expand Up @@ -809,9 +816,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
lexer_expect_object_literal_id (context_p, ident_opts);
}

if (is_private)
if (is_private && context_p->token.type == LEXER_LITERAL)
{
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
if (parser_is_constructor_literal (context_p))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
}
Expand All @@ -836,9 +843,9 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */

status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD;

if (is_private)
if (is_private && context_p->token.type == LEXER_LITERAL)
{
if (context_p->token.type == LEXER_LITERAL && parser_is_constructor_literal (context_p))
if (parser_is_constructor_literal (context_p))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/jerry/es.next/private_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ check_syntax_error("class A { static get #a(){}; set #a(){}; #a; }");
check_syntax_error("class A { static #a(){}; #a; }");
check_syntax_error("class A extends B{ foo(){ super.#a }}");
check_syntax_error("class A extends function() { x = this.#foo; }{ #foo; };");
check_syntax_error("class A { static async *#bar(x) { } #bar }");
check_syntax_error("class A { static async #bar(x) { } #bar }");
check_syntax_error("class A { static *#bar(x) { } #bar }");
check_syntax_error("class A { async *#bar(x) { } #bar }");
check_syntax_error("class A { async #bar(x) { } #bar }");
check_syntax_error("class A { *#bar(x) { } #bar }");


class A {
#a = 1;
Expand Down

0 comments on commit 6c19dda

Please # to comment.