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..dcfa74d835 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -431,6 +431,19 @@ describe('ExportMap', function () { ExportMap.parse('./baz.ts', 'export const baz = 5', differentContext); expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(2); }); + + it('should cache after parsing for an ambiguous module', function () { + 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(); + }); }); }); });