Skip to content

Commit

Permalink
[[FIX]] Allow destructuring in catch blocks parameter
Browse files Browse the repository at this point in the history
Fixes #2526
  • Loading branch information
nicolo-ribaudo authored and lukeapage committed Jul 9, 2015
1 parent 0604816 commit 759644c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3757,21 +3757,26 @@ var JSHINT = (function() {
var b;

function doCatch() {
var e;
var params = [];

advance("catch");
advance("(");

e = state.tokens.next;
if (e.type !== "(identifier)") {
warning("E030", state.tokens.next, e.value);
e = null;
if (checkPunctuators(state.tokens.next, ["[", "{"])) {
var tokens = destructuringExpression();
_.each(tokens, function(token) {
if (token.id) {
params.push({ id: token.id, token: token });
}
});
} else if (state.tokens.next.type !== "(identifier)") {
warning("E030", state.tokens.next, state.tokens.next.value);
} else {
// only advance if we have an identifier so we can continue parsing in the most common error - that no param is given.
advance();
params.push({ id: identifier(), token: state.tokens.curr, type: "exception" });
}

state.funct["(scope)"].stackParams(e ? [ { id: e.value, token: e, type: "exception" }] : []);
state.funct["(scope)"].stackParams(params);

if (state.tokens.next.value === "if") {
if (!state.inMoz()) {
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ exports.testCatchBlocks = function (test) {
TestRun(test)
.test(src, { es3: true, undef: true, devel: true, node: true });

var code = "try {} catch ({ message }) {}";

TestRun(test, "destructuring in catch blocks' parameter")
.test(code, { esnext: true });

test.done();
};

Expand Down

0 comments on commit 759644c

Please sign in to comment.