Skip to content

Commit 4ccce6f

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

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/ExportMap.js

+5-1
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

+3
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

+21
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ describe('ExportMap', function () {
104104
expect(imports.has('Bar')).to.be.true;
105105
});
106106

107+
it('should cache after parsing for an ambiguous module', function () {
108+
const context = Object.assign({}, fakeContext, {
109+
settings: {
110+
'import/extensions': ['.js'],
111+
'import/parsers': {
112+
'@typescript-eslint/parser': ['.ts', '.tsx'],
113+
},
114+
},
115+
});
116+
const source = './typescript-declare-module.ts';
117+
const parseSpy = sinon.spy(ExportMap, 'parse');
118+
119+
expect(ExportMap.get(source, context)).to.be.null;
120+
121+
ExportMap.get(source, context);
122+
123+
expect(parseSpy.callCount).to.equal(1);
124+
125+
parseSpy.restore();
126+
});
127+
107128
context('deprecation metadata', function () {
108129

109130
function jsdocTests(parseContext, lineEnding) {

0 commit comments

Comments
 (0)