@@ -620,26 +620,32 @@ class ParserBase {
620
620
return instance_members_scope != nullptr;
621
621
}
622
622
623
- DeclarationScope* EnsureStaticElementsScope(ParserBase* parser,
624
- int beg_pos ) {
623
+ DeclarationScope* EnsureStaticElementsScope(ParserBase* parser, int beg_pos,
624
+ int info_id ) {
625
625
if (!has_static_elements()) {
626
626
static_elements_scope = parser->NewFunctionScope(
627
627
FunctionKind::kClassStaticInitializerFunction);
628
628
static_elements_scope->SetLanguageMode(LanguageMode::kStrict);
629
629
static_elements_scope->set_start_position(beg_pos);
630
- static_elements_function_id = parser->GetNextInfoId();
630
+ static_elements_function_id = info_id;
631
+ // Actually consume the id. The id that was passed in might be an
632
+ // earlier id in case of computed property names.
633
+ parser->GetNextInfoId();
631
634
}
632
635
return static_elements_scope;
633
636
}
634
637
635
638
DeclarationScope* EnsureInstanceMembersScope(ParserBase* parser,
636
- int beg_pos) {
639
+ int beg_pos, int info_id ) {
637
640
if (!has_instance_members()) {
638
641
instance_members_scope = parser->NewFunctionScope(
639
642
FunctionKind::kClassMembersInitializerFunction);
640
643
instance_members_scope->SetLanguageMode(LanguageMode::kStrict);
641
644
instance_members_scope->set_start_position(beg_pos);
642
- instance_members_function_id = parser->GetNextInfoId();
645
+ instance_members_function_id = info_id;
646
+ // Actually consume the id. The id that was passed in might be an
647
+ // earlier id in case of computed property names.
648
+ parser->GetNextInfoId();
643
649
}
644
650
return instance_members_scope;
645
651
}
@@ -1321,7 +1327,7 @@ class ParserBase {
1321
1327
ParseFunctionFlags flags, bool is_static,
1322
1328
bool* has_seen_constructor);
1323
1329
ExpressionT ParseMemberInitializer(ClassInfo* class_info, int beg_pos,
1324
- bool is_static);
1330
+ int info_id, bool is_static);
1325
1331
BlockT ParseClassStaticBlock(ClassInfo* class_info);
1326
1332
ObjectLiteralPropertyT ParseObjectPropertyDefinition(
1327
1333
ParsePropertyInfo* prop_info, bool* has_seen_proto);
@@ -2624,6 +2630,8 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
2624
2630
DCHECK_NOT_NULL(class_info);
2625
2631
DCHECK_EQ(prop_info->position, PropertyPosition::kClassLiteral);
2626
2632
2633
+ int next_info_id = PeekNextInfoId();
2634
+
2627
2635
Token::Value name_token = peek();
2628
2636
int property_beg_pos = peek_position();
2629
2637
int name_token_position = property_beg_pos;
@@ -2667,12 +2675,18 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
2667
2675
// field.
2668
2676
DCHECK_IMPLIES(prop_info->is_computed_name, !prop_info->is_private);
2669
2677
2670
- if (!prop_info->is_computed_name) {
2678
+ if (prop_info->is_computed_name) {
2679
+ if (!has_error() && next_info_id != PeekNextInfoId() &&
2680
+ !(prop_info->is_static ? class_info->has_static_elements()
2681
+ : class_info->has_instance_members())) {
2682
+ impl()->ReindexComputedMemberName(name_expression);
2683
+ }
2684
+ } else {
2671
2685
CheckClassFieldName(prop_info->name, prop_info->is_static);
2672
2686
}
2673
2687
2674
- ExpressionT value = ParseMemberInitializer(class_info, property_beg_pos,
2675
- prop_info->is_static);
2688
+ ExpressionT value = ParseMemberInitializer(
2689
+ class_info, property_beg_pos, next_info_id, prop_info->is_static);
2676
2690
ExpectSemicolon();
2677
2691
2678
2692
ClassLiteralPropertyT result;
@@ -2786,11 +2800,12 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassInfo* class_info,
2786
2800
2787
2801
template <typename Impl>
2788
2802
typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberInitializer(
2789
- ClassInfo* class_info, int beg_pos, bool is_static) {
2803
+ ClassInfo* class_info, int beg_pos, int info_id, bool is_static) {
2790
2804
FunctionParsingScope body_parsing_scope(impl());
2791
2805
DeclarationScope* initializer_scope =
2792
- is_static ? class_info->EnsureStaticElementsScope(this, beg_pos)
2793
- : class_info->EnsureInstanceMembersScope(this, beg_pos);
2806
+ is_static
2807
+ ? class_info->EnsureStaticElementsScope(this, beg_pos, info_id)
2808
+ : class_info->EnsureInstanceMembersScope(this, beg_pos, info_id);
2794
2809
2795
2810
if (Check(Token::kAssign)) {
2796
2811
FunctionState initializer_state(&function_state_, &scope_,
@@ -2811,7 +2826,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseClassStaticBlock(
2811
2826
Consume(Token::kStatic);
2812
2827
2813
2828
DeclarationScope* initializer_scope =
2814
- class_info->EnsureStaticElementsScope(this, position());
2829
+ class_info->EnsureStaticElementsScope(this, position(), PeekNextInfoId() );
2815
2830
2816
2831
FunctionState initializer_state(&function_state_, &scope_, initializer_scope);
2817
2832
FunctionParsingScope body_parsing_scope(impl());
0 commit comments