File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
src/transformation/visitors/loops Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { FunctionVisitor } from "../../context";
44import { ForbiddenForIn , UnsupportedForInVariable } from "../../utils/errors" ;
55import { isArrayType } from "../../utils/typescript" ;
66import { transformIdentifier } from "../identifier" ;
7+ import { transformAssignment } from "../binary-expression/assignments" ;
78import { getVariableDeclarationBinding , transformLoopBody } from "./utils" ;
89
910export const transformForInStatement : FunctionVisitor < ts . ForInStatement > = ( statement , context ) => {
@@ -33,11 +34,14 @@ export const transformForInStatement: FunctionVisitor<ts.ForInStatement> = (stat
3334 // Iteration variable becomes ____key
3435 iterationVariable = lua . createIdentifier ( "____key" ) ;
3536 // Push variable = ____key to the start of the loop body to match TS scoping
36- const initializer = lua . createAssignmentStatement (
37- transformIdentifier ( context , statement . initializer ) ,
38- iterationVariable
37+ const assignment = transformAssignment (
38+ context ,
39+ statement . initializer ,
40+ iterationVariable ,
41+ statement . initializer
3942 ) ;
40- body . statements . unshift ( initializer ) ;
43+
44+ body . statements . unshift ( ...assignment ) ;
4145 } else {
4246 // This should never occur
4347 throw UnsupportedForInVariable ( statement . initializer ) ;
Original file line number Diff line number Diff line change @@ -253,3 +253,22 @@ test("export as specifier shouldn't effect local vars", () => {
253253 a = 6;
254254 ` . expectToMatchJsResult ( ) ;
255255} ) ;
256+
257+ test ( "export modified in for in loop" , ( ) => {
258+ util . testModule `
259+ export let foo = '';
260+ for (foo in { x: true }) {}
261+ `
262+ . setReturnExport ( "x" )
263+ . expectToMatchJsResult ( ) ;
264+ } ) ;
265+
266+ test ( "export dependency modified in for in loop" , ( ) => {
267+ util . testModule `
268+ let foo = '';
269+ export { foo as bar };
270+ for (foo in { x: true }) {}
271+ `
272+ . setReturnExport ( "bar" )
273+ . expectToEqual ( "x" ) ;
274+ } ) ;
You can’t perform that action at this time.
0 commit comments