Skip to content

Commit

Permalink
Merge 9e7a35f into caeb223
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmasn committed Jun 27, 2018
2 parents caeb223 + 9e7a35f commit b216347
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/prefer-const.js
Expand Up @@ -170,7 +170,7 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
const elements = leftNode.elements;

hasOuterVariables = elements
.map(element => element.name)
.map(element => element && element.name)
.some(name => isOuterVariableInDestructing(name, variable.scope));
}
if (hasOuterVariables) {
Expand Down
21 changes: 20 additions & 1 deletion tests/lib/rules/prefer-const.js
Expand Up @@ -121,7 +121,11 @@ ruleTester.run("prefer-const", rule, {
{
code: "let x; function foo() { bar(x); } x = 0;",
options: [{ ignoreReadBeforeAssign: true }]
}
},

// https://github.com/eslint/eslint/issues/10520
"const x = [1,2]; let y; [,y] = x; y = 0;",
"const x = [1,2,3]; let y, z; [y,,z] = x; y = 0; z = 0;"
],
invalid: [
{
Expand Down Expand Up @@ -361,6 +365,21 @@ ruleTester.run("prefer-const", rule, {
{ message: "'foo' is never reassigned. Use 'const' instead.", type: "Identifier" },
{ message: "'bar' is never reassigned. Use 'const' instead.", type: "Identifier" }
]
},

// https://github.com/eslint/eslint/issues/10520
{
code: "const x = [1,2]; let [,y] = x;",
output: "const x = [1,2]; const [,y] = x;",
errors: [{ message: "'y' is never reassigned. Use 'const' instead.", type: "Identifier" }]
},
{
code: "const x = [1,2,3]; let [y,,z] = x;",
output: "const x = [1,2,3]; const [y,,z] = x;",
errors: [
{ message: "'y' is never reassigned. Use 'const' instead.", type: "Identifier" },
{ message: "'z' is never reassigned. Use 'const' instead.", type: "Identifier" }
]
}
]
});

0 comments on commit b216347

Please sign in to comment.