@@ -847,11 +847,13 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
847847 }
848848 }
849849
850+ bool is_static_block = context_p -> token .type == LEXER_LEFT_BRACE ;
851+
850852 if (context_p -> token .type == LEXER_RIGHT_SQUARE )
851853 {
852854 is_computed = true;
853855 }
854- else if (LEXER_IS_IDENT_OR_STRING (context_p -> token .lit_location .type ))
856+ else if (! is_static_block && LEXER_IS_IDENT_OR_STRING (context_p -> token .lit_location .type ))
855857 {
856858 if (is_static && !is_private )
857859 {
@@ -869,7 +871,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
869871
870872 if (!(status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION )))
871873 {
872- if (!lexer_check_next_character (context_p , LIT_CHAR_LEFT_PAREN ))
874+ if (is_static_block || !lexer_check_next_character (context_p , LIT_CHAR_LEFT_PAREN ))
873875 {
874876 /* Class field. */
875877 if (fields_size == 0 )
@@ -889,7 +891,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
889891 parser_emit_cbc_ext_literal_from_token (context_p , field_opcode );
890892 }
891893
892- if (is_static && parser_is_constructor_literal (context_p ))
894+ if (is_static && ! is_static_block && parser_is_constructor_literal (context_p ))
893895 {
894896 parser_raise_error (context_p , PARSER_ERR_ARGUMENT_LIST_EXPECTED );
895897 }
@@ -925,7 +927,31 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
925927 }
926928 }
927929
928- if (lexer_consume_assign (context_p ))
930+ if (is_static_block )
931+ {
932+ class_field_type |= PARSER_CLASS_FIELD_STATIC_BLOCK ;
933+
934+ if (context_p -> next_scanner_info_p -> type != SCANNER_TYPE_CLASS_STATIC_BLOCK_END )
935+ {
936+ parser_flush_cbc (context_p );
937+ parser_parse_class_static_block (context_p );
938+ }
939+
940+ JERRY_ASSERT (context_p -> next_scanner_info_p -> type == SCANNER_TYPE_CLASS_STATIC_BLOCK_END );
941+
942+ scanner_set_location (context_p , & ((scanner_location_info_t * ) context_p -> next_scanner_info_p )-> location );
943+ scanner_release_next (context_p , sizeof (scanner_location_info_t ));
944+ JERRY_ASSERT (context_p -> next_scanner_info_p -> type == SCANNER_TYPE_FUNCTION );
945+ range .start_location .source_p = context_p -> next_scanner_info_p -> source_p - 1 ;
946+
947+ scanner_seek (context_p );
948+
949+ parser_stack_push (context_p , & range .start_location , sizeof (scanner_location_t ));
950+ fields_size += sizeof (scanner_location_t );
951+
952+ lexer_consume_next_character (context_p );
953+ }
954+ else if (lexer_consume_assign (context_p ))
929955 {
930956 class_field_type |= PARSER_CLASS_FIELD_INITIALIZED ;
931957
@@ -1738,8 +1764,17 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */
17381764
17391765 if (!lexer_check_next_character (context_p , LIT_CHAR_LEFT_PAREN ))
17401766 {
1767+ #if JERRY_ESNEXT
1768+ /* The `await` keyword is interpreted as an IdentifierReference within function expressions */
1769+ context_p -> status_flags &= (uint32_t ) ~PARSER_IS_CLASS_STATIC_BLOCK ;
1770+ #endif /* JERRY_ESNEXT */
1771+
17411772 lexer_next_token (context_p );
17421773
1774+ #if JERRY_ESNEXT
1775+ context_p -> status_flags |= parent_status_flags & PARSER_IS_CLASS_STATIC_BLOCK ;
1776+ #endif /* JERRY_ESNEXT */
1777+
17431778 if (context_p -> token .type != LEXER_LITERAL || context_p -> token .lit_location .type != LEXER_IDENT_LITERAL )
17441779 {
17451780 parser_raise_error (context_p , PARSER_ERR_IDENTIFIER_EXPECTED );
@@ -2168,7 +2203,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
21682203#endif /* JERRY_FUNCTION_TO_STRING */
21692204
21702205 uint32_t arrow_status_flags =
2171- (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p -> status_flags & PARSER_INSIDE_CLASS_FIELD ));
2206+ (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION
2207+ | (context_p -> status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK )));
21722208
21732209 if (context_p -> next_scanner_info_p -> u8_arg & SCANNER_FUNCTION_ASYNC )
21742210 {
@@ -2425,7 +2461,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
24252461#endif /* JERRY_FUNCTION_TO_STRING */
24262462
24272463 uint32_t arrow_status_flags =
2428- (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p -> status_flags & PARSER_INSIDE_CLASS_FIELD ));
2464+ (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION
2465+ | (context_p -> status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK )));
24292466 parser_parse_function_expression (context_p , arrow_status_flags );
24302467 return parser_abort_parsing_after_assignment_expression (context_p );
24312468 }
0 commit comments