Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions 7 src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ namespace ts {
}

startLexicalEnvironment();
let loopBody = visitNode(node.statement, visitor, isStatement);
let loopBody = visitNode(node.statement, visitor, isStatement, /*optional*/ false, liftToBlock);
const lexicalEnvironment = endLexicalEnvironment();

const currentState = convertedLoopState;
Expand All @@ -2305,7 +2305,10 @@ namespace ts {
loopBody = createBlock(statements, /*location*/ undefined, /*multiline*/ true);
}

if (!isBlock(loopBody)) {
if (isBlock(loopBody)) {
loopBody.multiLine = true;
}
else {
loopBody = createBlock([loopBody], /*location*/ undefined, /*multiline*/ true);
}

Expand Down
47 changes: 47 additions & 0 deletions 47 tests/baselines/reference/nestedLoops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [nestedLoops.ts]
export class Test {
constructor() {

let outerArray: Array<number> = [1, 2, 3];
let innerArray: Array<number> = [1, 2, 3];

for (let outer of outerArray)
for (let inner of innerArray) {
this.aFunction((newValue, oldValue) => {
let x = outer + inner + newValue;
});
}
}

public aFunction(func: (newValue: any, oldValue: any) => void): void {
}
}

//// [nestedLoops.js]
"use strict";
var Test = (function () {
function Test() {
var outerArray = [1, 2, 3];
var innerArray = [1, 2, 3];
var _loop_1 = function (outer) {
var _loop_2 = function (inner) {
this_1.aFunction(function (newValue, oldValue) {
var x = outer + inner + newValue;
});
};
for (var _i = 0, innerArray_1 = innerArray; _i < innerArray_1.length; _i++) {
var inner = innerArray_1[_i];
_loop_2(inner);
}
};
var this_1 = this;
for (var _i = 0, outerArray_1 = outerArray; _i < outerArray_1.length; _i++) {
var outer = outerArray_1[_i];
_loop_1(outer);
}
}
Test.prototype.aFunction = function (func) {
};
return Test;
}());
exports.Test = Test;
46 changes: 46 additions & 0 deletions 46 tests/baselines/reference/nestedLoops.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=== tests/cases/compiler/nestedLoops.ts ===
export class Test {
>Test : Symbol(Test, Decl(nestedLoops.ts, 0, 0))

constructor() {

let outerArray: Array<number> = [1, 2, 3];
>outerArray : Symbol(outerArray, Decl(nestedLoops.ts, 3, 11))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

let innerArray: Array<number> = [1, 2, 3];
>innerArray : Symbol(innerArray, Decl(nestedLoops.ts, 4, 11))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

for (let outer of outerArray)
>outer : Symbol(outer, Decl(nestedLoops.ts, 6, 16))
>outerArray : Symbol(outerArray, Decl(nestedLoops.ts, 3, 11))

for (let inner of innerArray) {
>inner : Symbol(inner, Decl(nestedLoops.ts, 7, 20))
>innerArray : Symbol(innerArray, Decl(nestedLoops.ts, 4, 11))

this.aFunction((newValue, oldValue) => {
>this.aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5))
>this : Symbol(Test, Decl(nestedLoops.ts, 0, 0))
>aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5))
>newValue : Symbol(newValue, Decl(nestedLoops.ts, 8, 32))
>oldValue : Symbol(oldValue, Decl(nestedLoops.ts, 8, 41))

let x = outer + inner + newValue;
>x : Symbol(x, Decl(nestedLoops.ts, 9, 23))
>outer : Symbol(outer, Decl(nestedLoops.ts, 6, 16))
>inner : Symbol(inner, Decl(nestedLoops.ts, 7, 20))
>newValue : Symbol(newValue, Decl(nestedLoops.ts, 8, 32))

});
}
}

public aFunction(func: (newValue: any, oldValue: any) => void): void {
>aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5))
>func : Symbol(func, Decl(nestedLoops.ts, 14, 21))
>newValue : Symbol(newValue, Decl(nestedLoops.ts, 14, 28))
>oldValue : Symbol(oldValue, Decl(nestedLoops.ts, 14, 42))
}
}
58 changes: 58 additions & 0 deletions 58 tests/baselines/reference/nestedLoops.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
=== tests/cases/compiler/nestedLoops.ts ===
export class Test {
>Test : Test

constructor() {

let outerArray: Array<number> = [1, 2, 3];
>outerArray : number[]
>Array : T[]
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3

let innerArray: Array<number> = [1, 2, 3];
>innerArray : number[]
>Array : T[]
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3

for (let outer of outerArray)
>outer : number
>outerArray : number[]

for (let inner of innerArray) {
>inner : number
>innerArray : number[]

this.aFunction((newValue, oldValue) => {
>this.aFunction((newValue, oldValue) => { let x = outer + inner + newValue; }) : void
>this.aFunction : (func: (newValue: any, oldValue: any) => void) => void
>this : this
>aFunction : (func: (newValue: any, oldValue: any) => void) => void
>(newValue, oldValue) => { let x = outer + inner + newValue; } : (newValue: any, oldValue: any) => void
>newValue : any
>oldValue : any

let x = outer + inner + newValue;
>x : any
>outer + inner + newValue : any
>outer + inner : number
>outer : number
>inner : number
>newValue : any

});
}
}

public aFunction(func: (newValue: any, oldValue: any) => void): void {
>aFunction : (func: (newValue: any, oldValue: any) => void) => void
>func : (newValue: any, oldValue: any) => void
>newValue : any
>oldValue : any
}
}
18 changes: 18 additions & 0 deletions 18 tests/cases/compiler/nestedLoops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @target: es5
export class Test {
constructor() {

let outerArray: Array<number> = [1, 2, 3];
let innerArray: Array<number> = [1, 2, 3];

for (let outer of outerArray)
for (let inner of innerArray) {
this.aFunction((newValue, oldValue) => {
let x = outer + inner + newValue;
});
}
}

public aFunction(func: (newValue: any, oldValue: any) => void): void {
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.