@@ -1078,6 +1078,12 @@ function lowerStatement(
10781078 const left = stmt . get ( 'left' ) ;
10791079 const leftLoc = left . node . loc ?? GeneratedSource ;
10801080 let test : Place ;
1081+ const advanceIterator = lowerValueToTemporary ( builder , {
1082+ kind : 'IteratorNext' ,
1083+ loc : leftLoc ,
1084+ iterator : { ...iterator } ,
1085+ collection : { ...value } ,
1086+ } ) ;
10811087 if ( left . isVariableDeclaration ( ) ) {
10821088 const declarations = left . get ( 'declarations' ) ;
10831089 CompilerError . invariant ( declarations . length === 1 , {
@@ -1087,12 +1093,6 @@ function lowerStatement(
10871093 suggestions : null ,
10881094 } ) ;
10891095 const id = declarations [ 0 ] . get ( 'id' ) ;
1090- const advanceIterator = lowerValueToTemporary ( builder , {
1091- kind : 'IteratorNext' ,
1092- loc : leftLoc ,
1093- iterator : { ...iterator } ,
1094- collection : { ...value } ,
1095- } ) ;
10961096 const assign = lowerAssignment (
10971097 builder ,
10981098 leftLoc ,
@@ -1103,13 +1103,19 @@ function lowerStatement(
11031103 ) ;
11041104 test = lowerValueToTemporary ( builder , assign ) ;
11051105 } 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' ,
11111109 } ) ;
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 ) ;
11131119 }
11141120 builder . terminateWithContinuation (
11151121 {
@@ -1166,6 +1172,11 @@ function lowerStatement(
11661172 const left = stmt . get ( 'left' ) ;
11671173 const leftLoc = left . node . loc ?? GeneratedSource ;
11681174 let test : Place ;
1175+ const nextPropertyTemp = lowerValueToTemporary ( builder , {
1176+ kind : 'NextPropertyOf' ,
1177+ loc : leftLoc ,
1178+ value,
1179+ } ) ;
11691180 if ( left . isVariableDeclaration ( ) ) {
11701181 const declarations = left . get ( 'declarations' ) ;
11711182 CompilerError . invariant ( declarations . length === 1 , {
@@ -1175,11 +1186,6 @@ function lowerStatement(
11751186 suggestions : null ,
11761187 } ) ;
11771188 const id = declarations [ 0 ] . get ( 'id' ) ;
1178- const nextPropertyTemp = lowerValueToTemporary ( builder , {
1179- kind : 'NextPropertyOf' ,
1180- loc : leftLoc ,
1181- value,
1182- } ) ;
11831189 const assign = lowerAssignment (
11841190 builder ,
11851191 leftLoc ,
@@ -1190,13 +1196,19 @@ function lowerStatement(
11901196 ) ;
11911197 test = lowerValueToTemporary ( builder , assign ) ;
11921198 } 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' ,
11981202 } ) ;
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 ) ;
12001212 }
12011213 builder . terminateWithContinuation (
12021214 {
0 commit comments