diff --git a/.eslintignore b/.eslintignore index b260021d4..9d2200682 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,6 +5,7 @@ node_modules tests/files/malformed.js tests/files/with-syntax-error tests/files/just-json-files/invalid.json +tests/files/typescript-d-ts/ resolvers/webpack/test/files # we want to ignore "tests/files" here, but unfortunately doing so would # interfere with unit test and fail it for some reason. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b4cb5608..987da7fb6 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/src/ExportMap.js b/src/ExportMap.js index d72952ef4..dfd9ca155 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 000000000..f22e9cb62 --- /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 000000000..872c30e8a --- /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 000000000..e8ed5afca --- /dev/null +++ b/tests/files/typescript-d-ts/file2.ts @@ -0,0 +1 @@ +export * from './file1.ts' diff --git a/tests/src/cli.js b/tests/src/cli.js index 53d6e8fdc..5e0a74e36 100644 --- a/tests/src/cli.js +++ b/tests/src/cli.js @@ -22,7 +22,7 @@ describe('CLI regression tests', function () { }) }) it("doesn't throw an error on gratuitous, erroneous self-reference", function () { - expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw(Error) + expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw() }) }) @@ -41,7 +41,7 @@ describe('CLI regression tests', function () { } }) - it('throws an error on invalid JSON', function () { + it('throws an error on invalid JSON', () => { const invalidJSON = './tests/files/just-json-files/invalid.json' const results = cli.executeOnFiles([invalidJSON]) expect(results).to.eql({ diff --git a/tests/src/rules/export.js b/tests/src/rules/export.js index 76fae4567..fb301495e 100644 --- a/tests/src/rules/export.js +++ b/tests/src/rules/export.js @@ -1,4 +1,4 @@ -import { test, SYNTAX_CASES, getTSParsers } from '../utils' +import { test, testFilePath, SYNTAX_CASES, getTSParsers } from '../utils' import { RuleTester } from 'eslint' @@ -187,6 +187,10 @@ context('TypeScript', function () { } `, }, parserConfig)), + test(Object.assign({ + code: 'export * from "./file1.ts"', + filename: testFilePath('typescript-d-ts/file-2.ts'), + }, parserConfig)), ], invalid: [ // type/value name clash