@@ -813,9 +813,15 @@ parser_parse_class (parser_context_t *context_p, /**< context */
813813
814814 if (is_statement )
815815 {
816- parser_emit_cbc_literal (context_p ,
817- class_ident_index >= PARSER_REGISTER_START ? CBC_MOV_IDENT : CBC_ASSIGN_LET_CONST ,
818- class_ident_index );
816+ cbc_opcode_t opcode = CBC_MOV_IDENT ;
817+
818+ if (class_ident_index < PARSER_REGISTER_START )
819+ {
820+ opcode = (scanner_literal_is_created (context_p , class_ident_index ) ? CBC_ASSIGN_LET_CONST
821+ : CBC_INIT_LET );
822+ }
823+
824+ parser_emit_cbc_literal (context_p , (uint16_t ) opcode , class_ident_index );
819825 }
820826
821827 parser_flush_cbc (context_p );
@@ -2251,9 +2257,9 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
22512257 */
22522258static uint8_t
22532259parser_append_binary_single_assignment_token (parser_context_t * context_p , /**< context */
2254- bool is_lexical ) /**< assign lexical declaration */
2260+ uint32_t pattern_flags ) /**< pattern flags */
22552261{
2256- JERRY_UNUSED (is_lexical );
2262+ JERRY_UNUSED (pattern_flags );
22572263
22582264 /* Unlike other tokens, the whole byte code is saved for binary
22592265 * assignment, since it has multiple forms depending on the
@@ -2301,7 +2307,7 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
23012307 assign_opcode = CBC_ASSIGN_SET_IDENT ;
23022308
23032309#if ENABLED (JERRY_ES2015 )
2304- if (!is_lexical )
2310+ if (!( pattern_flags & ( PARSER_PATTERN_LET | PARSER_PATTERN_CONST | PARSER_PATTERN_LOCAL )) )
23052311 {
23062312 if (scanner_literal_is_const_reg (context_p , literal_index ))
23072313 {
@@ -2310,7 +2316,20 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
23102316 }
23112317 else if (literal_index < PARSER_REGISTER_START )
23122318 {
2313- assign_opcode = CBC_ASSIGN_LET_CONST ;
2319+ assign_opcode = CBC_INIT_LET ;
2320+
2321+ if (scanner_literal_is_created (context_p , literal_index ))
2322+ {
2323+ assign_opcode = CBC_ASSIGN_LET_CONST ;
2324+ }
2325+ else if (pattern_flags & PARSER_PATTERN_CONST )
2326+ {
2327+ assign_opcode = CBC_INIT_CONST ;
2328+ }
2329+ else if (pattern_flags & PARSER_PATTERN_LOCAL )
2330+ {
2331+ assign_opcode = CBC_INIT_ARG_OR_CATCH ;
2332+ }
23142333 }
23152334#endif /* ENABLED (JERRY_ES2015) */
23162335
@@ -2395,7 +2414,7 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */
23952414
23962415 if (context_p -> token .type == LEXER_ASSIGN )
23972416 {
2398- parser_append_binary_single_assignment_token (context_p , false );
2417+ parser_append_binary_single_assignment_token (context_p , 0 );
23992418 return ;
24002419 }
24012420
@@ -2486,7 +2505,10 @@ parser_process_binary_opcodes (parser_context_t *context_p, /**< context */
24862505 JERRY_ASSERT (opcode == CBC_ASSIGN_SET_IDENT
24872506 || opcode == CBC_ASSIGN_PROP_LITERAL
24882507 || opcode == CBC_ASSIGN_PROP_THIS_LITERAL
2489- || opcode == CBC_ASSIGN_LET_CONST );
2508+ || opcode == CBC_ASSIGN_LET_CONST
2509+ || opcode == CBC_INIT_ARG_OR_CATCH
2510+ || opcode == CBC_INIT_LET
2511+ || opcode == CBC_INIT_CONST );
24902512
24912513 index = parser_stack_pop_uint16 (context_p );
24922514 }
@@ -2601,7 +2623,7 @@ parser_pattern_get_target (parser_context_t *context_p, /**< context */
26012623 {
26022624 JERRY_ASSERT (flags & PARSER_PATTERN_TARGET_ON_STACK );
26032625
2604- parser_emit_cbc_forward_branch (context_p , PARSER_TO_EXT_OPCODE ( CBC_EXT_DEFAULT_INITIALIZER ) , & skip_init );
2626+ parser_emit_cbc_ext_forward_branch (context_p , CBC_EXT_DEFAULT_INITIALIZER , & skip_init );
26052627 }
26062628
26072629 if ((flags & (PARSER_PATTERN_TARGET_ON_STACK | PARSER_PATTERN_TARGET_DEFAULT )) != PARSER_PATTERN_TARGET_ON_STACK )
@@ -2707,8 +2729,7 @@ parser_pattern_form_assignment (parser_context_t *context_p, /**< context */
27072729 JERRY_UNUSED (ident_line_counter );
27082730
27092731 parser_stack_push_uint8 (context_p , LEXER_EXPRESSION_START );
2710- bool is_lexical = (flags & (PARSER_PATTERN_LEXICAL | PARSER_PATTERN_LOCAL )) != 0 ;
2711- uint8_t assign_opcode = parser_append_binary_single_assignment_token (context_p , is_lexical );
2732+ uint8_t assign_opcode = parser_append_binary_single_assignment_token (context_p , flags );
27122733
27132734 if (flags & PARSER_PATTERN_ARRAY )
27142735 {
@@ -2724,7 +2745,7 @@ parser_pattern_form_assignment (parser_context_t *context_p, /**< context */
27242745 {
27252746 parser_branch_t skip_init ;
27262747 lexer_next_token (context_p );
2727- parser_emit_cbc_forward_branch (context_p , PARSER_TO_EXT_OPCODE ( CBC_EXT_DEFAULT_INITIALIZER ) , & skip_init );
2748+ parser_emit_cbc_ext_forward_branch (context_p , CBC_EXT_DEFAULT_INITIALIZER , & skip_init );
27282749
27292750 parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
27302751 parser_set_branch_to_current_position (context_p , & skip_init );
@@ -2770,7 +2791,8 @@ parser_pattern_process_nested_pattern (parser_context_t *context_p, /**< context
27702791 parser_pattern_flags_t options = (PARSER_PATTERN_NESTED_PATTERN
27712792 | PARSER_PATTERN_TARGET_ON_STACK
27722793 | (flags & (PARSER_PATTERN_BINDING
2773- | PARSER_PATTERN_LEXICAL
2794+ | PARSER_PATTERN_LET
2795+ | PARSER_PATTERN_CONST
27742796 | PARSER_PATTERN_LOCAL
27752797 | PARSER_PATTERN_REST_ELEMENT
27762798 | PARSER_PATTERN_ARGUMENTS )));
@@ -2821,7 +2843,7 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */
28212843
28222844 lexer_construct_literal_object (context_p , & context_p -> token .lit_location , LEXER_IDENT_LITERAL );
28232845
2824- if (flags & PARSER_PATTERN_LEXICAL
2846+ if (flags & ( PARSER_PATTERN_LET | PARSER_PATTERN_CONST )
28252847 && context_p -> token .keyword_type == LEXER_KEYW_LET )
28262848 {
28272849 parser_raise_error (context_p , PARSER_ERR_LEXICAL_LET_BINDING );
0 commit comments