Fix for-in emit under systemjs (#19223)

This commit is contained in:
Wesley Wigham 2017-10-16 12:57:23 -07:00 committed by GitHub
parent bac30fc1a2
commit 40222d1a77
5 changed files with 64 additions and 1 deletions

View file

@ -826,7 +826,7 @@ namespace ts {
/*needsValue*/ false,
createAssignment
)
: createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression));
: node.initializer ? createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)) : node.name;
}
/**
@ -1296,6 +1296,9 @@ namespace ts {
let expressions: Expression[];
for (const variable of node.declarations) {
expressions = append(expressions, transformInitializedVariable(variable, /*isExportedDeclaration*/ false));
if (!variable.initializer) {
hoistBindingElement(variable);
}
}
return expressions ? inlineExpressions(expressions) : createOmittedExpression();

View file

@ -0,0 +1,19 @@
//// [systemJsForInNoException.ts]
export const obj = { a: 1 };
for (var key in obj)
console.log(obj[key]);
//// [systemJsForInNoException.js]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var obj, key;
return {
setters: [],
execute: function () {
exports_1("obj", obj = { a: 1 });
for (key in obj)
console.log(obj[key]);
}
};
});

View file

@ -0,0 +1,16 @@
=== tests/cases/compiler/systemJsForInNoException.ts ===
export const obj = { a: 1 };
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
>a : Symbol(a, Decl(systemJsForInNoException.ts, 0, 20))
for (var key in obj)
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
console.log(obj[key]);
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))

View file

@ -0,0 +1,20 @@
=== tests/cases/compiler/systemJsForInNoException.ts ===
export const obj = { a: 1 };
>obj : { a: number; }
>{ a: 1 } : { a: number; }
>a : number
>1 : 1
for (var key in obj)
>key : string
>obj : { a: number; }
console.log(obj[key]);
>console.log(obj[key]) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>obj[key] : any
>obj : { a: number; }
>key : string

View file

@ -0,0 +1,5 @@
// @module: system
// @lib: es6,dom
export const obj = { a: 1 };
for (var key in obj)
console.log(obj[key]);