Skip to content

Commit

Permalink
[Fix] default: avoid crash with export =
Browse files Browse the repository at this point in the history
Fixes #1818.

Co-authored-by: AndrewLeedham <AndrewLeedham@Outlook.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
AndrewLeedham and ljharb committed Jun 12, 2020
1 parent 6f5d95a commit b22a183
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
@@ -0,0 +1 @@
export = function foo() {};
8 changes: 8 additions & 0 deletions tests/src/rules/default.js
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

0 comments on commit b22a183

Please sign in to comment.