Permalink
Browse files

Merge pull request #3066 from jugglinmike/asi-dowhile-es6-updated

[[FIX]] Throw W033 instead of E058 when the ; after a do-while stmt is missing (continued)
  • Loading branch information...
2 parents 29c359f + 2b12f69 commit 24b8c971031c19cd367fbafe291bffecdb9ff6ea @rwaldron rwaldron committed on GitHub Apr 25, 2017
Showing with 32 additions and 5 deletions.
  1. +11 −5 src/jshint.js
  2. +21 −0 tests/unit/options.js
View
@@ -1569,7 +1569,13 @@ var JSHINT = (function() {
}
}
- function parseFinalSemicolon() {
+ /**
+ * Consume the semicolon that delimits the statement currently being parsed,
+ * emitting relevant warnings/errors as appropriate.
+ *
+ * @param {token} stmt - token describing the statement under consideration
+ */
+ function parseFinalSemicolon(stmt) {
if (state.tokens.next.id !== ";") {
// don't complain about unclosed templates / strings
if (state.tokens.next.isUnclosed) return advance();
@@ -1578,13 +1584,13 @@ var JSHINT = (function() {
state.tokens.next.id !== "(end)";
var blockEnd = checkPunctuator(state.tokens.next, "}");
- if (sameLine && !blockEnd) {
+ if (sameLine && !blockEnd && !(stmt.id === "do" && state.inES6(true))) {
errorAt("E058", state.tokens.curr.line, state.tokens.curr.character);
} else if (!state.option.asi) {
// If this is the last statement in a block that ends on
// the same line *and* option lastsemic is on, ignore the warning.
// Otherwise, complain about missing semicolon.
- if ((blockEnd && !state.option.lastsemic) || !sameLine) {
+ if (!(blockEnd && sameLine && state.option.lastsemic)) {
warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
}
}
@@ -1669,7 +1675,7 @@ var JSHINT = (function() {
} else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") {
warning("W031", t);
}
- parseFinalSemicolon();
+ parseFinalSemicolon(t);
}
@@ -1725,7 +1731,7 @@ var JSHINT = (function() {
// there's no directive negation, so always set to true
state.directive[directive] = true;
- parseFinalSemicolon();
+ parseFinalSemicolon(current);
}
if (state.isStrict()) {
View
@@ -686,6 +686,27 @@ exports["missing semicolons not influenced by asi"] = function (test) {
TestRun(test).test(code, { expr: true, asi: true });
+ code = "do {} while (false) var a;";
+
+ TestRun(test, "do-while as es5")
+ .addError(1, "Missing semicolon.", { code: "E058" })
+ .test(code);
+
+ TestRun(test, "do-while as es5+moz")
+ .addError(1, "Missing semicolon.", { code: "E058" })
+ .test(code, { moz: true });
+
+ TestRun(test, "do-while as es6")
+ .addError(1, "Missing semicolon.", { code: "W033" })
+ .test(code, { esversion: 6 });
+
+ TestRun(test, "do-while as es6 with asi")
+ .test(code, { esversion: 6, asi: true });
+
+ TestRun(test, "do-while false positive")
+ .addError(1, "Missing semicolon.", { code: "E058" })
+ .test("'do' var x;", { esversion: 6, expr: true });
+
test.done();
};

0 comments on commit 24b8c97

Please sign in to comment.