Skip to content

Commit

Permalink
[Fix] export/TypeScript: properly detect export specifiers as child…
Browse files Browse the repository at this point in the history
…ren of a TS module block

Fixes import-js#1773
  • Loading branch information
Andreu Botella committed Aug 20, 2020
1 parent 5fe14e3 commit 2b5705b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`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])
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block

## [2.22.0] - 2020-06-26
### Added
Expand Down
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)
),

'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 @@ -212,6 +212,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 @@ -303,6 +327,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

0 comments on commit 2b5705b

Please sign in to comment.