@@ -847,11 +847,13 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
847
847
}
848
848
}
849
849
850
+ bool is_static_block = context_p -> token .type == LEXER_LEFT_BRACE ;
851
+
850
852
if (context_p -> token .type == LEXER_RIGHT_SQUARE )
851
853
{
852
854
is_computed = true;
853
855
}
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 ))
855
857
{
856
858
if (is_static && !is_private )
857
859
{
@@ -869,7 +871,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
869
871
870
872
if (!(status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION )))
871
873
{
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 ))
873
875
{
874
876
/* Class field. */
875
877
if (fields_size == 0 )
@@ -889,7 +891,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
889
891
parser_emit_cbc_ext_literal_from_token (context_p , field_opcode );
890
892
}
891
893
892
- if (is_static && parser_is_constructor_literal (context_p ))
894
+ if (is_static && ! is_static_block && parser_is_constructor_literal (context_p ))
893
895
{
894
896
parser_raise_error (context_p , PARSER_ERR_ARGUMENT_LIST_EXPECTED );
895
897
}
@@ -925,7 +927,31 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
925
927
}
926
928
}
927
929
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 ))
929
955
{
930
956
class_field_type |= PARSER_CLASS_FIELD_INITIALIZED ;
931
957
@@ -1738,8 +1764,17 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */
1738
1764
1739
1765
if (!lexer_check_next_character (context_p , LIT_CHAR_LEFT_PAREN ))
1740
1766
{
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
+
1741
1772
lexer_next_token (context_p );
1742
1773
1774
+ #if JERRY_ESNEXT
1775
+ context_p -> status_flags |= parent_status_flags & PARSER_IS_CLASS_STATIC_BLOCK ;
1776
+ #endif /* JERRY_ESNEXT */
1777
+
1743
1778
if (context_p -> token .type != LEXER_LITERAL || context_p -> token .lit_location .type != LEXER_IDENT_LITERAL )
1744
1779
{
1745
1780
parser_raise_error (context_p , PARSER_ERR_IDENTIFIER_EXPECTED );
@@ -2168,7 +2203,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
2168
2203
#endif /* JERRY_FUNCTION_TO_STRING */
2169
2204
2170
2205
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 )));
2172
2208
2173
2209
if (context_p -> next_scanner_info_p -> u8_arg & SCANNER_FUNCTION_ASYNC )
2174
2210
{
@@ -2425,7 +2461,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
2425
2461
#endif /* JERRY_FUNCTION_TO_STRING */
2426
2462
2427
2463
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 )));
2429
2466
parser_parse_function_expression (context_p , arrow_status_flags );
2430
2467
return parser_abort_parsing_after_assignment_expression (context_p );
2431
2468
}
0 commit comments