Skip to content

Commit 72824c7

Browse files
stenin-nikitaljharb
authored andcommitted
[Performance] ExportMap: add caching after parsing for an ambiguous module
1 parent 7cb6fcd commit 72824c7

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2727
- [Docs] remove global install in readme ([#2412], thanks [@aladdin-add])
2828
- [readme] clarify `eslint-import-resolver-typescript` usage ([#2503], thanks [@JounQin])
2929
- [Refactor] `no-cycle`: Add per-run caching of traversed paths ([#2419], thanks [@nokel81])
30+
- [Performance] `ExportMap`: add caching after parsing for an ambiguous module ([#2531], thanks [@stenin-nikita])
3031

3132
## [2.26.0] - 2022-04-05
3233

@@ -999,6 +1000,7 @@ for info on changes for earlier releases.
9991000

10001001
[`memo-parser`]: ./memo-parser/README.md
10011002

1003+
[#2531]: https://github.com/import-js/eslint-plugin-import/pull/2531
10021004
[#2506]: https://github.com/import-js/eslint-plugin-import/pull/2506
10031005
[#2503]: https://github.com/import-js/eslint-plugin-import/pull/2503
10041006
[#2490]: https://github.com/import-js/eslint-plugin-import/pull/2490
@@ -1701,6 +1703,7 @@ for info on changes for earlier releases.
17011703
[@spalger]: https://github.com/spalger
17021704
[@st-sloth]: https://github.com/st-sloth
17031705
[@stekycz]: https://github.com/stekycz
1706+
[@stenin-nikita]: https://github.com/stenin-nikita
17041707
[@stephtr]: https://github.com/stephtr
17051708
[@straub]: https://github.com/straub
17061709
[@strawbrary]: https://github.com/strawbrary

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)