Skip to content

Commit

Permalink
[Fix] TypeScript: export: avoid a crash with export =
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 7, 2020
1 parent 0d6d12e commit 55ed64b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619])
- [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur])
- [`no-internal-modules`]: also check `export from` syntax ([#1691], thanks [@adjerbetian])
- TypeScript: [`export`]: avoid a crash with `export =` ([#1801], thanks [@ljharb])

### Changed
- [Refactor] `no-extraneous-dependencies`: use moduleVisitor ([#1735], thanks [@adamborowski])
Expand Down Expand Up @@ -690,6 +691,7 @@ for info on changes for earlier releases.
[`memo-parser`]: ./memo-parser/README.md

[#1802]: https://github.com/benmosher/eslint-plugin-import/pull/1802
[#1801]: https://github.com/benmosher/eslint-plugin-import/issues/1801
[#1788]: https://github.com/benmosher/eslint-plugin-import/pull/1788
[#1786]: https://github.com/benmosher/eslint-plugin-import/pull/1786
[#1785]: https://github.com/benmosher/eslint-plugin-import/pull/1785
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -76,7 +76,7 @@
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
"eslint-module-utils": "file:./utils",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-import": "2.x",
"eslint-plugin-import": "file:./",
"eslint-plugin-json": "^2.1.1",
"fs-copy-file-sync": "^1.1.1",
"glob": "^7.1.6",
Expand Down
4 changes: 3 additions & 1 deletion src/ExportMap.js
Expand Up @@ -590,7 +590,9 @@ ExportMap.parse = function (path, content, context) {
moduleBlockNode.declaration :
moduleBlockNode

if (namespaceDecl.type === 'VariableDeclaration') {
if (!namespaceDecl) {
// TypeScript can check this for us; we needn't
} else if (namespaceDecl.type === 'VariableDeclaration') {
namespaceDecl.declarations.forEach((d) =>
recursivePatternCapture(d.id, (id) => m.namespace.set(
id.name,
Expand Down
12 changes: 12 additions & 0 deletions tests/files/typescript-d-ts/.eslintrc
@@ -0,0 +1,12 @@
{
"overrides": [
{
"files": "**.ts",
"parser": "@typescript-eslint/parser",
"extends": "../../../config/typescript",
"rules": {
"import/export": "error",
},
},
],
}
6 changes: 6 additions & 0 deletions tests/files/typescript-d-ts/file1.ts
@@ -0,0 +1,6 @@
declare namespace ts {
const x: string;
export { x };
}

export = ts;
1 change: 1 addition & 0 deletions tests/files/typescript-d-ts/file2.ts
@@ -0,0 +1 @@
export * from './file1.ts'

0 comments on commit 55ed64b

Please sign in to comment.