diff --git a/src/lex.js b/src/lex.js index 87568c4af1..98fa1c0fae 100644 --- a/src/lex.js +++ b/src/lex.js @@ -1352,17 +1352,11 @@ Lexer.prototype = { sequence = char; next = this.peek(index + 1); while (reg.nonzeroDigit.test(next) || next === "0") { - /* istanbul ignore next */ index += 1; - /* istanbul ignore next */ char = next; - /* istanbul ignore next */ sequence += char; - /* istanbul ignore next */ body += char; - /* istanbul ignore next */ value += char; - /* istanbul ignore next */ next = this.peek(index + 1); } groupReferences.push(Number(sequence)); @@ -1471,7 +1465,6 @@ Lexer.prototype = { } if (next === "}") { - /* istanbul ignore next */ return true; } diff --git a/tests/unit/parser.js b/tests/unit/parser.js index 603aea7523..b3fd37b479 100644 --- a/tests/unit/parser.js +++ b/tests/unit/parser.js @@ -756,6 +756,16 @@ exports.regexp.uFlag = function (test) { .addError(1, 6, "Invalid regular expression.") .test("void /.{}/u;", { esversion: 6 }); + TestRun(test) + .test([ + "void /.{0}/;", + "void /.{0}/u;", + "void /.{9}/;", + "void /.{9}/u;", + "void /.{23}/;", + "void /.{23}/u;" + ], { esversion: 6 }); + TestRun(test) .addError(1, 6, "Invalid regular expression.") .test("void /.{,2}/u;", { esversion: 6 }); @@ -768,6 +778,25 @@ exports.regexp.uFlag = function (test) { .addError(1, 6, "Invalid regular expression.") .test("void /(.)(.)\\3/u;", { esversion: 6 }); + TestRun(test, "Valid group reference - multiple digits") + .test([ + "void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\10/u;", + "void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\10a/u;", + "void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\11/u;", + "void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\11a/u;" + ], { esversion: 6 }); + + // A negative syntax test is the only way to verify JSHint is interpeting the + // adjacent digits as one reference as opposed to a reference followed by a + // literal digit. + TestRun(test, "Invalid group reference - two digits") + .addError(1, 6, "Invalid regular expression.") + .test("void /(.)\\10/u;", { esversion: 6 }); + + TestRun(test, "Invalid group reference - three digits") + .addError(1, 6, "Invalid regular expression.") + .test("void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\100/u;", { esversion: 6 }); + TestRun(test, "Invalid group reference (permitted without flag)") .test("void /(.)(.)\\3/;", { esversion: 6 });