Skip to content

Commit

Permalink
[[FIX]] Allow parentheses around object destructuring assignment.
Browse files Browse the repository at this point in the history
Fixes gh-2775
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Feb 14, 2016
1 parent 97d0ac1 commit 7a0bd70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2575,7 +2575,9 @@ var JSHINT = (function() {
// Used to delineate an integer number literal from a dereferencing
// punctuator (otherwise interpreted as a decimal point)
(ret.type === "(number)" &&
checkPunctuator(pn, ".") && /^\d+$/.test(ret.value));
checkPunctuator(pn, ".") && /^\d+$/.test(ret.value)) ||
// Used to wrap object destructuring assignment
(opening.beginsStmt && ret.id === "=" && ret.left.id === "{");
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,26 @@ singleGroups.postfix = function (test) {
test.done();
};

singleGroups.destructuringAssign = function (test) {

var code = [
// statements
"({ x } = { x : 1 });",
"([ x ] = [ 1 ]);",
// expressions
"1, ({ x } = { x : 1 });",
"1, ([ x ] = [ 1 ]);"
];

TestRun(test)
.addError(2, "Unnecessary grouping operator.")
.addError(3, "Unnecessary grouping operator.")
.addError(4, "Unnecessary grouping operator.")
.test(code, { esversion: 6, singleGroups: true, expr: true });

test.done();
};

exports.elision = function (test) {
var code = [
"var a = [1,,2];",
Expand Down

0 comments on commit 7a0bd70

Please sign in to comment.