Skip to content

Commit 82a3ea7

Browse files
committed
[Fix] ExportMap: add caching after parsing for an ambiguous module
1 parent 7cb6fcd commit 82a3ea7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/ExportMap.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,11 @@ ExportMap.for = function (context) {
346346
exportMap = ExportMap.parse(path, content, context);
347347

348348
// ambiguous modules return null
349-
if (exportMap == null) return null;
349+
if (exportMap == null) {
350+
log('ignored path due to ambiguous parse:', path);
351+
exportCache.set(cacheKey, null);
352+
return null;
353+
}
350354

351355
exportMap.mtime = stats.mtime;
352356

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "typescript-declare-module-foo" {
2+
export const foo: string;
3+
}

tests/src/core/getExports.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ describe('ExportMap', function () {
431431
ExportMap.parse('./baz.ts', 'export const baz = 5', differentContext);
432432
expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(2);
433433
});
434+
435+
it('should cache after parsing for an ambiguous module', function () {
436+
const source = './typescript-declare-module.ts';
437+
const parseSpy = sinon.spy(ExportMap, 'parse');
438+
439+
expect(ExportMap.get(source, context)).to.be.null;
440+
441+
ExportMap.get(source, context);
442+
443+
expect(parseSpy.callCount).to.equal(1);
444+
445+
parseSpy.restore();
446+
});
434447
});
435448
});
436449
});

0 commit comments

Comments
 (0)