Skip to content

do not crash if initializer in For-statement is missing #6498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2016
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
3 changes: 2 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
case SyntaxKind.ForOfStatement:
if ((<ForStatement | ForInStatement | ForOfStatement>node).initializer.kind === SyntaxKind.VariableDeclarationList) {
const initializer = (<ForStatement | ForInStatement | ForOfStatement>node).initializer;
if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) {
loopInitializer = <VariableDeclarationList>(<ForStatement | ForInStatement | ForOfStatement>node).initializer;
}
break;
Expand Down
35 changes: 35 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [capturedLetConstInLoop11.ts]
for (;;) {
let x = 1;
() => x;
}

function foo() {
for (;;) {
const a = 0;
switch(a) {
case 0: return () => a;
}
}
}

//// [capturedLetConstInLoop11.js]
var _loop_1 = function() {
var x = 1;
(function () { return x; });
};
for (;;) {
_loop_1();
}
function foo() {
var _loop_2 = function() {
var a = 0;
switch (a) {
case 0: return { value: function () { return a; } };
}
};
for (;;) {
var state_2 = _loop_2();
if (typeof state_2 === "object") return state_2.value
}
}
24 changes: 24 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/capturedLetConstInLoop11.ts ===
for (;;) {
let x = 1;
>x : Symbol(x, Decl(capturedLetConstInLoop11.ts, 1, 7))

() => x;
>x : Symbol(x, Decl(capturedLetConstInLoop11.ts, 1, 7))
}

function foo() {
>foo : Symbol(foo, Decl(capturedLetConstInLoop11.ts, 3, 1))

for (;;) {
const a = 0;
>a : Symbol(a, Decl(capturedLetConstInLoop11.ts, 7, 13))

switch(a) {
>a : Symbol(a, Decl(capturedLetConstInLoop11.ts, 7, 13))

case 0: return () => a;
>a : Symbol(a, Decl(capturedLetConstInLoop11.ts, 7, 13))
}
}
}
29 changes: 29 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/capturedLetConstInLoop11.ts ===
for (;;) {
let x = 1;
>x : number
>1 : number

() => x;
>() => x : () => number
>x : number
}

function foo() {
>foo : () => () => number

for (;;) {
const a = 0;
>a : number
>0 : number

switch(a) {
>a : number

case 0: return () => a;
>0 : number
>() => a : () => number
>a : number
}
}
}
28 changes: 28 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11_ES6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [capturedLetConstInLoop11_ES6.ts]
for (;;) {
let x = 1;
() => x;
}

function foo() {
for (;;) {
const a = 0;
switch(a) {
case 0: return () => a;
}
}
}

//// [capturedLetConstInLoop11_ES6.js]
for (;;) {
let x = 1;
(() => x);
}
function foo() {
for (;;) {
const a = 0;
switch (a) {
case 0: return () => a;
}
}
}
24 changes: 24 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11_ES6.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/capturedLetConstInLoop11_ES6.ts ===
for (;;) {
let x = 1;
>x : Symbol(x, Decl(capturedLetConstInLoop11_ES6.ts, 1, 7))

() => x;
>x : Symbol(x, Decl(capturedLetConstInLoop11_ES6.ts, 1, 7))
}

function foo() {
>foo : Symbol(foo, Decl(capturedLetConstInLoop11_ES6.ts, 3, 1))

for (;;) {
const a = 0;
>a : Symbol(a, Decl(capturedLetConstInLoop11_ES6.ts, 7, 13))

switch(a) {
>a : Symbol(a, Decl(capturedLetConstInLoop11_ES6.ts, 7, 13))

case 0: return () => a;
>a : Symbol(a, Decl(capturedLetConstInLoop11_ES6.ts, 7, 13))
}
}
}
29 changes: 29 additions & 0 deletions tests/baselines/reference/capturedLetConstInLoop11_ES6.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/capturedLetConstInLoop11_ES6.ts ===
for (;;) {
let x = 1;
>x : number
>1 : number

() => x;
>() => x : () => number
>x : number
}

function foo() {
>foo : () => () => number

for (;;) {
const a = 0;
>a : number
>0 : number

switch(a) {
>a : number

case 0: return () => a;
>0 : number
>() => a : () => number
>a : number
}
}
}
13 changes: 13 additions & 0 deletions tests/cases/compiler/capturedLetConstInLoop11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
for (;;) {
let x = 1;
() => x;
}

function foo() {
for (;;) {
const a = 0;
switch(a) {
case 0: return () => a;
}
}
}
14 changes: 14 additions & 0 deletions tests/cases/compiler/capturedLetConstInLoop11_ES6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @target: ES6
for (;;) {
let x = 1;
() => x;
}

function foo() {
for (;;) {
const a = 0;
switch(a) {
case 0: return () => a;
}
}
}