Skip to content

Commit e6f6018

Browse files
committed
[Fix] prefer-default-export: handle empty array destructuring
Fixes #1965
1 parent 8c1a65d commit e6f6018

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1111
- [`order`]: ignore non-module-level requires ([#1940], thanks [@golopot])
1212
- [`no-webpack-loader-syntax`]/TypeScript: avoid crash on missing name ([#1947], thanks @leonardodino)
1313
- [`no-extraneous-dependencies`]: Add package.json cache ([#1948], thanks @fa93hws)
14+
- [`prefer-default-export`]: handle empty array destructuring ([#1965], thanks @ljharb)
1415

1516
## [2.22.1] - 2020-09-27
1617
### Fixed
@@ -738,6 +739,7 @@ for info on changes for earlier releases.
738739

739740
[`memo-parser`]: ./memo-parser/README.md
740741

742+
[#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965
741743
[#1948]: https://github.com/benmosher/eslint-plugin-import/pull/1948
742744
[#1947]: https://github.com/benmosher/eslint-plugin-import/pull/1947
743745
[#1940]: https://github.com/benmosher/eslint-plugin-import/pull/1940

src/rules/prefer-default-export.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ module.exports = {
1919
let namedExportNode = null
2020

2121
function captureDeclaration(identifierOrPattern) {
22-
if (identifierOrPattern.type === 'ObjectPattern') {
22+
if (identifierOrPattern && identifierOrPattern.type === 'ObjectPattern') {
2323
// recursively capture
2424
identifierOrPattern.properties
2525
.forEach(function(property) {
2626
captureDeclaration(property.value)
2727
})
28-
} else if (identifierOrPattern.type === 'ArrayPattern') {
28+
} else if (identifierOrPattern && identifierOrPattern.type === 'ArrayPattern') {
2929
identifierOrPattern.elements
3030
.forEach(captureDeclaration)
3131
} else {

tests/src/rules/prefer-default-export.js

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ ruleTester.run('prefer-default-export', rule, {
8888
parser: require.resolve('babel-eslint'),
8989
}),
9090
// ...SYNTAX_CASES,
91+
{
92+
code: `
93+
export const [CounterProvider,, withCounter] = func();;
94+
`,
95+
parser: require.resolve('babel-eslint'),
96+
},
9197
],
9298
invalid: [
9399
test({

0 commit comments

Comments
 (0)