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] default: avoid crash with export = #1822

Merged
merged 1 commit into from
Jun 14, 2020
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
3 changes: 3 additions & 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

### Fixed
- [`no-extraneous-dependencies`]/TypeScript: do not error when importing type from dev dependencies ([#1820], thanks [@fernandopasik])
- [`default`]: avoid crash with `export =` ([#1822], thanks [@AndrewLeedham])

### Changed
- [`no-extraneous-dependencies`]: add tests for importing types ([#1824], thanks [@taye])
Expand Down Expand Up @@ -711,6 +712,7 @@ for info on changes for earlier releases.
[`memo-parser`]: ./memo-parser/README.md

[#1824]: https://github.com/benmosher/eslint-plugin-import/pull/1824
[#1822]: https://github.com/benmosher/eslint-plugin-import/pull/1822
[#1820]: https://github.com/benmosher/eslint-plugin-import/pull/1820
[#1819]: https://github.com/benmosher/eslint-plugin-import/pull/1819
[#1802]: https://github.com/benmosher/eslint-plugin-import/pull/1802
Expand Down Expand Up @@ -1230,3 +1232,4 @@ for info on changes for earlier releases.
[@nicolashenry]: https://github.com/nicolashenry
[@fernandopasik]: https://github.com/fernandopasik
[@taye]: https://github.com/taye
[@AndrewLeedham]: https://github.com/AndrewLeedham
4 changes: 3 additions & 1 deletion src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ ExportMap.parse = function (path, content, context) {

// This doesn't declare anything, but changes what's being exported.
if (includes(exports, n.type)) {
const exportedName = n.expression && n.expression.name || n.id.name
const exportedName = n.type === 'TSNamespaceExportDeclaration'
? n.id.name
: n.expression && n.expression.name || n.expression.id.name
const declTypes = [
'VariableDeclaration',
'ClassDeclaration',
Expand Down
1 change: 1 addition & 0 deletions tests/files/typescript-export-assign-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export = function foo() {};
8 changes: 8 additions & 0 deletions tests/src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ context('TypeScript', function () {
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import foobar from "./typescript-export-assign-function"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `import foobar from "./typescript-export-assign-mixed"`,
parser: parser,
Expand Down