@@ -570,14 +570,10 @@ class ThrowStmt extends Stmt, @throwstmt {
570570 override string getAPrimaryQlClass ( ) { result = "ThrowStmt" }
571571}
572572
573- /** A `break`, `yield` or `continue` statement. */
574- class JumpStmt extends Stmt {
575- JumpStmt ( ) {
576- this instanceof BreakStmt or
577- this instanceof YieldStmt or
578- this instanceof ContinueStmt
579- }
573+ private class JumpStmt_ = @breakstmt or @yieldstmt or @continuestmt;
580574
575+ /** A `break`, `yield` or `continue` statement. */
576+ class JumpStmt extends Stmt , JumpStmt_ {
581577 /**
582578 * Gets the labeled statement that this `break` or
583579 * `continue` statement refers to, if any.
@@ -598,12 +594,7 @@ class JumpStmt extends Stmt {
598594 )
599595 }
600596
601- private SwitchExpr getSwitchExprTarget ( ) { result = this .( YieldStmt ) .getParent + ( ) }
602-
603597 private StmtParent getEnclosingTarget ( ) {
604- result = this .getSwitchExprTarget ( )
605- or
606- not exists ( this .getSwitchExprTarget ( ) ) and
607598 result = this .getAPotentialTarget ( ) and
608599 not exists ( Stmt other | other = this .getAPotentialTarget ( ) | other .getEnclosingStmt + ( ) = result )
609600 }
@@ -612,14 +603,15 @@ class JumpStmt extends Stmt {
612603 * Gets the statement or `switch` expression that this `break`, `yield` or `continue` jumps to.
613604 */
614605 StmtParent getTarget ( ) {
606+ // Note: This implementation only considers `break` and `continue`; YieldStmt overrides this predicate
615607 result = this .getLabelTarget ( )
616608 or
617609 not exists ( this .getLabelTarget ( ) ) and result = this .getEnclosingTarget ( )
618610 }
619611}
620612
621613/** A `break` statement. */
622- class BreakStmt extends Stmt , @breakstmt {
614+ class BreakStmt extends JumpStmt , @breakstmt {
623615 /** Gets the label targeted by this `break` statement, if any. */
624616 string getLabel ( ) { namestrings ( result , _, this ) }
625617
@@ -640,12 +632,21 @@ class BreakStmt extends Stmt, @breakstmt {
640632/**
641633 * A `yield` statement.
642634 */
643- class YieldStmt extends Stmt , @yieldstmt {
635+ class YieldStmt extends JumpStmt , @yieldstmt {
644636 /**
645637 * Gets the value of this `yield` statement.
646638 */
647639 Expr getValue ( ) { result .getParent ( ) = this }
648640
641+ /**
642+ * Gets the `switch` expression target of this `yield` statement.
643+ */
644+ override SwitchExpr getTarget ( ) {
645+ // Get the innermost enclosing SwitchExpr; this works because getParent() is defined for Stmt and
646+ // therefore won't proceed after the innermost SwitchExpr (due to it being an Expr)
647+ result = this .getParent + ( )
648+ }
649+
649650 override string pp ( ) { result = "yield ..." }
650651
651652 override string toString ( ) { result = "yield ..." }
@@ -656,7 +657,7 @@ class YieldStmt extends Stmt, @yieldstmt {
656657}
657658
658659/** A `continue` statement. */
659- class ContinueStmt extends Stmt , @continuestmt {
660+ class ContinueStmt extends JumpStmt , @continuestmt {
660661 /** Gets the label targeted by this `continue` statement, if any. */
661662 string getLabel ( ) { namestrings ( result , _, this ) }
662663
0 commit comments