Repository: jshint/jshint
Pull request #3597 (2022-01-04 19:53:10)

[[FIX]] Recognize ES2020 globals
Include `globalThis` in the set of global bindings available in
ES2020-compliant runtimes. Add the instructions necessary to apply this
set. Extend the document of the `esversion` option to mention these
features.


Patch:
diff --git a/README.md b/README.md
index ba673acb..d0674228 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,6 @@
 [![NPM version](https://img.shields.io/npm/v/jshint.svg?style=flat)](https://www.npmjs.com/package/jshint)
 [![Linux Build Status](https://img.shields.io/travis/jshint/jshint/master.svg?style=flat&label=Linux%20build)](https://travis-ci.org/jshint/jshint)
 [![Windows Build status](https://img.shields.io/appveyor/ci/jshint/jshint/master.svg?style=flat&label=Windows%20build)](https://ci.appveyor.com/project/jshint/jshint/branch/master)
-[![Dependency Status](https://img.shields.io/david/jshint/jshint.svg?style=flat)](https://david-dm.org/jshint/jshint)
-[![devDependency Status](https://img.shields.io/david/dev/jshint/jshint.svg?style=flat)](https://david-dm.org/jshint/jshint#info=devDependencies)
 [![Coverage Status](https://img.shields.io/coveralls/jshint/jshint.svg?style=flat)](https://coveralls.io/r/jshint/jshint?branch=master)
 
 JSHint is a community-driven tool that detects errors and potential problems in
diff --git a/src/jshint.js b/src/jshint.js
index cdc2fa93..4d599b0b 100644
--- a/src/jshint.js
+++ b/src/jshint.js
@@ -242,6 +242,10 @@ var JSHINT = (function() {
       combine(predefined, vars.ecmaIdentifiers[8]);
     }
 
+    if (state.inES11()) {
+      combine(predefined, vars.ecmaIdentifiers[11]);
+    }
+
     /**
      * Use `in` to check for the presence of any explicitly-specified value for
      * `globalstrict` because both `true` and `false` should trigger an error.
diff --git a/src/options.js b/src/options.js
index 8e622296..53e70669 100644
--- a/src/options.js
+++ b/src/options.js
@@ -1053,7 +1053,8 @@ exports.val = {
    *    Notable additions: optional catch bindings.
    *  - `11` - To enable language features introduced by ECMAScript 11. Notable
    *    additions: "export * as ns from 'module'", `import.meta`, the nullish
-   *    coalescing operator, and optional chaining, and dynamic import.
+   *    coalescing operator, the BigInt type, the `globalThis` binding,
+   *    optional chaining, and dynamic import.
    */
   esversion: 5
 };
diff --git a/src/vars.js b/src/vars.js
index 783034b6..1d139ed4 100644
--- a/src/vars.js
+++ b/src/vars.js
@@ -68,7 +68,8 @@ exports.ecmaIdentifiers = {
     SharedArrayBuffer  : false
   },
   11: {
-    BigInt             : false
+    BigInt             : false,
+    globalThis         : false
   }
 };
 


Test patch:
diff --git a/tests/unit/core.js b/tests/unit/core.js
index 80ae889b..139eeb01 100644
--- a/tests/unit/core.js
+++ b/tests/unit/core.js
@@ -2582,3 +2582,26 @@ exports.constWithoutInit = function(test) {
 
   test.done();
 };
+
+// regression test for gh-3595
+exports.bigIntCtor = function(test) {
+  var code = [
+    "void BigInt;",
+    "void globalThis;"
+  ];
+
+  TestRun(test)
+    .addError(1, 6, "'BigInt' is not defined.")
+    .addError(2, 6, "'globalThis' is not defined.")
+    .test(code, { undef: true });
+
+  TestRun(test)
+    .addError(1, 6, "'BigInt' is not defined.")
+    .addError(2, 6, "'globalThis' is not defined.")
+    .test(code, { undef: true, esversion: 10 });
+
+  TestRun(test)
+    .test(code, { undef: true, esversion: 11 });
+
+  test.done();
+};