Skip to content

Commit

Permalink
[[FIX]] Tolerate dangling NewExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 6, 2021
1 parent 71ec395 commit 7c890aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2717,11 +2717,16 @@ var JSHINT = (function() {

var opening = state.tokens.next;
var c = expression(context, 155), i;

if (!c) {
return this;
}

if (!c.paren && c.rbp > 160) {
error("E024", opening, opening.value);
}

if (c && c.id !== "function") {
if (c.id !== "function") {
if (c.identifier) {
switch (c.value) {
case "Number":
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10598,3 +10598,26 @@ exports.optionalChaining = function (test) {

test.done();
};

// gh-3556: "Crash parsing: throw new"
exports.loneNew = function (test) {
TestRun(test, "as reported")
.addError(4, 3, "Expected an identifier and instead saw '}'.")
.addError(4, 4, "Missing semicolon.")
.addError(1, 21, "Unmatched '{'.")
.addError(5, 1, "Unrecoverable syntax error. (100% scanned).")
.test([
"function code(data) {",
" if (data.request === 'foo') {",
" throw new ",
" }",
"}"
]);

TestRun(test, "simplified")
.addError(1, 4, "Expected an identifier and instead saw ';'.")
.addError(1, 5, "Missing semicolon.")
.test("new;");

test.done();
};

0 comments on commit 7c890aa

Please sign in to comment.