Skip to content

Commit

Permalink
feat(typescript-estree): disallow switch statements with multiple def…
Browse files Browse the repository at this point in the history
…ault cases (#8411)
  • Loading branch information
DMartens committed Mar 16, 2024
1 parent 093225c commit 994812b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
@@ -0,0 +1,3 @@
switch (true) {
default: default:
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -839,6 +839,17 @@ export class Converter {
});

case SyntaxKind.SwitchStatement:
if (
node.caseBlock.clauses.filter(
switchCase => switchCase.kind === SyntaxKind.DefaultClause,
).length > 1
) {
this.#throwError(
node,
"A 'default' clause cannot appear more than once in a 'switch' statement.",
);
}

return this.createNode<TSESTree.SwitchStatement>(node, {
type: AST_NODE_TYPES.SwitchStatement,
discriminant: this.convertChild(node.expression),
Expand Down

0 comments on commit 994812b

Please sign in to comment.