Skip to content

Commit 5fe14e3

Browse files
foray1010ljharb
authored andcommitted
[Fix] allow using rest operator in named export
1 parent 3e65a70 commit 5fe14e3

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
99
### Fixed
1010
- [`default`]/TypeScript: avoid crash on `export =` with a MemberExpression ([#1841], thanks [@ljharb])
1111
- [`extensions`]/importType: Fix @/abc being treated as scoped module ([#1854], thanks [@3nuc])
12+
- allow using rest operator in named export ([#1878], thanks [@foray1010])
1213

1314
## [2.22.0] - 2020-06-26
1415
### Added
@@ -726,6 +727,7 @@ for info on changes for earlier releases.
726727

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

730+
[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878
729731
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
730732
[#1841]: https://github.com/benmosher/eslint-plugin-import/issues/1841
731733
[#1836]: https://github.com/benmosher/eslint-plugin-import/pull/1836
@@ -1263,3 +1265,4 @@ for info on changes for earlier releases.
12631265
[@noelebrun]: https://github.com/noelebrun
12641266
[@beatrizrezener]: https://github.com/beatrizrezener
12651267
[@3nuc]: https://github.com/3nuc
1268+
[@foray1010]: https://github.com/foray1010

src/ExportMap.js

+8
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,21 @@ export function recursivePatternCapture(pattern, callback) {
650650

651651
case 'ObjectPattern':
652652
pattern.properties.forEach(p => {
653+
if (p.type === 'ExperimentalRestProperty' || p.type === 'RestElement') {
654+
callback(p.argument)
655+
return
656+
}
653657
recursivePatternCapture(p.value, callback)
654658
})
655659
break
656660

657661
case 'ArrayPattern':
658662
pattern.elements.forEach((element) => {
659663
if (element == null) return
664+
if (element.type === 'ExperimentalRestProperty' || element.type === 'RestElement') {
665+
callback(element.argument)
666+
return
667+
}
660668
recursivePatternCapture(element, callback)
661669
})
662670
break

tests/files/named-exports.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export class ExportedClass {
1313

1414
// destructuring exports
1515

16-
export var { destructuredProp } = {}
16+
export var { destructuredProp, ...restProps } = {}
1717
, { destructingAssign = null } = {}
1818
, { destructingAssign: destructingRenamedAssign = null } = {}
19-
, [ arrayKeyProp ] = []
19+
, [ arrayKeyProp, ...arrayRestKeyProps ] = []
2020
, [ { deepProp } ] = []
2121
, { arr: [ ,, deepSparseElement ] } = {}

tests/src/core/getExports.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('ExportMap', function () {
295295
context('#size', function () {
296296

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

300300
it('includes exported namespace size', () => expect(ExportMap.get('./export-all', fakeContext))
301301
.to.have.property('size', 1))

tests/src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function test(t) {
3737
}, t, {
3838
parserOptions: Object.assign({
3939
sourceType: 'module',
40-
ecmaVersion: 6,
40+
ecmaVersion: 9,
4141
}, t.parserOptions),
4242
})
4343
}

0 commit comments

Comments
 (0)