Skip to content

Commit

Permalink
[[FIX]] Tolerate unterminated nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Sep 23, 2021
1 parent ca06e6a commit ecae54a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jshint.js
Expand Up @@ -2451,7 +2451,9 @@ var JSHINT = (function() {
that.left = left;
var right = that.right = expression(context, 39);

if (!right.paren && (right.id === "||" || right.id === "&&")) {
if (!right) {
error("E024", state.tokens.next, state.tokens.next.id);
} else if (!right.paren && (right.id === "||" || right.id === "&&")) {
error("E024", that.right, that.right.id);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -10624,3 +10624,26 @@ exports.loneNew = function (test) {

test.done();
};

// gh-3560: "Logical nullish assignment (??=) throwing error"
exports.loneNullishCoalescing = function (test) {
TestRun(test, "as reported")
.addError(2, 8, "Expected an identifier and instead saw '='.")
.addError(2, 10, "Unexpected '(number)'.")
.addError(2, 8, "Expected an assignment or function call and instead saw an expression.")
.addError(2, 9, "Missing semicolon.")
.addError(2, 10, "Expected an assignment or function call and instead saw an expression.")
.test([
"let a = [1,2];",
"a[0] ??= 0;"
], {esversion: 11});

TestRun(test, "simplified")
.addError(1, 4, "Expected an identifier and instead saw ';'.")
.addError(1, 4, "Unexpected '(end)'.")
.addError(1, 4, "Expected an assignment or function call and instead saw an expression.")
.addError(1, 5, "Missing semicolon.")
.test("0??;", {esversion: 11});

test.done();
};

0 comments on commit ecae54a

Please sign in to comment.