Skip to content

Commit

Permalink
Switch from WeakMap to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Jul 23, 2021
1 parent 73a20fe commit e94eb08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions fluent-bundle/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FluentResource } from "./resource.js";
import { FluentValue, FluentNone, FluentFunction } from "./types.js";
import { Message, Term, Pattern } from "./ast.js";
import { NUMBER, DATETIME } from "./builtins.js";
import { getMemoizerForLocale } from "./memoizer.js";
import { getMemoizerForLocale, IntlCache } from "./memoizer.js";

export type TextTransform = (text: string) => string;

Expand All @@ -23,12 +23,7 @@ export class FluentBundle {
public _functions: Record<string, FluentFunction>;
public _useIsolating: boolean;
public _transform: TextTransform;
public _intls = new WeakMap<
| typeof Intl.NumberFormat
| typeof Intl.DateTimeFormat
| typeof Intl.PluralRules,
Record<string, Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules>
>();
public _intls: IntlCache;

/**
* Create an instance of `FluentBundle`.
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/src/memoizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type IntlCache = WeakMap<
export type IntlCache = Map<
| typeof Intl.NumberFormat
| typeof Intl.DateTimeFormat
| typeof Intl.PluralRules,
Expand All @@ -11,7 +11,7 @@ export function getMemoizerForLocale(locales: string | string[]): IntlCache {
const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales;
let memoizer = cache.get(stringLocale);
if (memoizer === undefined) {
memoizer = new WeakMap();
memoizer = new Map();
cache.set(stringLocale, memoizer);
}

Expand Down

0 comments on commit e94eb08

Please sign in to comment.