Skip to content

Commit

Permalink
[[CHORE]] Optimize case clause tracking
Browse files Browse the repository at this point in the history
Analyzing a `switch` statement involves tracking the first occurance of
a `case` clause. Only noting its presence is necessary, and it is only
necessary in the context of the token's processing logic.

Replace the Array instance with a boolenan flag scoped to the token's
function.
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 20, 2019
1 parent 9cb3b20 commit 5a337a8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/jshint.js
Expand Up @@ -4833,6 +4833,7 @@ var JSHINT = (function() {
var t = state.tokens.next;
var g = false;
var noindent = false;
var seenCase = false;

state.funct["(breakage)"] += 1;
advance("(");
Expand All @@ -4848,8 +4849,6 @@ var JSHINT = (function() {
if (!noindent)
indent += state.option.indent;

this.cases = [];

for (;;) {
switch (state.tokens.next.id) {
case "case":
Expand Down Expand Up @@ -4878,7 +4877,8 @@ var JSHINT = (function() {
}

advance("case");
this.cases.push(expression(context, 0));
expression(context, 0);
seenCase = true;
increaseComplexityCount();
g = true;
advance(":");
Expand All @@ -4901,10 +4901,8 @@ var JSHINT = (function() {
default:
// Do not display a warning if 'default' is the first statement or if
// there is a special /* falls through */ comment.
if (this.cases.length) {
if (!state.tokens.curr.caseFallsThrough) {
warning("W086", state.tokens.curr, "default");
}
if (seenCase && !state.tokens.curr.caseFallsThrough) {
warning("W086", state.tokens.curr, "default");
}
}

Expand Down

0 comments on commit 5a337a8

Please sign in to comment.