wuchale 0.24.1 → 0.24.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.
@@ -41,7 +41,7 @@ type VisitProps<NodeT, AddCtx> = VisitVolatileCtx<AddCtx> & {
41
41
  * e.g. components in jsx to prevent `[object Object]` being rendered. */
42
42
  useComponent?: boolean;
43
43
  };
44
- export declare class MixedVisitor<MixNodeT, AddCtx extends object, TxtT extends MixNodeT, ComT extends MixNodeT, ExprT extends MixNodeT> {
44
+ export declare class MixedVisitor<MixNodeT extends object, AddCtx extends object, TxtT extends MixNodeT, ComT extends MixNodeT, ExprT extends MixNodeT> {
45
45
  #private;
46
46
  constructor(props: InitProps<MixNodeT, AddCtx, TxtT, ComT, ExprT>);
47
47
  separatelyVisitChildren: (props: VisitProps<MixNodeT, AddCtx>) => Message[];
@@ -13,6 +13,7 @@ const noopMstr = new Proxy(new MagicString(''), {
13
13
  });
14
14
  export class MixedVisitor {
15
15
  #props;
16
+ #scouted = new WeakMap();
16
17
  constructor(props) {
17
18
  this.#props = props;
18
19
  }
@@ -208,7 +209,16 @@ export class MixedVisitor {
208
209
  if (props.children.length === 0) {
209
210
  return [];
210
211
  }
211
- if (!this.visitNested(props, { mstr: noopMstr, index: noopIndex, addCtx: { ...props.addCtx } }, false)) {
212
+ const scouKey = props.children[0];
213
+ const scoutedBoth = this.#scouted.get(scouKey) ?? [null, null];
214
+ const scouKeyI = props.commentDirectives.unit ? 1 : 0;
215
+ let scouted = scoutedBoth[scouKeyI];
216
+ if (scouted == null) {
217
+ scouted = this.visitNested(props, { mstr: noopMstr, index: noopIndex, addCtx: { ...props.addCtx } }, false);
218
+ scoutedBoth[scouKeyI] = scouted;
219
+ this.#scouted.set(scouKey, scoutedBoth);
220
+ }
221
+ if (!scouted) {
212
222
  return this.separatelyVisitChildren(props);
213
223
  }
214
224
  return this.visitNested(props, { mstr: props.mstr, index: props.index, addCtx: props.addCtx }, true); // really modify
package/dist/ai/index.js CHANGED
@@ -156,20 +156,23 @@ export default class AIQueue {
156
156
  };
157
157
  groupItemsByLocales = (items) => {
158
158
  const itemsByLocales = new Map();
159
+ const group = this.ai.group[this.sourceLocale];
160
+ const groups = new Set();
159
161
  for (const item of items) {
162
+ groups.clear();
160
163
  for (const [loc, transl] of item.translations.entries()) {
161
164
  if (loc === this.sourceLocale || transl[0]) {
162
165
  continue;
163
166
  }
164
- const group = this.ai.group[this.sourceLocale]?.find(g => g.includes(loc));
165
- const groupKey = group ?? loc;
166
- const groupItems = itemsByLocales.get(groupKey);
167
+ groups.add(group?.find(g => g.includes(loc)) ?? loc);
168
+ }
169
+ for (const groupKey of groups) {
170
+ let groupItems = itemsByLocales.get(groupKey);
167
171
  if (groupItems == null) {
168
- itemsByLocales.set(groupKey, [item]);
169
- }
170
- else {
171
- groupItems.push(item);
172
+ groupItems = [];
173
+ itemsByLocales.set(groupKey, groupItems);
172
174
  }
175
+ groupItems.push(item);
173
176
  }
174
177
  }
175
178
  return itemsByLocales;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -85,7 +85,7 @@
85
85
  "license": "MIT",
86
86
  "dependencies": {
87
87
  "@sveltejs/acorn-typescript": "^1.0.10",
88
- "acorn": "^8.16.0",
88
+ "acorn": "^8.17.0",
89
89
  "chokidar": "^5.0.0",
90
90
  "magic-string": "^0.30.21",
91
91
  "picomatch": "^4.0.4",
@@ -93,7 +93,7 @@
93
93
  "tinyglobby": "^0.2.17"
94
94
  },
95
95
  "devDependencies": {
96
- "@types/node": "~24.13.1",
96
+ "@types/node": "~24.13.2",
97
97
  "@types/picomatch": "^4.0.3",
98
98
  "typescript": "^6.0.3"
99
99
  },