Fix for-in emit under systemjs (#19223)
This commit is contained in:
parent
bac30fc1a2
commit
40222d1a77
|
@ -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();
|
||||
|
|
19
tests/baselines/reference/systemJsForInNoException.js
Normal file
19
tests/baselines/reference/systemJsForInNoException.js
Normal 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]);
|
||||
}
|
||||
};
|
||||
});
|
16
tests/baselines/reference/systemJsForInNoException.symbols
Normal file
16
tests/baselines/reference/systemJsForInNoException.symbols
Normal 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))
|
||||
|
20
tests/baselines/reference/systemJsForInNoException.types
Normal file
20
tests/baselines/reference/systemJsForInNoException.types
Normal 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
|
||||
|
5
tests/cases/compiler/systemJsForInNoException.ts
Normal file
5
tests/cases/compiler/systemJsForInNoException.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
// @module: system
|
||||
// @lib: es6,dom
|
||||
export const obj = { a: 1 };
|
||||
for (var key in obj)
|
||||
console.log(obj[key]);
|
Loading…
Reference in a new issue