mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Merge pull request #6498 from Microsoft/convertLoopWithMissingInitializer
do not crash if initializer in For-statement is missing
This commit is contained in:
commit
efc573f263
@ -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;
|
||||
|
||||
35
tests/baselines/reference/capturedLetConstInLoop11.js
Normal file
35
tests/baselines/reference/capturedLetConstInLoop11.js
Normal file
@ -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
tests/baselines/reference/capturedLetConstInLoop11.symbols
Normal file
24
tests/baselines/reference/capturedLetConstInLoop11.symbols
Normal file
@ -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
tests/baselines/reference/capturedLetConstInLoop11.types
Normal file
29
tests/baselines/reference/capturedLetConstInLoop11.types
Normal file
@ -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
tests/baselines/reference/capturedLetConstInLoop11_ES6.js
Normal file
28
tests/baselines/reference/capturedLetConstInLoop11_ES6.js
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
tests/baselines/reference/capturedLetConstInLoop11_ES6.types
Normal file
29
tests/baselines/reference/capturedLetConstInLoop11_ES6.types
Normal file
@ -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
tests/cases/compiler/capturedLetConstInLoop11.ts
Normal file
13
tests/cases/compiler/capturedLetConstInLoop11.ts
Normal file
@ -0,0 +1,13 @@
|
||||
for (;;) {
|
||||
let x = 1;
|
||||
() => x;
|
||||
}
|
||||
|
||||
function foo() {
|
||||
for (;;) {
|
||||
const a = 0;
|
||||
switch(a) {
|
||||
case 0: return () => a;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
tests/cases/compiler/capturedLetConstInLoop11_ES6.ts
Normal file
14
tests/cases/compiler/capturedLetConstInLoop11_ES6.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @target: ES6
|
||||
for (;;) {
|
||||
let x = 1;
|
||||
() => x;
|
||||
}
|
||||
|
||||
function foo() {
|
||||
for (;;) {
|
||||
const a = 0;
|
||||
switch(a) {
|
||||
case 0: return () => a;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user