Skip to content

Commit a00727e

Browse files
Andreu Botellaljharb
Andreu Botella
authored andcommitted
[Fix] export/TypeScript: properly detect export specifiers as children of a TS module block
Fixes #1773
1 parent 5ade156 commit a00727e

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66

77
## [Unreleased]
88

9+
### Fixed
10+
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block ([#1889], thanks [@andreubotella])
11+
912
## [2.22.1] - 2020-09-27
1013
### Fixed
1114
- [`default`]/TypeScript: avoid crash on `export =` with a MemberExpression ([#1841], thanks [@ljharb])
@@ -732,6 +735,7 @@ for info on changes for earlier releases.
732735

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

738+
[#1889]: https://github.com/benmosher/eslint-plugin-import/pull/1889
735739
[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878
736740
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
737741
[#1848]: https://github.com/benmosher/eslint-plugin-import/pull/1848
@@ -1276,3 +1280,4 @@ for info on changes for earlier releases.
12761280
[@foray1010]: https://github.com/foray1010
12771281
[@tomprats]: https://github.com/tomprats
12781282
[@straub]: https://github.com/straub
1283+
[@andreubotella]: https://github.com/andreubotella

src/rules/export.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ module.exports = {
8787
return {
8888
'ExportDefaultDeclaration': (node) => addNamed('default', node, getParent(node)),
8989

90-
'ExportSpecifier': (node) => addNamed(node.exported.name, node.exported, getParent(node)),
90+
'ExportSpecifier': (node) => addNamed(
91+
node.exported.name,
92+
node.exported,
93+
getParent(node.parent)
94+
),
9195

9296
'ExportNamedDeclaration': function (node) {
9397
if (node.declaration == null) return

tests/src/rules/export.js

+48
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ context('TypeScript', function () {
221221
parser: parser,
222222
}),
223223
]),
224+
225+
// Exports in ambient modules
226+
test(Object.assign({
227+
code: `
228+
declare module "a" {
229+
const Foo = 1;
230+
export {Foo as default};
231+
}
232+
declare module "b" {
233+
const Bar = 2;
234+
export {Bar as default};
235+
}
236+
`,
237+
}, parserConfig)),
238+
test(Object.assign({
239+
code: `
240+
declare module "a" {
241+
const Foo = 1;
242+
export {Foo as default};
243+
}
244+
const Bar = 2;
245+
export {Bar as default};
246+
`,
247+
}, parserConfig)),
224248
],
225249
invalid: [
226250
// type/value name clash
@@ -312,6 +336,30 @@ context('TypeScript', function () {
312336
},
313337
],
314338
}, parserConfig)),
339+
340+
// Exports in ambient modules
341+
test(Object.assign({
342+
code: `
343+
declare module "a" {
344+
const Foo = 1;
345+
export {Foo as default};
346+
}
347+
const Bar = 2;
348+
export {Bar as default};
349+
const Baz = 3;
350+
export {Baz as default};
351+
`,
352+
errors: [
353+
{
354+
message: 'Multiple default exports.',
355+
line: 7,
356+
},
357+
{
358+
message: 'Multiple default exports.',
359+
line: 9,
360+
},
361+
],
362+
}, parserConfig)),
315363
],
316364
})
317365
})

0 commit comments

Comments
 (0)