@whiteslove/parsing-lexicon 0.9.5 → 0.9.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whiteslove/parsing-lexicon",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "Shared deterministic multilingual parsing lexicon for WhitesLove housing and hiring services",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,6 +49,18 @@ export function locationEntries(rows = []) {
49
49
  return Object.freeze(rows.map(([name, ...aliases]) => locationEntry(name, ...aliases)));
50
50
  }
51
51
 
52
+ // Copy an entry's data fields without touching its lazy `re` getter. Object
53
+ // spread invokes getters, which would compile every alias regex eagerly at
54
+ // merge time (tens of seconds at import) instead of on first match.
55
+ function entryData(entry) {
56
+ const data = {};
57
+ if (!entry) return data;
58
+ for (const key of Object.keys(entry)) {
59
+ if (key !== 're') data[key] = entry[key];
60
+ }
61
+ return data;
62
+ }
63
+
52
64
  function mergeEntry(existing, incoming) {
53
65
  const aliases = [...new Set([
54
66
  ...(existing?.aliases || []),
@@ -56,7 +68,7 @@ function mergeEntry(existing, incoming) {
56
68
  existing?.name,
57
69
  incoming?.name,
58
70
  ].filter(Boolean))];
59
- const base = { ...(existing || {}), ...(incoming || {}) };
71
+ const base = { ...entryData(existing), ...entryData(incoming) };
60
72
  // A map-data entry may enrich an existing reviewed owner with additional
61
73
  // aliases. It remains fallback-only only when every merged source is map
62
74
  // data; otherwise the reviewed owner must retain its matching precedence.