Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] allow using rest operator in named export #1878

Merged
merged 1 commit into from Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
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
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
Expand Up @@ -37,7 +37,7 @@ export function test(t) {
}, t, {
parserOptions: Object.assign({
sourceType: 'module',
ecmaVersion: 6,
ecmaVersion: 9,
}, t.parserOptions),
})
}
Expand Down