@@ -67,6 +67,9 @@ typedef enum
67
67
SCAN_STACK_BLOCK_STATEMENT , /**< block statement group */
68
68
SCAN_STACK_BLOCK_EXPRESSION , /**< block expression group */
69
69
SCAN_STACK_BLOCK_PROPERTY , /**< block property group */
70
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
71
+ SCAN_STACK_COMPUTED_PROPERTY , /**< computed property name */
72
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
70
73
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
71
74
SCAN_STACK_TEMPLATE_STRING , /**< template string */
72
75
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
@@ -372,9 +375,41 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */
372
375
return false;
373
376
}
374
377
378
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
379
+ if (context_p -> token .type == LEXER_RIGHT_SQUARE && stack_top == SCAN_STACK_COMPUTED_PROPERTY )
380
+ {
381
+ lexer_next_token (context_p );
382
+
383
+ parser_stack_pop_uint8 (context_p );
384
+ stack_top = (scan_stack_modes_t ) context_p -> stack_top_uint8 ;
385
+
386
+ if (stack_top == SCAN_STACK_BLOCK_PROPERTY )
387
+ {
388
+ if (context_p -> token .type != LEXER_LEFT_PAREN )
389
+ {
390
+ parser_raise_error (context_p , PARSER_ERR_ARGUMENT_LIST_EXPECTED );
391
+ }
392
+
393
+ * mode = SCAN_MODE_FUNCTION_ARGUMENTS ;
394
+ return true;
395
+ }
396
+
397
+ JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL );
398
+
399
+ if (context_p -> token .type != LEXER_COLON )
400
+ {
401
+ parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
402
+ }
403
+
404
+ * mode = SCAN_MODE_PRIMARY_EXPRESSION ;
405
+ return false;
406
+ }
407
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
408
+
375
409
/* Check whether we can enter to statement mode. */
376
410
if (stack_top != SCAN_STACK_BLOCK_STATEMENT
377
411
&& stack_top != SCAN_STACK_BLOCK_EXPRESSION
412
+ && stack_top != SCAN_STACK_BLOCK_PROPERTY
378
413
#ifndef CONFIG_DISABLE_ES2015_CLASS
379
414
&& stack_top != SCAN_STACK_CLASS
380
415
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
@@ -776,6 +811,7 @@ parser_scan_until (parser_context_t *context_p, /**< context */
776
811
777
812
if (context_p -> token .type == LEXER_LITERAL
778
813
&& (context_p -> token .lit_location .type == LEXER_IDENT_LITERAL
814
+ || context_p -> token .lit_location .type == LEXER_STRING_LITERAL
779
815
|| context_p -> token .lit_location .type == LEXER_NUMBER_LITERAL ))
780
816
{
781
817
lexer_next_token (context_p );
@@ -826,6 +862,15 @@ parser_scan_until (parser_context_t *context_p, /**< context */
826
862
827
863
lexer_scan_identifier (context_p , true);
828
864
865
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
866
+ if (context_p -> token .type == LEXER_LEFT_SQUARE )
867
+ {
868
+ parser_stack_push_uint8 (context_p , SCAN_STACK_COMPUTED_PROPERTY );
869
+ mode = SCAN_MODE_PRIMARY_EXPRESSION ;
870
+ break ;
871
+ }
872
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
873
+
829
874
if (context_p -> token .type == LEXER_RIGHT_BRACE )
830
875
{
831
876
parser_stack_pop_uint8 (context_p );
@@ -836,9 +881,26 @@ parser_scan_until (parser_context_t *context_p, /**< context */
836
881
if (context_p -> token .type == LEXER_PROPERTY_GETTER
837
882
|| context_p -> token .type == LEXER_PROPERTY_SETTER )
838
883
{
884
+ lexer_next_token (context_p );
885
+
839
886
parser_stack_push_uint8 (context_p , SCAN_STACK_BLOCK_PROPERTY );
887
+
888
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
889
+ if (context_p -> token .type == LEXER_LEFT_SQUARE )
890
+ {
891
+ parser_stack_push_uint8 (context_p , SCAN_STACK_COMPUTED_PROPERTY );
892
+ mode = SCAN_MODE_PRIMARY_EXPRESSION ;
893
+ break ;
894
+ }
895
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
896
+
897
+ if (context_p -> token .type != LEXER_LITERAL )
898
+ {
899
+ parser_raise_error (context_p , PARSER_ERR_IDENTIFIER_EXPECTED );
900
+ }
901
+
840
902
mode = SCAN_MODE_FUNCTION_ARGUMENTS ;
841
- break ;
903
+ continue ;
842
904
}
843
905
844
906
lexer_next_token (context_p );
0 commit comments