@@ -780,7 +780,13 @@ func (ctx *lowerClassContext) enableNameCapture(p *parser, result visitClassResu
780
780
//
781
781
// If this returns true, the return property should be added to the class
782
782
// body. Otherwise the property should be omitted from the class body.
783
- func (ctx * lowerClassContext ) lowerField (p * parser , prop js_ast.Property , private * js_ast.EPrivateIdentifier , shouldOmitFieldInitializer bool , staticFieldToBlockAssign bool ) (js_ast.Property , bool ) {
783
+ func (ctx * lowerClassContext ) lowerField (
784
+ p * parser ,
785
+ prop js_ast.Property ,
786
+ private * js_ast.EPrivateIdentifier ,
787
+ shouldOmitFieldInitializer bool ,
788
+ staticFieldToBlockAssign bool ,
789
+ ) (js_ast.Property , bool ) {
784
790
mustLowerPrivate := private != nil && p .privateSymbolNeedsToBeLowered (private )
785
791
786
792
// The TypeScript compiler doesn't follow the JavaScript spec for
@@ -825,20 +831,16 @@ func (ctx *lowerClassContext) lowerField(p *parser, prop js_ast.Property, privat
825
831
826
832
// Add every newly-constructed instance into this map
827
833
key := js_ast.Expr {Loc : prop .Key .Loc , Data : & js_ast.EIdentifier {Ref : ref }}
828
- var args []js_ast.Expr
829
- if _ , ok := init .Data .(* js_ast.EUndefined ); ok {
830
- args = []js_ast.Expr {target , key }
831
- } else {
832
- args = []js_ast.Expr {target , key , init }
834
+ args := []js_ast.Expr {target , key }
835
+ if _ , ok := init .Data .(* js_ast.EUndefined ); ! ok {
836
+ args = append (args , init )
833
837
}
834
838
memberExpr = p .callRuntime (loc , "__privateAdd" , args )
835
839
p .recordUsage (ref )
836
840
} else if private == nil && ctx .class .UseDefineForClassFields {
837
- var args []js_ast.Expr
838
- if _ , ok := init .Data .(* js_ast.EUndefined ); ok {
839
- args = []js_ast.Expr {target , prop .Key }
840
- } else {
841
- args = []js_ast.Expr {target , prop .Key , init }
841
+ args := []js_ast.Expr {target , prop .Key }
842
+ if _ , ok := init .Data .(* js_ast.EUndefined ); ! ok {
843
+ args = append (args , init )
842
844
}
843
845
memberExpr = js_ast.Expr {Loc : loc , Data : & js_ast.ECall {
844
846
Target : p .importFromRuntime (loc , "__publicField" ),
@@ -1135,8 +1137,6 @@ func (ctx *lowerClassContext) hoistComputedProperties(p *parser, classLoweringIn
1135
1137
// If this key is referenced elsewhere, make sure to still preserve
1136
1138
// its side effects in the property's original location
1137
1139
if analysis .isComputedPropertyCopiedOrMoved {
1138
- inlineKey := prop .Key
1139
-
1140
1140
// If this property is being duplicated instead of moved or removed, then
1141
1141
// we still need the assignment to the temporary so that we can reference
1142
1142
// it in multiple places, but we don't have to hoist the assignment to an
@@ -1168,6 +1168,8 @@ func (ctx *lowerClassContext) hoistComputedProperties(p *parser, classLoweringIn
1168
1168
//
1169
1169
// So only do the hoist if this property is being moved or removed.
1170
1170
if ! analysis .rewriteAutoAccessorToGetSet && (analysis .mustLowerField || analysis .staticFieldToBlockAssign ) {
1171
+ inlineKey := prop .Key
1172
+
1171
1173
if ! analysis .needsValueOfKey {
1172
1174
// In certain cases, we only need to evaluate a property key for its
1173
1175
// side effects but we don't actually need the value of the key itself.
@@ -1201,14 +1203,13 @@ func (ctx *lowerClassContext) hoistComputedProperties(p *parser, classLoweringIn
1201
1203
// Otherwise, we keep the side effects in place (as described above) but
1202
1204
// just store the key in a temporary so we can refer to it later.
1203
1205
ref := p .generateTempRef (tempRefNeedsDeclare , "" )
1204
- inlineKey = js_ast .Assign (js_ast.Expr {Loc : prop .Key .Loc , Data : & js_ast.EIdentifier {Ref : ref }}, prop .Key )
1206
+ prop . Key = js_ast .Assign (js_ast.Expr {Loc : prop .Key .Loc , Data : & js_ast.EIdentifier {Ref : ref }}, prop .Key )
1205
1207
p .recordUsage (ref )
1206
1208
1207
1209
// Use this temporary when creating duplicate references to this key
1208
1210
if propertyKeyTempRefs == nil {
1209
1211
propertyKeyTempRefs = make (map [int ]ast.Ref )
1210
1212
}
1211
- prop .Key = inlineKey
1212
1213
propertyKeyTempRefs [propIndex ] = ref
1213
1214
1214
1215
// Deliberately continue to fall through to the "computed" case below:
0 commit comments