diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b4cb56088..987da7fb6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 diff --git a/package.json b/package.json index da8f028162..3323fa6721 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ExportMap.js b/src/ExportMap.js index d72952ef4c..dfd9ca155d 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -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, diff --git a/tests/files/typescript-d-ts/.eslintrc b/tests/files/typescript-d-ts/.eslintrc new file mode 100644 index 0000000000..f22e9cb620 --- /dev/null +++ b/tests/files/typescript-d-ts/.eslintrc @@ -0,0 +1,12 @@ +{ + "overrides": [ + { + "files": "**.ts", + "parser": "@typescript-eslint/parser", + "extends": "../../../config/typescript", + "rules": { + "import/export": "error", + }, + }, + ], +} diff --git a/tests/files/typescript-d-ts/file1.ts b/tests/files/typescript-d-ts/file1.ts new file mode 100644 index 0000000000..872c30e8af --- /dev/null +++ b/tests/files/typescript-d-ts/file1.ts @@ -0,0 +1,6 @@ +declare namespace ts { + const x: string; + export { x }; +} + +export = ts; diff --git a/tests/files/typescript-d-ts/file2.ts b/tests/files/typescript-d-ts/file2.ts new file mode 100644 index 0000000000..e8ed5afca7 --- /dev/null +++ b/tests/files/typescript-d-ts/file2.ts @@ -0,0 +1 @@ +export * from './file1.ts'