Skip to content

Commit d903477

Browse files
committed
[Fix] ExportMap: do not crash when tsconfig lacks .compilerOptions
Fixes #2067
1 parent dd0e8cb commit d903477

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
88

99
### Fixed
1010
- [`newline-after-import`]: fix crash with `export {}` syntax ([#2063], [#2056], thanks [@ljharb])
11+
- `ExportMap`: do not crash when tsconfig lacks `.compilerOptions` ([#2067], thanks [@ljharb])
1112

1213
## [2.23.0] - 2021-05-13
1314

@@ -1006,6 +1007,7 @@ for info on changes for earlier releases.
10061007
[#211]: https://github.com/benmosher/eslint-plugin-import/pull/211
10071008
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
10081009
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
1010+
[#2067]: https://github.com/benmosher/eslint-plugin-import/issues/2067
10091011
[#2056]: https://github.com/benmosher/eslint-plugin-import/issues/2056
10101012
[#2063]: https://github.com/benmosher/eslint-plugin-import/issues/2063
10111013
[#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965

src/ExportMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ ExportMap.parse = function (path, content, context) {
472472
tsConfigCache.set(cacheKey, tsConfig);
473473
}
474474

475-
return tsConfig !== null ? tsConfig.compilerOptions.esModuleInterop : false;
475+
return tsConfig && tsConfig.compilerOptions ? tsConfig.compilerOptions.esModuleInterop : false;
476476
}
477477

478478
ast.body.forEach(function (n) {

tests/src/rules/default.js

+20
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,26 @@ context('TypeScript', function () {
258258
},
259259
errors: ['No default export found in imported module "./typescript-export-as-default-namespace".'],
260260
}),
261+
test({
262+
code: `import Foo from "./typescript-export-as-default-namespace"`,
263+
parser: parser,
264+
settings: {
265+
'import/parsers': { [parser]: ['.ts'] },
266+
'import/resolver': { 'eslint-import-resolver-typescript': true },
267+
},
268+
parserOptions: {
269+
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-no-compiler-options/'),
270+
},
271+
errors: [
272+
{
273+
message: 'No default export found in imported module "./typescript-export-as-default-namespace".',
274+
line: 1,
275+
column: 8,
276+
endLine: 1,
277+
endColumn: 11,
278+
},
279+
],
280+
}),
261281
],
262282
});
263283
});

0 commit comments

Comments
 (0)