Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[[FIX]] Tolerate unterminated nullish coalescing #3563

Merged
merged 2 commits into from Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/jshint.js
Expand Up @@ -2450,7 +2450,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 @@ -10617,3 +10617,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();
};