Skip to content

Commit fb1c9cd

Browse files
committed
fix(compat-eslint): only cache the last estree AST
close #81
1 parent 69bc86c commit fb1c9cd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/compat-eslint/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import type * as TSSLint from '@tsslint/types';
22
import type * as ESLint from 'eslint';
33
import type * as ts from 'typescript';
44

5-
const estrees = new WeakMap<ts.SourceFile, {
6-
estree: ESLint.AST.Program;
7-
sourceCode: ESLint.SourceCode;
8-
eventQueue: any[];
9-
}>();
5+
let cachedEstree: [sourceFile: ts.SourceFile, sourceCode: ESLint.SourceCode, eventQueue: any[]] | undefined;
106

117
export function convertRule(
128
eslintRule: ESLint.Rule.RuleModule,
@@ -381,7 +377,7 @@ function getEstree(
381377
file: ts.SourceFile,
382378
getProgram: () => ts.Program,
383379
) {
384-
if (!estrees.has(file)) {
380+
if (cachedEstree?.[0] !== file) {
385381
let program: ts.Program | undefined;
386382
let SourceCode;
387383

@@ -422,7 +418,10 @@ function getEstree(
422418
},
423419
});
424420
const eventQueue = sourceCode.traverse();
425-
estrees.set(file, { estree: ast, sourceCode, eventQueue });
421+
cachedEstree = [file, sourceCode, eventQueue];
426422
}
427-
return estrees.get(file)!;
423+
return {
424+
sourceCode: cachedEstree[1],
425+
eventQueue: cachedEstree[2],
426+
};
428427
}

0 commit comments

Comments
 (0)