in web/jslint/src/main/resources/data/jslint-2020-03-28.js [3365:3465]
stmt("switch", function () {
var dups = [];
var last;
var stmts;
var the_cases = [];
var the_disrupt = true;
var the_switch = token;
not_top_level(the_switch);
if (functionage.finally > 0) {
warn("unexpected_a", the_switch);
}
functionage.switch += 1;
advance("(");
token.free = true;
the_switch.expression = expression(0);
the_switch.block = the_cases;
advance(")");
advance("{");
(function major() {
var the_case = next_token;
the_case.arity = "statement";
the_case.expression = [];
(function minor() {
advance("case");
token.switch = true;
var exp = expression(0);
if (dups.some(function (thing) {
return are_similar(thing, exp);
})) {
warn("unexpected_a", exp);
}
dups.push(exp);
the_case.expression.push(exp);
advance(":");
if (next_token.id === "case") {
return minor();
}
})();
stmts = statements();
if (stmts.length < 1) {
warn("expected_statements_a");
return;
}
the_case.block = stmts;
the_cases.push(the_case);
last = stmts[stmts.length - 1];
if (last.disrupt) {
if (last.id === "break" && last.label === undefined) {
the_disrupt = false;
}
} else {
warn("expected_a_before_b", next_token, "break;", artifact(next_token));
}
if (next_token.id === "case") {
return major();
}
})();
dups = undefined;
if (next_token.id === "default") {
var the_default = next_token;
advance("default");
token.switch = true;
advance(":");
the_switch.else = statements();
if (the_switch.else.length < 1) {
warn("unexpected_a", the_default);
the_disrupt = false;
} else {
var the_last = the_switch.else[the_switch.else.length - 1];
if (the_last.id === "break" && the_last.label === undefined) {
warn("unexpected_a", the_last);
the_last.disrupt = false;
}
the_disrupt = the_disrupt && the_last.disrupt;
}
} else {
the_disrupt = false;
}
advance("}", the_switch);
functionage.switch -= 1;
the_switch.disrupt = the_disrupt;
return the_switch;
});