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 Jun 20, 2020
1 parent 2f227f1 commit cbce34a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/jshint.js
Expand Up @@ -1473,8 +1473,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 @@ -872,19 +872,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(); }
);

value += char;
index += 1;
Expand Down
30 changes: 15 additions & 15 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,43 +54,43 @@ 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 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 cbce34a

Please sign in to comment.