diff --git a/src/ExportMap.js b/src/ExportMap.js index e18797a4d7..885801fbbb 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -346,7 +346,11 @@ ExportMap.for = function (context) { exportMap = ExportMap.parse(path, content, context); // ambiguous modules return null - if (exportMap == null) return null; + if (exportMap == null) { + log('ignored path due to ambiguous parse:', path); + exportCache.set(cacheKey, null); + return null; + } exportMap.mtime = stats.mtime; diff --git a/tests/files/typescript-declare-module.ts b/tests/files/typescript-declare-module.ts new file mode 100644 index 0000000000..8a9e304e91 --- /dev/null +++ b/tests/files/typescript-declare-module.ts @@ -0,0 +1,3 @@ +declare module "typescript-declare-module-foo" { + export const foo: string; +} diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index 867644bc19..9b1100adfd 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -104,6 +104,27 @@ describe('ExportMap', function () { expect(imports.has('Bar')).to.be.true; }); + it('should cache after parsing for an ambiguous module', function () { + const context = Object.assign({}, fakeContext, { + settings: { + 'import/extensions': ['.js'], + 'import/parsers': { + '@typescript-eslint/parser': ['.ts', '.tsx'], + }, + }, + }); + const source = './typescript-declare-module.ts'; + const parseSpy = sinon.spy(ExportMap, 'parse'); + + expect(ExportMap.get(source, context)).to.be.null; + + ExportMap.get(source, context); + + expect(parseSpy.callCount).to.equal(1); + + parseSpy.restore(); + }); + context('deprecation metadata', function () { function jsdocTests(parseContext, lineEnding) {