Skip to content

Commit 2b5705b

Browse files
author
Andreu Botella
committed
[Fix] export/TypeScript: properly detect export specifiers as children of a TS module block
Fixes import-js#1773
1 parent 5fe14e3 commit 2b5705b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
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])
1212
- allow using rest operator in named export ([#1878], thanks [@foray1010])
13+
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block
1314

1415
## [2.22.0] - 2020-06-26
1516
### Added

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
@@ -212,6 +212,30 @@ context('TypeScript', function () {
212212
parser: parser,
213213
}),
214214
]),
215+
216+
// Exports in ambient modules
217+
test(Object.assign({
218+
code: `
219+
declare module "a" {
220+
const Foo = 1;
221+
export {Foo as default};
222+
}
223+
declare module "b" {
224+
const Bar = 2;
225+
export {Bar as default};
226+
}
227+
`,
228+
}, parserConfig)),
229+
test(Object.assign({
230+
code: `
231+
declare module "a" {
232+
const Foo = 1;
233+
export {Foo as default};
234+
}
235+
const Bar = 2;
236+
export {Bar as default};
237+
`,
238+
}, parserConfig)),
215239
],
216240
invalid: [
217241
// type/value name clash
@@ -303,6 +327,30 @@ context('TypeScript', function () {
303327
},
304328
],
305329
}, parserConfig)),
330+
331+
// Exports in ambient modules
332+
test(Object.assign({
333+
code: `
334+
declare module "a" {
335+
const Foo = 1;
336+
export {Foo as default};
337+
}
338+
const Bar = 2;
339+
export {Bar as default};
340+
const Baz = 3;
341+
export {Baz as default};
342+
`,
343+
errors: [
344+
{
345+
message: 'Multiple default exports.',
346+
line: 7,
347+
},
348+
{
349+
message: 'Multiple default exports.',
350+
line: 9,
351+
},
352+
],
353+
}, parserConfig)),
306354
],
307355
})
308356
})

0 commit comments

Comments
 (0)