Skip to content

Commit

Permalink
[[FIX]] Tolerate static as class method name
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 20, 2019
1 parent b14acca commit 9cb3b20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jshint.js
Expand Up @@ -2829,7 +2829,8 @@ var JSHINT = (function() {
inGenerator = false;
context &= ~prodParams.preAsync;

if (state.tokens.next.value === "static") {
if (state.tokens.next.value === "static" &&
!checkPunctuator(peek(), "(")) {
isStatic = true;
advance();
}
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -6844,6 +6844,28 @@ exports["class and method naming"] = function (test) {
"};"
], {esversion: 6});

TestRun(test, "valid uses of name `static`")
.test([
"void class {",
" static() {}",
" static static() {}",
" static ['static']() {}",
"};",
"void class {",
" * static() { yield; }",
" static * static() { yield; }",
" static * ['static']() { yield; }",
"};",
"void class {",
" get static() {}",
" set static(x) {}",
" static get static() {}",
" static set static(x) {}",
" static get ['static']() {}",
" static set ['static'](x) {}",
"};"
], {esversion: 6});

TestRun(test, "invalid use of name `prototype`: static method")
.addError(2, 10, "A static class method cannot be named 'prototype'.")
.test([
Expand Down

0 comments on commit 9cb3b20

Please sign in to comment.