Skip to content

Commit 55ed64b

Browse files
committed
[Fix] TypeScript: export: avoid a crash with export =
Fixes import-js#1801.
1 parent 0d6d12e commit 55ed64b

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2424
- [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619])
2525
- [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur])
2626
- [`no-internal-modules`]: also check `export from` syntax ([#1691], thanks [@adjerbetian])
27+
- TypeScript: [`export`]: avoid a crash with `export =` ([#1801], thanks [@ljharb])
2728

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

692693
[#1802]: https://github.com/benmosher/eslint-plugin-import/pull/1802
694+
[#1801]: https://github.com/benmosher/eslint-plugin-import/issues/1801
693695
[#1788]: https://github.com/benmosher/eslint-plugin-import/pull/1788
694696
[#1786]: https://github.com/benmosher/eslint-plugin-import/pull/1786
695697
[#1785]: https://github.com/benmosher/eslint-plugin-import/pull/1785

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
7777
"eslint-module-utils": "file:./utils",
7878
"eslint-plugin-eslint-plugin": "^2.2.1",
79-
"eslint-plugin-import": "2.x",
79+
"eslint-plugin-import": "file:./",
8080
"eslint-plugin-json": "^2.1.1",
8181
"fs-copy-file-sync": "^1.1.1",
8282
"glob": "^7.1.6",

src/ExportMap.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,9 @@ ExportMap.parse = function (path, content, context) {
590590
moduleBlockNode.declaration :
591591
moduleBlockNode
592592

593-
if (namespaceDecl.type === 'VariableDeclaration') {
593+
if (!namespaceDecl) {
594+
// TypeScript can check this for us; we needn't
595+
} else if (namespaceDecl.type === 'VariableDeclaration') {
594596
namespaceDecl.declarations.forEach((d) =>
595597
recursivePatternCapture(d.id, (id) => m.namespace.set(
596598
id.name,

tests/files/typescript-d-ts/.eslintrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": "**.ts",
5+
"parser": "@typescript-eslint/parser",
6+
"extends": "../../../config/typescript",
7+
"rules": {
8+
"import/export": "error",
9+
},
10+
},
11+
],
12+
}

tests/files/typescript-d-ts/file1.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare namespace ts {
2+
const x: string;
3+
export { x };
4+
}
5+
6+
export = ts;

tests/files/typescript-d-ts/file2.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './file1.ts'

0 commit comments

Comments
 (0)