File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
src/compiler/transformers Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -2629,7 +2629,7 @@ namespace ts {
2629
2629
* Flush the final label of the generator function body.
2630
2630
*/
2631
2631
function flushFinalLabel ( operationIndex : number ) : void {
2632
- if ( ! lastOperationWasCompletion ) {
2632
+ if ( isFinalLabelReachable ( operationIndex ) ) {
2633
2633
tryEnterLabel ( operationIndex ) ;
2634
2634
withBlockStack = undefined ;
2635
2635
writeReturn ( /*expression*/ undefined , /*operationLocation*/ undefined ) ;
@@ -2642,6 +2642,34 @@ namespace ts {
2642
2642
updateLabelExpressions ( ) ;
2643
2643
}
2644
2644
2645
+ /**
2646
+ * Tests whether the final label of the generator function body
2647
+ * is reachable by user code.
2648
+ */
2649
+ function isFinalLabelReachable ( operationIndex : number ) {
2650
+ // if the last operation was *not* a completion (return/throw) then
2651
+ // the final label is reachable.
2652
+ if ( ! lastOperationWasCompletion ) {
2653
+ return true ;
2654
+ }
2655
+
2656
+ // if there are no labels defined or referenced, then the final label is
2657
+ // not reachable.
2658
+ if ( ! labelOffsets || ! labelExpressions ) {
2659
+ return false ;
2660
+ }
2661
+
2662
+ // if the label for this offset is referenced, then the final label
2663
+ // is reachable.
2664
+ for ( let label = 0 ; label < labelOffsets . length ; label ++ ) {
2665
+ if ( labelOffsets [ label ] === operationIndex && labelExpressions [ label ] ) {
2666
+ return true ;
2667
+ }
2668
+ }
2669
+
2670
+ return false ;
2671
+ }
2672
+
2645
2673
/**
2646
2674
* Appends a case clause for the last label and sets the new label.
2647
2675
*
You can’t perform that action at this time.
0 commit comments