Skip to content

Commit

Permalink
[Fix] ExportMap: add caching after parsing for an ambiguous module
Browse files Browse the repository at this point in the history
  • Loading branch information
stenin-nikita committed Aug 24, 2022
1 parent 7cb6fcd commit 4ccce6f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions tests/files/typescript-declare-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "typescript-declare-module-foo" {
export const foo: string;
}
21 changes: 21 additions & 0 deletions tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4ccce6f

Please sign in to comment.