UNPKG

@fluent/bundle

Version:

Localization library for expressive translations.

42 lines (41 loc) 1.31 kB
export class Scope { constructor(bundle, errors, args) { /** * The Set of patterns already encountered during this resolution. * Used to detect and prevent cyclic resolutions. * @ignore */ this.dirty = new WeakSet(); /** A dict of parameters passed to a TermReference. */ this.params = null; /** * The running count of placeables resolved so far. * Used to detect the Billion Laughs and Quadratic Blowup attacks. * @ignore */ this.placeables = 0; this.bundle = bundle; this.errors = errors; this.args = args; } reportError(error) { if (!this.errors || !(error instanceof Error)) { throw error; } this.errors.push(error); } memoizeIntlObject(ctor, opts) { let cache = this.bundle._intls.get(ctor); if (!cache) { cache = {}; this.bundle._intls.set(ctor, cache); } let id = JSON.stringify(opts); if (!cache[id]) { // @ts-expect-error This is fine. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment cache[id] = new ctor(this.bundle.locales, opts); } return cache[id]; } }