Skip to content

Commit 89c1573

Browse files
Fixed getLongestPrefix caching bug
1 parent 134f32c commit 89c1573

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/longest-prefix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function getLongestPrefix(
9999
const { includeAfter = false, onlyInside = false, looseGroups = false } = options;
100100

101101
const cache = cacheInstance.getLongestPrefix;
102-
const cacheKey = `${direction},${includeAfter},${looseGroups}`;
102+
const cacheKey = `${direction},${includeAfter},${onlyInside},${looseGroups}`;
103103
let weakCache = cache.get(cacheKey);
104104
if (weakCache === undefined) {
105105
weakCache = new WeakMap();

tests/longest-prefix.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ describe(RAA.getLongestPrefix.name, function () {
6565
for (const direction of ["ltr", "rtl"] as MatchingDirection[]) {
6666
for (const regex of regexes) {
6767
it(`${regex} ${direction}`, function () {
68-
const { pattern, flags } = new RegExpParser().parseLiteral(regex.toString());
68+
const parsed = new RegExpParser().parseLiteral(regex.toString());
69+
const { pattern } = parsed;
70+
const flags = RAA.toCache(parsed.flags);
6971

7072
const parent = selectNamedGroups(pattern, /^this$/)[0] ?? pattern;
7173
const alternatives: Alternative[] = [];

0 commit comments

Comments
 (0)