@formatjs/intl-listformat 9.0.0 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +8 -2
  2. package/polyfill.iife.js +28 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-listformat",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "Formats JS list in a i18n-safe way",
5
5
  "keywords": [
6
6
  "format",
@@ -19,6 +19,12 @@
19
19
  "url": "git@github.com:formatjs/formatjs.git"
20
20
  },
21
21
  "type": "module",
22
+ "sideEffects": [
23
+ "./polyfill.js",
24
+ "./polyfill-force.js",
25
+ "./polyfill.iife.js",
26
+ "./locale-data/*.js"
27
+ ],
22
28
  "types": "index.d.ts",
23
29
  "exports": {
24
30
  ".": "./index.js",
@@ -29,6 +35,6 @@
29
35
  "./should-polyfill.js": "./should-polyfill.js"
30
36
  },
31
37
  "dependencies": {
32
- "@formatjs/intl-localematcher": "0.10.0"
38
+ "@formatjs/intl-localematcher": "0.10.1"
33
39
  }
34
40
  }
package/polyfill.iife.js CHANGED
@@ -2449,16 +2449,23 @@ function distance(desired, supported) {
2449
2449
  /** ICU language/script/region distance, including fractional explicit-subtag ties. */
2450
2450
  const findMatchingDistance = memoize((desired, supported) => distance(maximal(canonicalize(desired)), maximal(canonicalize(supported))), { serializer: (args) => `${args[0]}|${args[1]}` });
2451
2451
  const supportedCache = /* @__PURE__ */ new WeakMap();
2452
+ const immutableLocaleLists = /* @__PURE__ */ new WeakSet();
2452
2453
  let paradigms;
2454
+ function createLocaleListSnapshot(locales) {
2455
+ const snapshot = Object.freeze(Array.from(locales));
2456
+ immutableLocaleLists.add(snapshot);
2457
+ return snapshot;
2458
+ }
2453
2459
  function equivalentKey(lsr) {
2454
2460
  return `${lsr.language}|${lsr.script}|${lsr.region}`;
2455
2461
  }
2456
2462
  function prepare(locales) {
2463
+ const immutable = immutableLocaleLists.has(locales);
2457
2464
  let result = supportedCache.get(locales);
2458
- if (result && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
2465
+ if (result && !immutable && (result.original.length !== locales.length || result.original.some((tag, index) => tag !== locales[index]))) result = void 0;
2459
2466
  if (!result) {
2460
2467
  result = {
2461
- original: Array.from(locales),
2468
+ original: immutable ? locales : Array.from(locales),
2462
2469
  tags: [],
2463
2470
  raw: /* @__PURE__ */ new Map(),
2464
2471
  orders: /* @__PURE__ */ new Map(),
@@ -2964,22 +2971,28 @@ function UnicodeExtensionComponents(extension) {
2964
2971
  };
2965
2972
  }
2966
2973
  const availableLocaleArrays = /* @__PURE__ */ new WeakMap();
2967
- function localeArray(locales) {
2974
+ function localeArray(locales, bestFit) {
2968
2975
  if (Array.isArray(locales)) return locales;
2969
2976
  const available = locales;
2970
- const cached = availableLocaleArrays.get(available);
2971
- if (cached?.length === available.size) {
2977
+ let cached = availableLocaleArrays.get(available);
2978
+ if (cached?.original.length !== available.size) cached = void 0;
2979
+ if (cached) {
2980
+ const original = cached.original;
2972
2981
  let index = 0;
2973
- for (const locale of available) if (cached[index++] !== locale) {
2974
- const result = Array.from(available);
2975
- availableLocaleArrays.set(available, result);
2976
- return result;
2982
+ for (const locale of available) if (original[index++] !== locale) {
2983
+ cached = void 0;
2984
+ break;
2977
2985
  }
2978
- return cached;
2979
2986
  }
2980
- const result = Array.from(available);
2981
- availableLocaleArrays.set(available, result);
2982
- return result;
2987
+ if (!cached) {
2988
+ cached = {
2989
+ original: Array.from(available),
2990
+ snapshot: void 0
2991
+ };
2992
+ availableLocaleArrays.set(available, cached);
2993
+ }
2994
+ if (!bestFit) return cached.original;
2995
+ return cached.snapshot ??= createLocaleListSnapshot(cached.original);
2983
2996
  }
2984
2997
  /**
2985
2998
  * https://tc39.es/ecma402/#sec-resolvelocale
@@ -2987,8 +3000,8 @@ function localeArray(locales) {
2987
3000
  function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
2988
3001
  const matcher = options.localeMatcher;
2989
3002
  let r;
2990
- if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
2991
- else r = BestFitMatcher(localeArray(availableLocales), requestedLocales, getDefaultLocale);
3003
+ if (matcher === "lookup") r = LookupMatcher(localeArray(availableLocales, false), requestedLocales, getDefaultLocale);
3004
+ else r = BestFitMatcher(localeArray(availableLocales, true), requestedLocales, getDefaultLocale);
2992
3005
  if (r == null) r = {
2993
3006
  locale: getDefaultLocale(),
2994
3007
  extension: ""