Skip to content

Commit

Permalink
[[FIX]] Do not crash on invalid program code
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 20, 2019
1 parent 2366c92 commit b14acca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/jshint.js
Expand Up @@ -4372,11 +4372,13 @@ var JSHINT = (function() {
}
var id = state.tokens.prev;
value = expression(context, 10);
if (value && value.identifier && value.value === "undefined") {
warning("W080", id, id.value);
}
if (!lone) {
destructuringPatternMatch(names, value);
if (value) {
if (value.identifier && value.value === "undefined") {
warning("W080", id, id.value);
}
if (!lone) {
destructuringPatternMatch(names, value);
}
}
}

Expand Down Expand Up @@ -4558,12 +4560,14 @@ var JSHINT = (function() {
}
id = state.tokens.prev;
value = expression(context, 10);
if (value && !state.funct["(loopage)"] && value.identifier &&
value.value === "undefined") {
warning("W080", id, id.value);
}
if (!lone) {
destructuringPatternMatch(names, value);
if (value) {
if (!state.funct["(loopage)"] && value.identifier &&
value.value === "undefined") {
warning("W080", id, id.value);
}
if (!lone) {
destructuringPatternMatch(names, value);
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -2493,6 +2493,25 @@ exports["destructuring assignment of valid simple assignment targets"] = functio
test.done();
};

exports["regression test for GH-3408"] = function (test) {
TestRun(test, "var statement")
.addError(1, 9, "Expected an identifier and instead saw ';'.")
.addError(1, 10, "Missing semicolon.")
.test("var [x]=;", { esversion: 6 });

TestRun(test, "let statement")
.addError(1, 9, "Expected an identifier and instead saw ';'.")
.addError(1, 10, "Missing semicolon.")
.test("let [x]=;", { esversion: 6 });

TestRun(test, "const statement")
.addError(1, 11, "Expected an identifier and instead saw ';'.")
.addError(1, 12, "Missing semicolon.")
.test("const [x]=;", { esversion: 6 });

test.done();
};

exports["non-identifier PropertyNames in object destructuring"] = function (test) {
var code = [
"var { ['x' + 2]: a = 3, 0: b } = { x2: 1, 0: 2 };",
Expand Down

0 comments on commit b14acca

Please sign in to comment.