Skip to content

Commit

Permalink
[Fix] prefer-default-export: handle empty array destructuring
Browse files Browse the repository at this point in the history
Fixes #1965
  • Loading branch information
ljharb committed Dec 15, 2020
1 parent 8c1a65d commit e6f6018
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`order`]: ignore non-module-level requires ([#1940], thanks [@golopot])
- [`no-webpack-loader-syntax`]/TypeScript: avoid crash on missing name ([#1947], thanks @leonardodino)
- [`no-extraneous-dependencies`]: Add package.json cache ([#1948], thanks @fa93hws)
- [`prefer-default-export`]: handle empty array destructuring ([#1965], thanks @ljharb)

## [2.22.1] - 2020-09-27
### Fixed
Expand Down Expand Up @@ -738,6 +739,7 @@ for info on changes for earlier releases.

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

[#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965
[#1948]: https://github.com/benmosher/eslint-plugin-import/pull/1948
[#1947]: https://github.com/benmosher/eslint-plugin-import/pull/1947
[#1940]: https://github.com/benmosher/eslint-plugin-import/pull/1940
Expand Down
4 changes: 2 additions & 2 deletions src/rules/prefer-default-export.js
Expand Up @@ -19,13 +19,13 @@ module.exports = {
let namedExportNode = null

function captureDeclaration(identifierOrPattern) {
if (identifierOrPattern.type === 'ObjectPattern') {
if (identifierOrPattern && identifierOrPattern.type === 'ObjectPattern') {
// recursively capture
identifierOrPattern.properties
.forEach(function(property) {
captureDeclaration(property.value)
})
} else if (identifierOrPattern.type === 'ArrayPattern') {
} else if (identifierOrPattern && identifierOrPattern.type === 'ArrayPattern') {
identifierOrPattern.elements
.forEach(captureDeclaration)
} else {
Expand Down
6 changes: 6 additions & 0 deletions tests/src/rules/prefer-default-export.js
Expand Up @@ -88,6 +88,12 @@ ruleTester.run('prefer-default-export', rule, {
parser: require.resolve('babel-eslint'),
}),
// ...SYNTAX_CASES,
{
code: `
export const [CounterProvider,, withCounter] = func();;
`,
parser: require.resolve('babel-eslint'),
},

This comment has been minimized.

Copy link
@webmaster128

webmaster128 Dec 21, 2020

isn't there a test(…) missing for this case?

This comment has been minimized.

Copy link
@ljharb

ljharb Dec 21, 2020

Author Member

whoops, yes, thanks :-) all it does is add a filename, and set the sourceType and ecmaVersion, which babel-eslint handles, so it doesn't change anything - but the consistency is nice.

Done in 18f9bd3.

],
invalid: [
test({
Expand Down

0 comments on commit e6f6018

Please sign in to comment.