Skip to content

Commit 2563e8b

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 569d726 commit 2563e8b

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
### Changed
1516
- [`export`]: add tests for a name collision with `export * from` ([#1704], thanks @tomprats)

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)