Skip to content

Commit

Permalink
[Fix] ExportMap: do not crash when tsconfig lacks .compilerOptions
Browse files Browse the repository at this point in the history
Fixes #2067
  • Loading branch information
ljharb committed May 14, 2021
1 parent dd0e8cb commit d903477
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ExportMap.js
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions tests/src/rules/default.js
Expand Up @@ -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,
},
],
}),
],
});
});
Expand Down

0 comments on commit d903477

Please sign in to comment.