-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed crashed related to emptied labeled statements in converted loop…
… bodies (#86334)
- Loading branch information
Showing
16 changed files
with
462 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/capturedLetConstInLoop14.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
capturedLetConstInLoop14.ts(7,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'v' must be of type 'number', but here has type 'any'. | ||
|
||
|
||
==== capturedLetConstInLoop14.ts (1 errors) ==== | ||
function use(v: number) {} | ||
|
||
function foo(x: number) { | ||
var v = 1; | ||
do { | ||
let x = v; | ||
var v; | ||
~ | ||
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'v' must be of type 'number', but here has type 'any'. | ||
!!! related TS6203 capturedLetConstInLoop14.ts:4:7: 'v' was also declared here. | ||
var v = 2; | ||
() => x + v; | ||
} while (false); | ||
|
||
use(v); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//// [tests/cases/compiler/capturedLetConstInLoop14.ts] //// | ||
|
||
//// [capturedLetConstInLoop14.ts] | ||
function use(v: number) {} | ||
|
||
function foo(x: number) { | ||
var v = 1; | ||
do { | ||
let x = v; | ||
var v; | ||
var v = 2; | ||
() => x + v; | ||
} while (false); | ||
|
||
use(v); | ||
} | ||
|
||
|
||
//// [capturedLetConstInLoop14.js] | ||
"use strict"; | ||
function use(v) { } | ||
function foo(x) { | ||
var v = 1; | ||
var _loop_1 = function () { | ||
var x_1 = v; | ||
v = 2; | ||
(function () { return x_1 + v; }); | ||
}; | ||
var v, v; | ||
do { | ||
_loop_1(); | ||
} while (false); | ||
use(v); | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
labeledStatementDeclarationListInLoopNoCrash1.ts(3,11): error TS1123: Variable declaration list cannot be empty. | ||
|
||
|
||
==== labeledStatementDeclarationListInLoopNoCrash1.ts (1 errors) ==== | ||
for (let x of []) { | ||
var v0 = x; | ||
foo: var; | ||
|
||
!!! error TS1123: Variable declaration list cannot be empty. | ||
(function() { return x + v0}); | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementDeclarationListInLoopNoCrash1.ts] //// | ||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash1.ts] | ||
for (let x of []) { | ||
var v0 = x; | ||
foo: var; | ||
(function() { return x + v0}); | ||
} | ||
|
||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash1.js] | ||
"use strict"; | ||
var _loop_1 = function (x) { | ||
v0 = x; | ||
foo: ; | ||
(function () { return x + v0; }); | ||
}; | ||
var v0; | ||
for (var _i = 0, _a = []; _i < _a.length; _i++) { | ||
var x = _a[_i]; | ||
_loop_1(x); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementDeclarationListInLoopNoCrash2.ts] //// | ||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash2.ts] | ||
for (let x of []) { | ||
var v0 = x; | ||
foo: var y; | ||
(function() { return x + v0}); | ||
} | ||
|
||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash2.js] | ||
"use strict"; | ||
var _loop_1 = function (x) { | ||
v0 = x; | ||
foo: ; | ||
(function () { return x + v0; }); | ||
}; | ||
var v0, y; | ||
for (var _i = 0, _a = []; _i < _a.length; _i++) { | ||
var x = _a[_i]; | ||
_loop_1(x); | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash3.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(9,12): error TS2339: Property 'classFormat' does not exist on type 'ParseThemeData'. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,12): error TS1005: ',' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,12): error TS2304: Cannot find name 'font'. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,21): error TS1005: ',' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,23): error TS1135: Argument expression expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,26): error TS1134: Variable declaration expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,41): error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,42): error TS1005: ')' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,53): error TS2304: Cannot find name 'fontSize'. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(15,61): error TS1005: ';' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,12): error TS1005: ';' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,23): error TS1134: Variable declaration expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,38): error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,39): error TS1005: ')' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,50): error TS2304: Cannot find name 'height'. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(16,56): error TS1005: ';' expected. | ||
labeledStatementDeclarationListInLoopNoCrash3.ts(22,1): error TS1160: Unterminated template literal. | ||
|
||
|
||
==== labeledStatementDeclarationListInLoopNoCrash3.ts (17 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/59345 | ||
|
||
export class ParseThemeData { | ||
parseButton(button: any) { | ||
const {type, size} = button; | ||
for (let item of type) { | ||
const fontType = item.type; | ||
const style = (state: string) => `color: var(--button-${fontType}-${state}-font-color)`; | ||
this.classFormat(`${style('active')}); | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'classFormat' does not exist on type 'ParseThemeData'. | ||
} | ||
for (let item of size) { | ||
const fontType = item.type; | ||
this.classFormat( | ||
[ | ||
`font-size: var(--button-size-${fontType}-fontSize)`, | ||
~~~~ | ||
!!! error TS1005: ',' expected. | ||
~~~~ | ||
!!! error TS2304: Cannot find name 'font'. | ||
~ | ||
!!! error TS1005: ',' expected. | ||
~~~ | ||
!!! error TS1135: Argument expression expected. | ||
~ | ||
!!! error TS1134: Variable declaration expected. | ||
~ | ||
!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
~ | ||
!!! error TS1005: ')' expected. | ||
~~~~~~~~ | ||
!!! error TS2304: Cannot find name 'fontSize'. | ||
~ | ||
!!! error TS1005: ';' expected. | ||
`height: var(--button-size-${fontType}-height)`, | ||
~~~~~~ | ||
!!! error TS1005: ';' expected. | ||
~ | ||
!!! error TS1134: Variable declaration expected. | ||
~ | ||
!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
~ | ||
!!! error TS1005: ')' expected. | ||
~~~~~~ | ||
!!! error TS2304: Cannot find name 'height'. | ||
~ | ||
!!! error TS1005: ';' expected. | ||
].join(';') | ||
); | ||
} | ||
} | ||
} | ||
|
||
|
||
!!! error TS1160: Unterminated template literal. |
63 changes: 63 additions & 0 deletions
63
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementDeclarationListInLoopNoCrash3.ts] //// | ||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash3.ts] | ||
// https://github.com/microsoft/TypeScript/issues/59345 | ||
|
||
export class ParseThemeData { | ||
parseButton(button: any) { | ||
const {type, size} = button; | ||
for (let item of type) { | ||
const fontType = item.type; | ||
const style = (state: string) => `color: var(--button-${fontType}-${state}-font-color)`; | ||
this.classFormat(`${style('active')}); | ||
} | ||
for (let item of size) { | ||
const fontType = item.type; | ||
this.classFormat( | ||
[ | ||
`font-size: var(--button-size-${fontType}-fontSize)`, | ||
`height: var(--button-size-${fontType}-height)`, | ||
].join(';') | ||
); | ||
} | ||
} | ||
} | ||
|
||
|
||
//// [labeledStatementDeclarationListInLoopNoCrash3.js] | ||
"use strict"; | ||
// https://github.com/microsoft/TypeScript/issues/59345 | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParseThemeData = void 0; | ||
var ParseThemeData = /** @class */ (function () { | ||
function ParseThemeData() { | ||
} | ||
ParseThemeData.prototype.parseButton = function (button) { | ||
var type = button.type, size = button.size; | ||
var _loop_1 = function (item) { | ||
var fontType = item.type; | ||
var style = function (state) { return "color: var(--button-".concat(fontType, "-").concat(state, "-font-color)"); }; | ||
this_1.classFormat("".concat(style('active'), ");\n }\n for (let item of size) {\n const fontType = item.type;\n this.classFormat(\n [\n "), font - size); | ||
(--button - size - $); | ||
{ | ||
fontType; | ||
} | ||
-fontSize; | ||
",\n "; | ||
height: ; | ||
(--button - size - $); | ||
{ | ||
fontType; | ||
} | ||
-height; | ||
",\n ].join(';')\n );\n }\n }\n}\n"; | ||
}; | ||
var this_1 = this; | ||
for (var _i = 0, type_1 = type; _i < type_1.length; _i++) { | ||
var item = type_1[_i]; | ||
_loop_1(item); | ||
} | ||
}; | ||
return ParseThemeData; | ||
}()); | ||
exports.ParseThemeData = ParseThemeData; |
72 changes: 72 additions & 0 deletions
72
tests/baselines/reference/labeledStatementDeclarationListInLoopNoCrash4.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(7,12): error TS2339: Property 'classFormat' does not exist on type 'ParseThemeData'. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,12): error TS1005: ',' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,12): error TS2304: Cannot find name 'font'. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,21): error TS1005: ',' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,23): error TS1135: Argument expression expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,26): error TS1134: Variable declaration expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,41): error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,42): error TS1005: ')' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,53): error TS2304: Cannot find name 'fontSize'. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(13,61): error TS1005: ';' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(14,12): error TS1005: ';' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(14,27): error TS1005: ',' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(20,1): error TS1005: '}' expected. | ||
labeledStatementDeclarationListInLoopNoCrash4.ts(20,1): error TS1160: Unterminated template literal. | ||
|
||
|
||
==== labeledStatementDeclarationListInLoopNoCrash4.ts (14 errors) ==== | ||
export class ParseThemeData { | ||
parseButton(button: any) { | ||
const {type, size} = button; | ||
for (let item of type) { | ||
const fontType = item.type; | ||
const style = (state: string) => `color: var(--button-${fontType}-${state}-font-color)`; | ||
this.classFormat(`${style('active')}); | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'classFormat' does not exist on type 'ParseThemeData'. | ||
} | ||
for (let item of size) { | ||
const fontType = item.type; | ||
this.classFormat( | ||
[ | ||
`font-size: var(--button-size-${fontType}-fontSize)`, | ||
~~~~ | ||
!!! error TS1005: ',' expected. | ||
~~~~ | ||
!!! error TS2304: Cannot find name 'font'. | ||
~ | ||
!!! error TS1005: ',' expected. | ||
~~~ | ||
!!! error TS1135: Argument expression expected. | ||
~ | ||
!!! error TS1134: Variable declaration expected. | ||
~ | ||
!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery`. | ||
~ | ||
!!! error TS1005: ')' expected. | ||
~~~~~~~~ | ||
!!! error TS2304: Cannot find name 'fontSize'. | ||
~ | ||
!!! error TS1005: ';' expected. | ||
`height: var foo`, | ||
~~~~~~ | ||
!!! error TS1005: ';' expected. | ||
~~ | ||
].join(';') | ||
~~~~~~~~~~~~~~~~~~~ | ||
); | ||
~~~~~~~~ | ||
} | ||
~~~~~ | ||
} | ||
~~~ | ||
} | ||
~ | ||
|
||
|
||
!!! error TS1005: ',' expected. | ||
|
||
!!! error TS1005: '}' expected. | ||
!!! related TS1007 labeledStatementDeclarationListInLoopNoCrash4.ts:4:28: The parser expected to find a '}' to match the '{' token here. | ||
|
||
!!! error TS1160: Unterminated template literal. |
Oops, something went wrong.