@@ -90,10 +90,12 @@ impl<'a> PeepholeOptimizations {
9090 ctx : & mut Ctx < ' a , ' _ > ,
9191 ) {
9292 let property_key_parent: ClassPropertyKeyParent = prop. into ( ) ;
93- if let PropertyKey :: StringLiteral ( str) = & prop. key {
94- if property_key_parent. should_keep_as_computed_property ( & str. value ) {
95- return ;
96- }
93+ // Only check for computed property restrictions if this is actually a computed property
94+ if prop. computed
95+ && let PropertyKey :: StringLiteral ( str) = & prop. key
96+ && property_key_parent. should_keep_as_computed_property ( & str. value )
97+ {
98+ return ;
9799 }
98100 self . try_compress_property_key ( & mut prop. key , & mut prop. computed , ctx) ;
99101 }
@@ -104,10 +106,12 @@ impl<'a> PeepholeOptimizations {
104106 ctx : & mut Ctx < ' a , ' _ > ,
105107 ) {
106108 let property_key_parent: ClassPropertyKeyParent = prop. into ( ) ;
107- if let PropertyKey :: StringLiteral ( str) = & prop. key {
108- if property_key_parent. should_keep_as_computed_property ( & str. value ) {
109- return ;
110- }
109+ // Only check for computed property restrictions if this is actually a computed property
110+ if prop. computed
111+ && let PropertyKey :: StringLiteral ( str) = & prop. key
112+ && property_key_parent. should_keep_as_computed_property ( & str. value )
113+ {
114+ return ;
111115 }
112116 self . try_compress_property_key ( & mut prop. key , & mut prop. computed , ctx) ;
113117 }
@@ -118,10 +122,12 @@ impl<'a> PeepholeOptimizations {
118122 ctx : & mut Ctx < ' a , ' _ > ,
119123 ) {
120124 let property_key_parent: ClassPropertyKeyParent = prop. into ( ) ;
121- if let PropertyKey :: StringLiteral ( str) = & prop. key {
122- if property_key_parent. should_keep_as_computed_property ( & str. value ) {
123- return ;
124- }
125+ // Only check for computed property restrictions if this is actually a computed property
126+ if prop. computed
127+ && let PropertyKey :: StringLiteral ( str) = & prop. key
128+ && property_key_parent. should_keep_as_computed_property ( & str. value )
129+ {
130+ return ;
125131 }
126132 self . try_compress_property_key ( & mut prop. key , & mut prop. computed , ctx) ;
127133 }
@@ -1698,19 +1704,23 @@ mod test {
16981704 test_same ( "class C { static ['prototype'] = 0 }" ) ; // class C { prototype = 0 } is an early error
16991705 test_same ( "class C { static accessor ['prototype'] = 0 }" ) ; // class C { accessor prototype = 0 } is an early error
17001706 test ( "class C { ['prototype']() {} }" , "class C { prototype() {} }" ) ;
1707+ test ( "class C { 'prototype'() {} }" , "class C { prototype() {} }" ) ;
17011708 test ( "class C { ['prototype'] = 0 }" , "class C { prototype = 0 }" ) ;
1709+ test ( "class C { 'prototype' = 0 }" , "class C { prototype = 0 }" ) ;
17021710 test ( "class C { accessor ['prototype'] = 0 }" , "class C { accessor prototype = 0 }" ) ;
17031711 test_same ( "class C { ['constructor'] = 0 }" ) ; // class C { constructor = 0 } is an early error
17041712 test_same ( "class C { accessor ['constructor'] = 0 }" ) ; // class C { accessor constructor = 0 } is an early error
17051713 test_same ( "class C { static ['constructor'] = 0 }" ) ; // class C { static constructor = 0 } is an early error
17061714 test_same ( "class C { static accessor ['constructor'] = 0 }" ) ; // class C { static accessor constructor = 0 } is an early error
17071715 test_same ( "class C { ['constructor']() {} }" ) ; // computed `constructor` is not treated as a constructor
1716+ test ( "class C { 'constructor'() {} }" , "class C { constructor() {} }" ) ;
17081717 test_same ( "class C { *['constructor']() {} }" ) ; // class C { *constructor() {} } is an early error
17091718 test_same ( "class C { async ['constructor']() {} }" ) ; // class C { async constructor() {} } is an early error
17101719 test_same ( "class C { async *['constructor']() {} }" ) ; // class C { async *constructor() {} } is an early error
17111720 test_same ( "class C { get ['constructor']() {} }" ) ; // class C { get constructor() {} } is an early error
17121721 test_same ( "class C { set ['constructor'](v) {} }" ) ; // class C { set constructor(v) {} } is an early error
17131722 test ( "class C { static ['constructor']() {} }" , "class C { static constructor() {} }" ) ;
1723+ test ( "class C { static 'constructor'() {} }" , "class C { static constructor() {} }" ) ;
17141724 test_same ( "class C { ['#constructor'] = 0 }" ) ; // class C { #constructor = 0 } is an early error
17151725 test_same ( "class C { accessor ['#constructor'] = 0 }" ) ; // class C { accessor #constructor = 0 } is an early error
17161726 test_same ( "class C { ['#constructor']() {} }" ) ; // class C { #constructor() {} } is an early error
0 commit comments