Skip to content

Commit 40222d1

Browse files
authored
Fix for-in emit under systemjs (microsoft#19223)
1 parent bac30fc commit 40222d1

5 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/compiler/transformers/module/system.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ namespace ts {
826826
/*needsValue*/ false,
827827
createAssignment
828828
)
829-
: createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression));
829+
: node.initializer ? createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)) : node.name;
830830
}
831831

832832
/**
@@ -1296,6 +1296,9 @@ namespace ts {
12961296
let expressions: Expression[];
12971297
for (const variable of node.declarations) {
12981298
expressions = append(expressions, transformInitializedVariable(variable, /*isExportedDeclaration*/ false));
1299+
if (!variable.initializer) {
1300+
hoistBindingElement(variable);
1301+
}
12991302
}
13001303

13011304
return expressions ? inlineExpressions(expressions) : createOmittedExpression();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [systemJsForInNoException.ts]
2+
export const obj = { a: 1 };
3+
for (var key in obj)
4+
console.log(obj[key]);
5+
6+
//// [systemJsForInNoException.js]
7+
System.register([], function (exports_1, context_1) {
8+
"use strict";
9+
var __moduleName = context_1 && context_1.id;
10+
var obj, key;
11+
return {
12+
setters: [],
13+
execute: function () {
14+
exports_1("obj", obj = { a: 1 });
15+
for (key in obj)
16+
console.log(obj[key]);
17+
}
18+
};
19+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/systemJsForInNoException.ts ===
2+
export const obj = { a: 1 };
3+
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
4+
>a : Symbol(a, Decl(systemJsForInNoException.ts, 0, 20))
5+
6+
for (var key in obj)
7+
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))
8+
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
9+
10+
console.log(obj[key]);
11+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
12+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
13+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
14+
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
15+
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))
16+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/systemJsForInNoException.ts ===
2+
export const obj = { a: 1 };
3+
>obj : { a: number; }
4+
>{ a: 1 } : { a: number; }
5+
>a : number
6+
>1 : 1
7+
8+
for (var key in obj)
9+
>key : string
10+
>obj : { a: number; }
11+
12+
console.log(obj[key]);
13+
>console.log(obj[key]) : void
14+
>console.log : (message?: any, ...optionalParams: any[]) => void
15+
>console : Console
16+
>log : (message?: any, ...optionalParams: any[]) => void
17+
>obj[key] : any
18+
>obj : { a: number; }
19+
>key : string
20+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @module: system
2+
// @lib: es6,dom
3+
export const obj = { a: 1 };
4+
for (var key in obj)
5+
console.log(obj[key]);

0 commit comments

Comments
 (0)