From 1b4ed755fe605f04adea60c91366a9bc69bb32f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=E1=BB=B3nh=20Tr=E1=BA=A7n=20Khanh?= Date: Sat, 9 Mar 2024 15:14:34 +0000 Subject: [PATCH] Fix PairMap --- compiler/PairMap.test.js | 5 +++-- compiler/PairMap.ts | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/PairMap.test.js b/compiler/PairMap.test.js index 48084af..35dc90b 100644 --- a/compiler/PairMap.test.js +++ b/compiler/PairMap.test.js @@ -25,8 +25,9 @@ describe('PairMap', () => { test('set method works for different types of keys', () => { pairMap.set([1, 'a'], 'value') expect(pairMap.get([1, 'a'])).toBe('value') - pairMap.set(['x', { key: 'b' }], 'anotherValue') - expect(pairMap.get(['x', { key: 'b' }])).toBe('anotherValue') + const key = { key: 'b' } + pairMap.set(['x', key], 'anotherValue') + expect(pairMap.get(['x', key])).toBe('anotherValue') }) test('get method returns undefined for non-existing keys', () => { diff --git a/compiler/PairMap.ts b/compiler/PairMap.ts index a797405..8fcefc6 100644 --- a/compiler/PairMap.ts +++ b/compiler/PairMap.ts @@ -6,9 +6,9 @@ function createCounter() { } export class PairMap { - private leftKeyMap = new WeakMap() - private rightKeyMap = new WeakMap() - private valueMap = new WeakMap() + private leftKeyMap = new Map() + private rightKeyMap = new Map() + private valueMap = new Map() private getNextCounter: () => number constructor() { @@ -16,7 +16,7 @@ export class PairMap { } private getOrCreateCounterForKey( - map: WeakMap, + map: Map, key: T ): number { if (!map.has(key)) {