Skip to content

Commit

Permalink
[[CHORE]] Recognize 'esversion: 11'
Browse files Browse the repository at this point in the history
This commit extends the options parsing system to tolerate the values
"11" and "2020" for the `esversion` linting option. It does not
introduce support for any features introduced by the new edition of the
language.
  • Loading branch information
jugglinmike committed Jun 20, 2020
1 parent 1013d51 commit 2f227f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/jshint.js
Expand Up @@ -710,6 +710,7 @@ var JSHINT = (function() {
case "8":
case "9":
case "10":
case "11":
state.option.moz = false;
state.option.esversion = +val;
break;
Expand All @@ -718,6 +719,7 @@ var JSHINT = (function() {
case "2017":
case "2018":
case "2019":
case "2020":
state.option.moz = false;
// Translate specification publication year to version number.
state.option.esversion = +val - 2009;
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Expand Up @@ -1051,6 +1051,7 @@ exports.val = {
* - `10` - To enable language features introduced by ECMAScript
* 10](https://www.ecma-international.org/ecma-262/10.0/index.html).
* Notable additions: optional catch bindings.
* - `11` - To enable language features introduced by ECMAScript 11.
*/
esversion: 5
};
Expand Down
9 changes: 9 additions & 0 deletions src/state.js
Expand Up @@ -65,6 +65,15 @@ var state = {
return this.option.moz;
},

/**
* Determine if constructs introduced in ECMAScript 11 should be accepted.
*
* @returns {boolean}
*/
inES11: function() {
return this.esVersion >= 11;
},

/**
* Determine if constructs introduced in ECMAScript 10 should be accepted.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/test262/test.js
Expand Up @@ -51,7 +51,7 @@ module.exports = function(test) {

try {
JSHint(test.contents, {
esversion: 10,
esversion: 11,
maxerr: Infinity,
module: isModule,
unstable: {
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/options.js
Expand Up @@ -4238,13 +4238,15 @@ exports.esversion = function(test) {
"// jshint esversion: 10",
"// jshint esversion: 2019",
"// jshint esversion: 11",
"// jshint esversion: 2020"
"// jshint esversion: 2020",
"// jshint esversion: 12",
"// jshint esversion: 2021"
];

TestRun(test, "Value")
.addError(2, 1, "Bad option value.")
.addError(14, 1, "Bad option value.")
.addError(15, 1, "Bad option value.")
.addError(16, 1, "Bad option value.")
.addError(17, 1, "Bad option value.")
.test(code);

var es5code = [
Expand Down

0 comments on commit 2f227f1

Please sign in to comment.