Skip to content

Commit

Permalink
handle switch-with-default in JS impl
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Jan 23, 2021
1 parent 77a09a0 commit c98f28a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ends-in-iteration-or-declaration/impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ foo: {
switch (0) {
case 0:
while (false);
default:
case 2: {
// fall through
}
Expand Down Expand Up @@ -122,6 +123,27 @@ function EndsInIterationOrDeclaration(node, labelSet, isLast) {
}
return false;
}
case 'SwitchStatementWithDefault': {
let newLabelSet;
if (isLast) {
newLabelSet = labelSet.concat([EMPTY]);
} else {
newLabelSet = labelSet.filter(l => l !== EMPTY);
}
let clauses = [...node.preDefaultCases, node.defaultCase, ...node.postDefaultCases];
for (let clause of clauses.reverse()) {
if (!IsEmpty(clause, [])) {
if (EndsInIterationOrDeclaration(clause, newLabelSet, isLast)) {
return true;
}
if (IsBreak(clause, newLabelSet)) {
isLast = true;
} else {
isLast = false;
}
}
}
}
case 'SwitchCase':
case 'SwitchDefault': {
if (node.consequent.length === 0) {
Expand Down

0 comments on commit c98f28a

Please sign in to comment.