mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge pull request #10883 from Microsoft/fix10876
Fix missing final label
This commit is contained in:
@@ -2629,7 +2629,7 @@ namespace ts {
|
||||
* Flush the final label of the generator function body.
|
||||
*/
|
||||
function flushFinalLabel(operationIndex: number): void {
|
||||
if (!lastOperationWasCompletion) {
|
||||
if (isFinalLabelReachable(operationIndex)) {
|
||||
tryEnterLabel(operationIndex);
|
||||
withBlockStack = undefined;
|
||||
writeReturn(/*expression*/ undefined, /*operationLocation*/ undefined);
|
||||
@@ -2642,6 +2642,34 @@ namespace ts {
|
||||
updateLabelExpressions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the final label of the generator function body
|
||||
* is reachable by user code.
|
||||
*/
|
||||
function isFinalLabelReachable(operationIndex: number) {
|
||||
// if the last operation was *not* a completion (return/throw) then
|
||||
// the final label is reachable.
|
||||
if (!lastOperationWasCompletion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if there are no labels defined or referenced, then the final label is
|
||||
// not reachable.
|
||||
if (!labelOffsets || !labelExpressions) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the label for this offset is referenced, then the final label
|
||||
// is reachable.
|
||||
for (let label = 0; label < labelOffsets.length; label++) {
|
||||
if (labelOffsets[label] === operationIndex && labelExpressions[label]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a case clause for the last label and sets the new label.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user