@@ -3614,10 +3614,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3614
3614
//
3615
3615
// for (let v of arr) { }
3616
3616
//
3617
- // we don't want to emit a temporary variable for the RHS, just use it directly.
3618
- let rhsIsIdentifier = node . expression . kind === SyntaxKind . Identifier ;
3617
+ // we can't reuse 'arr' because it might be modified within the body of the loop.
3619
3618
let counter = createTempVariable ( TempFlags . _i ) ;
3620
- let rhsReference = rhsIsIdentifier ? < Identifier > node . expression : createTempVariable ( TempFlags . Auto ) ;
3619
+ let rhsReference = createSynthesizedNode ( SyntaxKind . Identifier ) as Identifier ;
3620
+ rhsReference . text = node . expression . kind === SyntaxKind . Identifier ?
3621
+ makeUniqueName ( ( < Identifier > node . expression ) . text ) :
3622
+ makeTempVariableName ( TempFlags . Auto ) ;
3621
3623
3622
3624
// This is the let keyword for the counter and rhsReference. The let keyword for
3623
3625
// the LHS will be emitted inside the body.
@@ -3629,15 +3631,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3629
3631
write ( " = 0" ) ;
3630
3632
emitEnd ( node . expression ) ;
3631
3633
3632
- if ( ! rhsIsIdentifier ) {
3633
- // , _a = expr
3634
- write ( ", " ) ;
3635
- emitStart ( node . expression ) ;
3636
- emitNodeWithoutSourceMap ( rhsReference ) ;
3637
- write ( " = " ) ;
3638
- emitNodeWithoutSourceMap ( node . expression ) ;
3639
- emitEnd ( node . expression ) ;
3640
- }
3634
+ // , _a = expr
3635
+ write ( ", " ) ;
3636
+ emitStart ( node . expression ) ;
3637
+ emitNodeWithoutSourceMap ( rhsReference ) ;
3638
+ write ( " = " ) ;
3639
+ emitNodeWithoutSourceMap ( node . expression ) ;
3640
+ emitEnd ( node . expression ) ;
3641
3641
3642
3642
write ( "; " ) ;
3643
3643
0 commit comments