@@ -557,14 +557,11 @@ namespace ts {
557557 function bindBreakOrContinueStatement ( n : BreakOrContinueStatement ) : boolean {
558558 // call bind on label (don't affect reachability)
559559 bind ( n . label ) ;
560- if ( n . kind === SyntaxKind . BreakStatement ) {
561- jumpToLabel ( n . label , currentReachabilityState ) ;
560+ // for continue case touch label so it will be marked a used
561+ const isValidJump = jumpToLabel ( n . label , n . kind === SyntaxKind . BreakStatement ? currentReachabilityState : Reachability . Unreachable ) ;
562+ if ( isValidJump ) {
563+ currentReachabilityState = Reachability . Unreachable ;
562564 }
563- else {
564- jumpToLabel ( n . label , Reachability . Unreachable ) ; // touch label so it will be marked a used
565- }
566- currentReachabilityState = Reachability . Unreachable ;
567-
568565 return true ;
569566 }
570567
@@ -1406,7 +1403,7 @@ namespace ts {
14061403 initializeReachabilityStateIfNecessary ( ) ;
14071404
14081405 if ( innerMergedState === Reachability . Unintialized ) {
1409- if ( label && options . noUnusedLabels ) {
1406+ if ( label && ! options . allowUnusedLabels ) {
14101407 file . bindDiagnostics . push ( createDiagnosticForNode ( label , Diagnostics . Unused_label ) ) ;
14111408 }
14121409 currentReachabilityState = outerState ;
@@ -1416,17 +1413,18 @@ namespace ts {
14161413 }
14171414 }
14181415
1419- function jumpToLabel ( label : Identifier , outerState : Reachability ) : void {
1416+ function jumpToLabel ( label : Identifier , outerState : Reachability ) : boolean {
14201417 initializeReachabilityStateIfNecessary ( ) ;
14211418
14221419 const index = label ? labelIndexMap [ label . text ] : lastOrUndefined ( implicitLabels ) ;
14231420 if ( index === undefined ) {
14241421 // reference to unknown label or
14251422 // break/continue used outside of loops
1426- return ;
1423+ return false ;
14271424 }
14281425 const stateAtLabel = labelStack [ index ] ;
14291426 labelStack [ index ] = stateAtLabel === Reachability . Unintialized ? outerState : or ( stateAtLabel , outerState ) ;
1427+ return true ;
14301428 }
14311429
14321430 function checkUnreachable ( node : Node ) : boolean {
@@ -1455,7 +1453,7 @@ namespace ts {
14551453 // Rationale: we don't want to report errors on non-initialized var's since they are hoisted
14561454 // On the other side we do want to report errors on non-initialized 'lets' because of TDZ
14571455 const reportUnreachableCode =
1458- options . noUnreachableCode &&
1456+ ! options . allowUnreachableCode &&
14591457 ! isInAmbientContext ( node ) &&
14601458 (
14611459 node . kind !== SyntaxKind . VariableStatement ||
@@ -1464,7 +1462,7 @@ namespace ts {
14641462 ) ;
14651463
14661464 if ( reportUnreachableCode ) {
1467- file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Unreachable_code_detected ) ) ;
1465+ errorOnFirstToken ( node , Diagnostics . Unreachable_code_detected ) ;
14681466 }
14691467 }
14701468 case Reachability . ReportedUnreachable :
0 commit comments