Skip to content

Commit

Permalink
[Fix] allow using rest operator in named export
Browse files Browse the repository at this point in the history
  • Loading branch information
foray1010 authored and ljharb committed Aug 14, 2020
1 parent 3e65a70 commit 5fe14e3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- [`default`]/TypeScript: avoid crash on `export =` with a MemberExpression ([#1841], thanks [@ljharb])
- [`extensions`]/importType: Fix @/abc being treated as scoped module ([#1854], thanks [@3nuc])
- allow using rest operator in named export ([#1878], thanks [@foray1010])

## [2.22.0] - 2020-06-26
### Added
Expand Down Expand Up @@ -726,6 +727,7 @@ for info on changes for earlier releases.

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

[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
[#1841]: https://github.com/benmosher/eslint-plugin-import/issues/1841
[#1836]: https://github.com/benmosher/eslint-plugin-import/pull/1836
Expand Down Expand Up @@ -1263,3 +1265,4 @@ for info on changes for earlier releases.
[@noelebrun]: https://github.com/noelebrun
[@beatrizrezener]: https://github.com/beatrizrezener
[@3nuc]: https://github.com/3nuc
[@foray1010]: https://github.com/foray1010
8 changes: 8 additions & 0 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,21 @@ export function recursivePatternCapture(pattern, callback) {

case 'ObjectPattern':
pattern.properties.forEach(p => {
if (p.type === 'ExperimentalRestProperty' || p.type === 'RestElement') {
callback(p.argument)
return
}
recursivePatternCapture(p.value, callback)
})
break

case 'ArrayPattern':
pattern.elements.forEach((element) => {
if (element == null) return
if (element.type === 'ExperimentalRestProperty' || element.type === 'RestElement') {
callback(element.argument)
return
}
recursivePatternCapture(element, callback)
})
break
Expand Down
4 changes: 2 additions & 2 deletions tests/files/named-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class ExportedClass {

// destructuring exports

export var { destructuredProp } = {}
export var { destructuredProp, ...restProps } = {}
, { destructingAssign = null } = {}
, { destructingAssign: destructingRenamedAssign = null } = {}
, [ arrayKeyProp ] = []
, [ arrayKeyProp, ...arrayRestKeyProps ] = []
, [ { deepProp } ] = []
, { arr: [ ,, deepSparseElement ] } = {}
2 changes: 1 addition & 1 deletion tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe('ExportMap', function () {
context('#size', function () {

it('counts the names', () => expect(ExportMap.get('./named-exports', fakeContext))
.to.have.property('size', 10))
.to.have.property('size', 12))

it('includes exported namespace size', () => expect(ExportMap.get('./export-all', fakeContext))
.to.have.property('size', 1))
Expand Down
2 changes: 1 addition & 1 deletion tests/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function test(t) {
}, t, {
parserOptions: Object.assign({
sourceType: 'module',
ecmaVersion: 6,
ecmaVersion: 9,
}, t.parserOptions),
})
}
Expand Down

0 comments on commit 5fe14e3

Please sign in to comment.