Skip to content

Commit

Permalink
[fix] prefer-default-export: fix cases when exporting array destruc…
Browse files Browse the repository at this point in the history
…turing

Fixes #706
  • Loading branch information
golopot authored and ljharb committed Aug 24, 2019
1 parent 5e143b2 commit 3704801
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module.exports = {
.forEach(function(property) {
captureDeclaration(property.value)
})
} else {
} else if (identifierOrPattern.type === 'ArrayPattern') {
identifierOrPattern.elements
.forEach(captureDeclaration)
} else {
// assume it's a single standard identifier
specifierExportCount++
}
Expand Down
12 changes: 12 additions & 0 deletions tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ ruleTester.run('prefer-default-export', rule, {
code: `
export const { foo: { bar, baz } } = item;`,
}),
test({
code: `
export const [a, b] = item;`,
}),
test({
code: `
let item;
Expand Down Expand Up @@ -127,6 +131,14 @@ ruleTester.run('prefer-default-export', rule, {
message: 'Prefer default export.',
}],
}),
test({
code: `
export const [a] = ["foo"]`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
}],
}),
],
})

Expand Down

0 comments on commit 3704801

Please sign in to comment.