Skip to content

Commit a8b9f96

Browse files
committed
Use control flow analyzer for switch case fallthrough checks
1 parent 35a6426 commit a8b9f96

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ namespace ts {
13411341
bind(clause);
13421342
fallthroughFlow = currentFlow;
13431343
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
1344-
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
1344+
clause.fallthroughFlowNode = currentFlow;
13451345
}
13461346
}
13471347
clauses.transformFlags = subtreeTransformFlags | TransformFlags.HasComputedFlags;

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31079,6 +31079,9 @@ namespace ts {
3107931079
}
3108031080
}
3108131081
forEach(clause.statements, checkSourceElement);
31082+
if (compilerOptions.noFallthroughCasesInSwitch && clause.fallthroughFlowNode && isReachableFlowNode(clause.fallthroughFlowNode)) {
31083+
grammarErrorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
31084+
}
3108231085
});
3108331086
if (node.caseBlock.locals) {
3108431087
registerForUnusedIdentifiersCheck(node.caseBlock);

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,12 +2250,14 @@ namespace ts {
22502250
parent: CaseBlock;
22512251
expression: Expression;
22522252
statements: NodeArray<Statement>;
2253+
/* @internal */ fallthroughFlowNode?: FlowNode;
22532254
}
22542255

22552256
export interface DefaultClause extends Node {
22562257
kind: SyntaxKind.DefaultClause;
22572258
parent: CaseBlock;
22582259
statements: NodeArray<Statement>;
2260+
/* @internal */ fallthroughFlowNode?: FlowNode;
22592261
}
22602262

22612263
export type CaseOrDefaultClause = CaseClause | DefaultClause;

0 commit comments

Comments
 (0)