@@ -3089,7 +3089,7 @@ const typeIsNotOneOf = (type, types, valtype = Valtype.i32) => {
3089
3089
return out ;
3090
3090
} ;
3091
3091
3092
- const allocVar = ( scope , name , global = false , type = true , redecl = false ) => {
3092
+ const allocVar = ( scope , name , global = false , type = true , redecl = false , i32 = false ) => {
3093
3093
const target = global ? globals : scope . locals ;
3094
3094
3095
3095
// already declared
@@ -3104,7 +3104,7 @@ const allocVar = (scope, name, global = false, type = true, redecl = false) => {
3104
3104
}
3105
3105
3106
3106
let idx = global ? globals [ '#ind' ] ++ : scope . localInd ++ ;
3107
- target [ name ] = { idx, type : valtypeBinary } ;
3107
+ target [ name ] = { idx, type : i32 ? Valtype . i32 : valtypeBinary } ;
3108
3108
3109
3109
if ( type ) {
3110
3110
let typeIdx = global ? globals [ '#ind' ] ++ : scope . localInd ++ ;
@@ -6201,18 +6201,6 @@ const generateClass = (scope, decl) => {
6201
6201
// default value to undefined
6202
6202
value ??= DEFAULT_VALUE ( ) ;
6203
6203
6204
- let outArr = out , outOp = 'push' , outScope = scope ;
6205
- if ( type === 'PropertyDefinition' && ! _static ) {
6206
- // define in construction instead
6207
- outArr = func . wasm ;
6208
- outOp = 'unshift' ;
6209
- object = {
6210
- type : 'ThisExpression' ,
6211
- _noGlobalThis : true
6212
- } ;
6213
- outScope = func ;
6214
- }
6215
-
6216
6204
if ( isFuncType ( value . type ) ) {
6217
6205
let id = value . id ;
6218
6206
@@ -6230,19 +6218,60 @@ const generateClass = (scope, decl) => {
6230
6218
} ;
6231
6219
}
6232
6220
6233
- outArr [ outOp ] (
6234
- ...generate ( outScope , object ) ,
6235
- Opcodes . i32_to_u ,
6236
- ...getNodeType ( outScope , object ) ,
6221
+ if ( type === 'PropertyDefinition' && ! _static ) {
6222
+ // define in construction instead
6223
+ object = {
6224
+ type : 'ThisExpression' ,
6225
+ _noGlobalThis : true
6226
+ } ;
6237
6227
6238
- ...toPropertyKey ( outScope , generate ( outScope , k ) , getNodeType ( outScope , k ) , computed , true ) ,
6228
+ let computedTmp ;
6229
+ if ( computed ) {
6230
+ // compute now, reference in construction
6231
+ computedTmp = allocVar ( scope , `#class_computed_prop${ uniqId ( ) } ` , true , true , false , true ) ;
6239
6232
6240
- ...generate ( outScope , value ) ,
6241
- ...( initKind !== 'value' && initKind !== 'method' ? [ Opcodes . i32_to_u ] : [ ] ) ,
6242
- ...getNodeType ( outScope , value ) ,
6233
+ out . push (
6234
+ ...toPropertyKey ( scope , generate ( scope , k ) , getNodeType ( scope , k ) , computed , true ) ,
6235
+ [ Opcodes . global_set , computedTmp + 1 ] ,
6236
+ [ Opcodes . global_set , computedTmp ]
6237
+ ) ;
6238
+ }
6243
6239
6244
- [ Opcodes . call , includeBuiltin ( outScope , `__Porffor_object_class_${ initKind } ` ) . index ]
6245
- ) ;
6240
+ func . wasm . unshift (
6241
+ ...generate ( func , object ) ,
6242
+ Opcodes . i32_to_u ,
6243
+ ...getNodeType ( func , object ) ,
6244
+
6245
+ ...( computed ? [
6246
+ [ Opcodes . global_get , computedTmp ] ,
6247
+ [ Opcodes . global_get , computedTmp + 1 ] ,
6248
+ ] : [
6249
+ ...generate ( func , k ) ,
6250
+ Opcodes . i32_to_u ,
6251
+ ...getNodeType ( func , k )
6252
+ ] ) ,
6253
+
6254
+ ...generate ( func , value ) ,
6255
+ ...( initKind !== 'value' && initKind !== 'method' ? [ Opcodes . i32_to_u ] : [ ] ) ,
6256
+ ...getNodeType ( func , value ) ,
6257
+
6258
+ [ Opcodes . call , includeBuiltin ( func , `__Porffor_object_class_${ initKind } ` ) . index ]
6259
+ ) ;
6260
+ } else {
6261
+ out . push (
6262
+ ...generate ( scope , object ) ,
6263
+ Opcodes . i32_to_u ,
6264
+ ...getNodeType ( scope , object ) ,
6265
+
6266
+ ...toPropertyKey ( scope , generate ( scope , k ) , getNodeType ( scope , k ) , computed , true ) ,
6267
+
6268
+ ...generate ( scope , value ) ,
6269
+ ...( initKind !== 'value' && initKind !== 'method' ? [ Opcodes . i32_to_u ] : [ ] ) ,
6270
+ ...getNodeType ( scope , value ) ,
6271
+
6272
+ [ Opcodes . call , includeBuiltin ( scope , `__Porffor_object_class_${ initKind } ` ) . index ]
6273
+ ) ;
6274
+ }
6246
6275
}
6247
6276
6248
6277
delete scope . overrideThis ;
0 commit comments