Skip to content

Commit

Permalink
[[FIX]] Recognize ES2020 globals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jugglinmike authored and rwaldron committed Jan 4, 2022
1 parent be94b1d commit b1426f1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/jshint.js
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/options.js
Expand Up @@ -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
};
Expand Down
3 changes: 2 additions & 1 deletion src/vars.js
Expand Up @@ -68,7 +68,8 @@ exports.ecmaIdentifiers = {
SharedArrayBuffer : false
},
11: {
BigInt : false
BigInt : false,
globalThis : false
}
};

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/core.js
Expand Up @@ -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();
};

0 comments on commit b1426f1

Please sign in to comment.