Skip to content

Commit

Permalink
[[FIX]] Parse semicolons in class bodies
Browse files Browse the repository at this point in the history
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 58c8e64
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("*");
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}",
Expand Down

0 comments on commit 58c8e64

Please sign in to comment.