From d903477f4e31be71e016f8af56cbe2a8d4f11c9c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 14 May 2021 11:24:13 -0700 Subject: [PATCH] [Fix] ExportMap: do not crash when tsconfig lacks `.compilerOptions` Fixes #2067 --- CHANGELOG.md | 2 ++ src/ExportMap.js | 2 +- tests/src/rules/default.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 454d55e62..44ab437d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed - [`newline-after-import`]: fix crash with `export {}` syntax ([#2063], [#2056], thanks [@ljharb]) +- `ExportMap`: do not crash when tsconfig lacks `.compilerOptions` ([#2067], thanks [@ljharb]) ## [2.23.0] - 2021-05-13 @@ -1006,6 +1007,7 @@ for info on changes for earlier releases. [#211]: https://github.com/benmosher/eslint-plugin-import/pull/211 [#164]: https://github.com/benmosher/eslint-plugin-import/pull/164 [#157]: https://github.com/benmosher/eslint-plugin-import/pull/157 +[#2067]: https://github.com/benmosher/eslint-plugin-import/issues/2067 [#2056]: https://github.com/benmosher/eslint-plugin-import/issues/2056 [#2063]: https://github.com/benmosher/eslint-plugin-import/issues/2063 [#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965 diff --git a/src/ExportMap.js b/src/ExportMap.js index 215f3de71..9cc7a089e 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -472,7 +472,7 @@ ExportMap.parse = function (path, content, context) { tsConfigCache.set(cacheKey, tsConfig); } - return tsConfig !== null ? tsConfig.compilerOptions.esModuleInterop : false; + return tsConfig && tsConfig.compilerOptions ? tsConfig.compilerOptions.esModuleInterop : false; } ast.body.forEach(function (n) { diff --git a/tests/src/rules/default.js b/tests/src/rules/default.js index 7ff654972..c7eb780d0 100644 --- a/tests/src/rules/default.js +++ b/tests/src/rules/default.js @@ -258,6 +258,26 @@ context('TypeScript', function () { }, errors: ['No default export found in imported module "./typescript-export-as-default-namespace".'], }), + test({ + code: `import Foo from "./typescript-export-as-default-namespace"`, + parser: parser, + settings: { + 'import/parsers': { [parser]: ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + parserOptions: { + tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-no-compiler-options/'), + }, + errors: [ + { + message: 'No default export found in imported module "./typescript-export-as-default-namespace".', + line: 1, + column: 8, + endLine: 1, + endColumn: 11, + }, + ], + }), ], }); });