@@ -1078,6 +1078,12 @@ function lowerStatement(
1078
1078
const left = stmt . get ( 'left' ) ;
1079
1079
const leftLoc = left . node . loc ?? GeneratedSource ;
1080
1080
let test : Place ;
1081
+ const advanceIterator = lowerValueToTemporary ( builder , {
1082
+ kind : 'IteratorNext' ,
1083
+ loc : leftLoc ,
1084
+ iterator : { ...iterator } ,
1085
+ collection : { ...value } ,
1086
+ } ) ;
1081
1087
if ( left . isVariableDeclaration ( ) ) {
1082
1088
const declarations = left . get ( 'declarations' ) ;
1083
1089
CompilerError . invariant ( declarations . length === 1 , {
@@ -1087,12 +1093,6 @@ function lowerStatement(
1087
1093
suggestions : null ,
1088
1094
} ) ;
1089
1095
const id = declarations [ 0 ] . get ( 'id' ) ;
1090
- const advanceIterator = lowerValueToTemporary ( builder , {
1091
- kind : 'IteratorNext' ,
1092
- loc : leftLoc ,
1093
- iterator : { ...iterator } ,
1094
- collection : { ...value } ,
1095
- } ) ;
1096
1096
const assign = lowerAssignment (
1097
1097
builder ,
1098
1098
leftLoc ,
@@ -1103,13 +1103,19 @@ function lowerStatement(
1103
1103
) ;
1104
1104
test = lowerValueToTemporary ( builder , assign ) ;
1105
1105
} else {
1106
- builder . errors . push ( {
1107
- reason : `(BuildHIR::lowerStatement) Handle ${ left . type } inits in ForOfStatement` ,
1108
- severity : ErrorSeverity . Todo ,
1109
- loc : left . node . loc ?? null ,
1110
- suggestions : null ,
1106
+ CompilerError . invariant ( left . isLVal ( ) , {
1107
+ loc : leftLoc ,
1108
+ reason : 'Expected ForOf init to be a variable declaration or lval' ,
1111
1109
} ) ;
1112
- return ;
1110
+ const assign = lowerAssignment (
1111
+ builder ,
1112
+ leftLoc ,
1113
+ InstructionKind . Reassign ,
1114
+ left ,
1115
+ advanceIterator ,
1116
+ 'Assignment' ,
1117
+ ) ;
1118
+ test = lowerValueToTemporary ( builder , assign ) ;
1113
1119
}
1114
1120
builder . terminateWithContinuation (
1115
1121
{
@@ -1166,6 +1172,11 @@ function lowerStatement(
1166
1172
const left = stmt . get ( 'left' ) ;
1167
1173
const leftLoc = left . node . loc ?? GeneratedSource ;
1168
1174
let test : Place ;
1175
+ const nextPropertyTemp = lowerValueToTemporary ( builder , {
1176
+ kind : 'NextPropertyOf' ,
1177
+ loc : leftLoc ,
1178
+ value,
1179
+ } ) ;
1169
1180
if ( left . isVariableDeclaration ( ) ) {
1170
1181
const declarations = left . get ( 'declarations' ) ;
1171
1182
CompilerError . invariant ( declarations . length === 1 , {
@@ -1175,11 +1186,6 @@ function lowerStatement(
1175
1186
suggestions : null ,
1176
1187
} ) ;
1177
1188
const id = declarations [ 0 ] . get ( 'id' ) ;
1178
- const nextPropertyTemp = lowerValueToTemporary ( builder , {
1179
- kind : 'NextPropertyOf' ,
1180
- loc : leftLoc ,
1181
- value,
1182
- } ) ;
1183
1189
const assign = lowerAssignment (
1184
1190
builder ,
1185
1191
leftLoc ,
@@ -1190,13 +1196,19 @@ function lowerStatement(
1190
1196
) ;
1191
1197
test = lowerValueToTemporary ( builder , assign ) ;
1192
1198
} else {
1193
- builder . errors . push ( {
1194
- reason : `(BuildHIR::lowerStatement) Handle ${ left . type } inits in ForInStatement` ,
1195
- severity : ErrorSeverity . Todo ,
1196
- loc : left . node . loc ?? null ,
1197
- suggestions : null ,
1199
+ CompilerError . invariant ( left . isLVal ( ) , {
1200
+ loc : leftLoc ,
1201
+ reason : 'Expected ForIn init to be a variable declaration or lval' ,
1198
1202
} ) ;
1199
- return ;
1203
+ const assign = lowerAssignment (
1204
+ builder ,
1205
+ leftLoc ,
1206
+ InstructionKind . Reassign ,
1207
+ left ,
1208
+ nextPropertyTemp ,
1209
+ 'Assignment' ,
1210
+ ) ;
1211
+ test = lowerValueToTemporary ( builder , assign ) ;
1200
1212
}
1201
1213
builder . terminateWithContinuation (
1202
1214
{
0 commit comments