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] export/TypeScript: properly detect export specifiers as children of a TS module block #1889

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

### Fixed
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block ([#1889], thanks [@andreubotella])

## [2.22.1] - 2020-09-27
### Fixed
- [`default`]/TypeScript: avoid crash on `export =` with a MemberExpression ([#1841], thanks [@ljharb])
Expand Down Expand Up @@ -732,6 +735,7 @@ for info on changes for earlier releases.

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

[#1889]: https://github.com/benmosher/eslint-plugin-import/pull/1889
[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
[#1848]: https://github.com/benmosher/eslint-plugin-import/pull/1848
Expand Down Expand Up @@ -1276,3 +1280,4 @@ for info on changes for earlier releases.
[@foray1010]: https://github.com/foray1010
[@tomprats]: https://github.com/tomprats
[@straub]: https://github.com/straub
[@andreubotella]: https://github.com/andreubotella
6 changes: 5 additions & 1 deletion src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ module.exports = {
return {
'ExportDefaultDeclaration': (node) => addNamed('default', node, getParent(node)),

'ExportSpecifier': (node) => addNamed(node.exported.name, node.exported, getParent(node)),
'ExportSpecifier': (node) => addNamed(
node.exported.name,
node.exported,
getParent(node.parent)
),

Comment on lines +90 to 95
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a bit confused; all this is doing is reformatting. do these tests pass on master?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changes getParent(node) to getParent(node.parent). That would've been more obvious if I hadn't reformatted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

'ExportNamedDeclaration': function (node) {
if (node.declaration == null) return
Expand Down
48 changes: 48 additions & 0 deletions tests/src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ context('TypeScript', function () {
parser: parser,
}),
]),

// Exports in ambient modules
test(Object.assign({
code: `
declare module "a" {
const Foo = 1;
export {Foo as default};
}
declare module "b" {
const Bar = 2;
export {Bar as default};
}
`,
}, parserConfig)),
test(Object.assign({
code: `
declare module "a" {
const Foo = 1;
export {Foo as default};
}
const Bar = 2;
export {Bar as default};
`,
}, parserConfig)),
],
invalid: [
// type/value name clash
Expand Down Expand Up @@ -312,6 +336,30 @@ context('TypeScript', function () {
},
],
}, parserConfig)),

// Exports in ambient modules
test(Object.assign({
code: `
declare module "a" {
const Foo = 1;
export {Foo as default};
}
const Bar = 2;
export {Bar as default};
const Baz = 3;
export {Baz as default};
`,
errors: [
{
message: 'Multiple default exports.',
line: 7,
},
{
message: 'Multiple default exports.',
line: 9,
},
],
}, parserConfig)),
],
})
})
Expand Down