Skip to content

Commit 7c890aa

Browse files
jugglinmikerwaldron
authored andcommitted
[[FIX]] Tolerate dangling NewExpression
1 parent 71ec395 commit 7c890aa

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/jshint.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,11 +2717,16 @@ var JSHINT = (function() {
27172717

27182718
var opening = state.tokens.next;
27192719
var c = expression(context, 155), i;
2720+
2721+
if (!c) {
2722+
return this;
2723+
}
2724+
27202725
if (!c.paren && c.rbp > 160) {
27212726
error("E024", opening, opening.value);
27222727
}
27232728

2724-
if (c && c.id !== "function") {
2729+
if (c.id !== "function") {
27252730
if (c.identifier) {
27262731
switch (c.value) {
27272732
case "Number":

tests/unit/parser.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10598,3 +10598,26 @@ exports.optionalChaining = function (test) {
1059810598

1059910599
test.done();
1060010600
};
10601+
10602+
// gh-3556: "Crash parsing: throw new"
10603+
exports.loneNew = function (test) {
10604+
TestRun(test, "as reported")
10605+
.addError(4, 3, "Expected an identifier and instead saw '}'.")
10606+
.addError(4, 4, "Missing semicolon.")
10607+
.addError(1, 21, "Unmatched '{'.")
10608+
.addError(5, 1, "Unrecoverable syntax error. (100% scanned).")
10609+
.test([
10610+
"function code(data) {",
10611+
" if (data.request === 'foo') {",
10612+
" throw new ",
10613+
" }",
10614+
"}"
10615+
]);
10616+
10617+
TestRun(test, "simplified")
10618+
.addError(1, 4, "Expected an identifier and instead saw ';'.")
10619+
.addError(1, 5, "Missing semicolon.")
10620+
.test("new;");
10621+
10622+
test.done();
10623+
};

0 commit comments

Comments
 (0)