Skip to content

Commit

Permalink
[[FIX]] Graduate BigInt support to esversion: 11
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed Sep 19, 2020
1 parent 0d9f6fd commit dc00db3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 52 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"browser-test-server": "node tests/helpers/browser/server",
"build": "node bin/build",
"coverage": "istanbul -- cover ./node_modules/nodeunit/bin/nodeunit tests/unit tests/unit/unstable",
"coverage": "istanbul -- cover ./node_modules/nodeunit/bin/nodeunit tests/unit",
"coverage-report": "npm run coverage && istanbul report html",
"data": "node scripts/generate-identifier-data",
"fetch-test262": "git submodule init && git submodule update",
Expand All @@ -34,7 +34,7 @@
"test-cli": "nodeunit tests/cli.js",
"test-node": "npm run test-unit && npm run test-cli && npm run test-regression",
"test-regression": "nodeunit tests/regression",
"test-unit": "nodeunit tests/unit tests/unit/unstable",
"test-unit": "nodeunit tests/unit",
"test-website": "node tests/website.js",
"test": "npm run test-node && npm run test-browser"
},
Expand Down
4 changes: 2 additions & 2 deletions src/jshint.js
Expand Up @@ -1472,8 +1472,8 @@ var JSHINT = (function() {

if (right.type === "(identifier)" && right.value === "typeof" && left.type === "(string)") {
if (left.value === "bigint") {
if (!state.option.unstable.bigint) {
warning("W144", left, "BigInt", "bigint");
if (!state.inES11()) {
warning("W119", left, "BigInt", "11");
}

return false;
Expand Down
24 changes: 11 additions & 13 deletions src/lex.js
Expand Up @@ -874,19 +874,17 @@ Lexer.prototype = {

if (isAllowedDigit !== isDecimalDigit || isBigInt) {
if (isBigInt) {
if (!state.option.unstable.bigint) {
this.triggerAsync(
"warning",
{
code: "W144",
line: this.line,
character: this.char,
data: [ "BigInt", "bigint" ]
},
checks,
function() { return true; }
);
}
this.triggerAsync(
"warning",
{
code: "W119",
line: this.line,
character: this.char,
data: [ "BigInt", "11" ]
},
checks,
function() { return !state.inES11(); }
);

if (isLegacy || isNonOctal) {
this.triggerAsync(
Expand Down
11 changes: 0 additions & 11 deletions src/options.js
Expand Up @@ -1063,17 +1063,6 @@ exports.val = {
* right to remove or modify them between major version releases.
*/
exports.unstable = {
/**
* [The BigInt proposal](https://github.com/tc39/proposal-bigint) extends the
* language's grammer for numeric literals to support integer values of
* arbitrary precision. It also introduces a new value of the `typeof`
* operator, "bigint".
*
* Mathematical operations which use both BigInt and traditional ECMAScript
* Number values may not have the intended effect. Due to the weakly-typed
* nature of the language, JSHint is unable to identify such cases.
*/
bigint: true
};

// These are JSHint boolean options which are shared with JSLint
Expand Down
5 changes: 1 addition & 4 deletions tests/test262/test.js
Expand Up @@ -53,10 +53,7 @@ module.exports = function(test) {
JSHint(test.contents, {
esversion: 11,
maxerr: Infinity,
module: isModule,
unstable: {
bigint: true
}
module: isModule
});
} catch (e) {
return false;
Expand Down
34 changes: 17 additions & 17 deletions tests/unit/unstable/bigint.js → tests/unit/bigint.js
@@ -1,22 +1,22 @@
"use strict";

var TestRun = require("../../helpers/testhelper").setup.testRun;
var TestRun = require("../helpers/testhelper").setup.testRun;

exports.enabling = function (test) {
TestRun(test, "Not enabled")
.addError(1, 6, "'BigInt' is a non-standard language feature. Enable it using the 'bigint' unstable option.")
.test("void 1n;", {esversion: 9});
.addError(1, 6, "'BigInt' is only available in ES11 (use 'esversion: 11').")
.test("void 1n;", {esversion: 10});

TestRun(test, "Enabled via inline directive")
.test([
"// jshint.unstable bigint: true",
"// jshint esversion: 11",
"void 1n;"
], {esversion: 9});
], {esversion: 10});

TestRun(test, "Enabled via configuration object")
.test([
"void 1n;"
], {esversion: 9, unstable: {bigint: true}});
], {esversion: 11});

test.done();
};
Expand All @@ -34,7 +34,7 @@ exports.validUsage = function(test) {
"void 0b1n;",
"void 0b01n;",
"void 0b10n;",
], {esversion: 6, unstable: {bigint: true}});
], {esversion: 11});

TestRun(test, 'No warnings for values that would otherwise coerce to Infinity')
.test([
Expand All @@ -44,7 +44,7 @@ exports.validUsage = function(test) {
"0000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000n;"
], {esversion: 9, unstable: {bigint: true}});
], {esversion: 11});

test.done();
};
Expand All @@ -54,51 +54,51 @@ exports.invalid = function (test) {
.addError(1, 10, "A leading decimal point can be confused with a dot: '.1'.")
.addError(1, 8, "Missing semicolon.")
.addError(1, 8, "Expected an assignment or function call and instead saw an expression.")
.test("void 1n.1;", {esversion: 6, unstable: {bigint: true}});
.test("void 1n.1;", {esversion: 11});

TestRun(test, "following decimal point")
.addError(1, 6, "Unexpected '1'.")
.addError(1, 1, "Unexpected early end of program.")
.addError(1, 6, "Unrecoverable syntax error. (100% scanned).")
.test("void 1.1n;", {esversion: 6, unstable: {bigint: true}});
.test("void 1.1n;", {esversion: 11});

TestRun(test, "preceding exponent")
.addError(1, 6, "Unexpected '1'.")
.addError(1, 1, "Unexpected early end of program.")
.addError(1, 6, "Unrecoverable syntax error. (100% scanned).")
.test("void 1ne3;", {esversion: 6, unstable: {bigint: true}});
.test("void 1ne3;", {esversion: 11});

TestRun(test, "following exponent")
.addError(1, 6, "Unexpected '1'.")
.addError(1, 1, "Unexpected early end of program.")
.addError(1, 6, "Unrecoverable syntax error. (100% scanned).")
.test("void 1e3n;", {esversion: 6, unstable: {bigint: true}});
.test("void 1e3n;", {esversion: 11});

TestRun(test, "invalid legacy octal")
.addError(1, 6, "Malformed numeric literal: '01n'.")
.test("void 01n;", {esversion: 6, unstable: {bigint: true}});
.test("void 01n;", {esversion: 11});

TestRun(test, "invalid leading 0")
.addError(1, 6, "Malformed numeric literal: '08n'.")
.test("void 08n;", {esversion: 6, unstable: {bigint: true}});
.test("void 08n;", {esversion: 11});

TestRun(test, "invalid hex digit")
.addError(1, 8, "Malformed numeric literal: '0x'.")
.addError(1, 8, "Missing semicolon.")
.addError(1, 8, "Expected an assignment or function call and instead saw an expression.")
.test("void 0xgn;", {esversion: 6, unstable: {bigint: true}});
.test("void 0xgn;", {esversion: 11});

TestRun(test, "invalid binary digit")
.addError(1, 8, "Malformed numeric literal: '0b'.")
.addError(1, 8, "Missing semicolon.")
.addError(1, 8, "Expected an assignment or function call and instead saw an expression.")
.test("void 0b2n;", {esversion: 6, unstable: {bigint: true}});
.test("void 0b2n;", {esversion: 11});

TestRun(test, "invalid octal digit")
.addError(1, 8, "Malformed numeric literal: '0o'.")
.addError(1, 8, "Missing semicolon.")
.addError(1, 8, "Expected an assignment or function call and instead saw an expression.")
.test("void 0o8n;", {esversion: 6, unstable: {bigint: true}});
.test("void 0o8n;", {esversion: 11});

test.done();
};
6 changes: 3 additions & 3 deletions tests/unit/options.js
Expand Up @@ -311,23 +311,23 @@ exports.notypeof = function (test) {
.addError(3, 17, "Invalid typeof value 'bool'")
.addError(4, 11, "Invalid typeof value 'obj'")
.addError(13, 17, "Invalid typeof value 'symbol'")
.addError(14, 21, "'BigInt' is a non-standard language feature. Enable it using the 'bigint' unstable option.")
.addError(14, 21, "'BigInt' is only available in ES11 (use 'esversion: 11').")
.test(src);

TestRun(test)
.addError(1, 17, "Invalid typeof value 'funtion'")
.addError(2, 14, "Invalid typeof value 'double'")
.addError(3, 17, "Invalid typeof value 'bool'")
.addError(4, 11, "Invalid typeof value 'obj'")
.addError(14, 21, "'BigInt' is a non-standard language feature. Enable it using the 'bigint' unstable option.")
.addError(14, 21, "'BigInt' is only available in ES11 (use 'esversion: 11').")
.test(src, { esnext: true });

TestRun(test)
.addError(1, 17, "Invalid typeof value 'funtion'")
.addError(2, 14, "Invalid typeof value 'double'")
.addError(3, 17, "Invalid typeof value 'bool'")
.addError(4, 11, "Invalid typeof value 'obj'")
.test(src, { esnext: true, unstable: { bigint: true } });
.test(src, { esversion: 11 });

TestRun(test)
.test(src, { notypeof: true });
Expand Down

0 comments on commit dc00db3

Please sign in to comment.