Permalink
Browse files

[[FIX]] Parse semicolons in class bodies

Although the semicolon token may appear in class bodies in valid ES6
code, it serves no purpose. Extend the parser to accept this token, but
emit the same warning used for unnecessary semicolons appearing
elsewhere. This warning may be disabled by the end user if desired.
  • Loading branch information...
jugglinmike committed Apr 29, 2015
1 parent dd768c2 commit 58c8e64c86259790254037faa8879ed210c7d429
Showing with 34 additions and 0 deletions.
  1. +10 −0 src/jshint.js
  2. +24 −0 tests/unit/parser.js
@@ -3711,6 +3711,16 @@ var JSHINT = (function() {
isStatic = false;
isGenerator = false;
getset = null;

// The ES6 grammar for ClassElement includes the `;` token, but it is
// defined only as a placeholder to facilitate future language
// extensions. In ES6 code, it serves no purpose.
if (name.id === ";") {
warning("W032");
advance(";");
continue;
}

if (name.id === "*") {
isGenerator = true;
advance("*");
@@ -4670,6 +4670,30 @@ exports.classExpressionThis = function (test) {
test.done();
};

exports.classElementEmpty = function (test) {
var code = [
"class A {",
" ;",
" method() {}",
" ;",
" *methodB() { yield; }",
" ;;",
" methodC() {}",
" ;",
"}",
];

TestRun(test)
.addError(2, "Unnecessary semicolon.")
.addError(4, "Unnecessary semicolon.")
.addError(6, "Unnecessary semicolon.")
.addError(6, "Unnecessary semicolon.")
.addError(8, "Unnecessary semicolon.")
.test(code, { esnext: true });

test.done();
};

exports["test for GH-1018"] = function (test) {
var code = [
"if (a = 42) {}",

0 comments on commit 58c8e64

Please sign in to comment.