Skip to content

Commit 90bac23

Browse files
Always generate an identifier in a for-of loop.
1 parent f36b6ab commit 90bac23

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/compiler/emitter.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,10 +3614,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
36143614
//
36153615
// for (let v of arr) { }
36163616
//
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.
36193618
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);
36213623

36223624
// This is the let keyword for the counter and rhsReference. The let keyword for
36233625
// the LHS will be emitted inside the body.
@@ -3629,15 +3631,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
36293631
write(" = 0");
36303632
emitEnd(node.expression);
36313633

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);
36413641

36423642
write("; ");
36433643

0 commit comments

Comments
 (0)