From 5fe14e391f8c74c23f1d78fd547791f79ad30146 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Fri, 14 Aug 2020 09:22:49 +0800 Subject: [PATCH] [Fix] allow using rest operator in named export --- CHANGELOG.md | 3 +++ src/ExportMap.js | 8 ++++++++ tests/files/named-exports.js | 4 ++-- tests/src/core/getExports.js | 2 +- tests/src/utils.js | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e04d630..56c6fb4c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 @@ -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 diff --git a/src/ExportMap.js b/src/ExportMap.js index eb6ad58fc..837546aeb 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -650,6 +650,10 @@ 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 @@ -657,6 +661,10 @@ export function recursivePatternCapture(pattern, callback) { 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 diff --git a/tests/files/named-exports.js b/tests/files/named-exports.js index f2881c10c..d8b17bb90 100644 --- a/tests/files/named-exports.js +++ b/tests/files/named-exports.js @@ -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 ] } = {} diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index d61544e7a..145f236f1 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -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)) diff --git a/tests/src/utils.js b/tests/src/utils.js index 4bc8f0119..0f45e7bf2 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -37,7 +37,7 @@ export function test(t) { }, t, { parserOptions: Object.assign({ sourceType: 'module', - ecmaVersion: 6, + ecmaVersion: 9, }, t.parserOptions), }) }