i18next-cli 1.74.2 → 1.74.3

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.
@@ -366,22 +366,21 @@ function isSimpleTemplateLiteral(literal) {
366
366
  * @private
367
367
  */
368
368
  function getObjectPropValue(object, propName, identifierResolver, expressionResolver) {
369
- const prop = getObjectProperty(object, propName);
370
- if (prop?.type === 'KeyValueProperty') {
371
- const val = unwrapParens(prop.value);
372
- if (val.type === 'StringLiteral')
373
- return val.value;
374
- if (val.type === 'Identifier' && identifierResolver)
375
- return identifierResolver(val.value);
376
- if (val.type === 'TemplateLiteral' && isSimpleTemplateLiteral(val))
377
- return val.quasis[0].cooked;
378
- if (val.type === 'BooleanLiteral')
379
- return val.value;
380
- if (val.type === 'NumericLiteral')
381
- return val.value;
382
- return expressionResolver?.(val) ?? ''; // Indicate presence for other types
383
- }
384
- return undefined;
369
+ // Shorthand `{ ns }` resolves like `{ ns: ns }`
370
+ const val = getObjectPropValueExpression(object, propName);
371
+ if (!val)
372
+ return undefined;
373
+ if (val.type === 'StringLiteral')
374
+ return val.value;
375
+ if (val.type === 'Identifier' && identifierResolver)
376
+ return identifierResolver(val.value);
377
+ if (val.type === 'TemplateLiteral' && isSimpleTemplateLiteral(val))
378
+ return val.quasis[0].cooked;
379
+ if (val.type === 'BooleanLiteral')
380
+ return val.value;
381
+ if (val.type === 'NumericLiteral')
382
+ return val.value;
383
+ return expressionResolver?.(val) ?? ''; // Indicate presence for other types
385
384
  }
386
385
 
387
386
  export { buildByteToCharMap, collectIgnoredLineRanges, convertSpansToCharIndices, findFirstTokenIndex, getObjectPropValue, getObjectPropValueExpression, getObjectProperty, isSimpleTemplateLiteral, lineColumnFromOffset, normalizeASTSpans, normalizeSpansToCharIndices, unwrapParens };
@@ -1,5 +1,39 @@
1
1
  import { unwrapParens } from './ast-utils.js';
2
2
 
3
+ // Whether `next` holds everything `prev` does: every value of a list, every
4
+ // member of a map (recursively), or the same primitive.
5
+ const covers = (next, prev) => {
6
+ if (Array.isArray(prev)) {
7
+ const has = new Set(Array.isArray(next) ? next : []);
8
+ return prev.every(v => has.has(v));
9
+ }
10
+ if (prev && typeof prev === 'object') {
11
+ return !!next && typeof next === 'object' && Object.keys(prev).every(k => covers(next[k], prev[k]));
12
+ }
13
+ return next === prev;
14
+ };
15
+ // Whether replacing `prev` by `next` only adds to it.
16
+ const grows = (next, prev) => prev === undefined || (covers(next, prev) && !covers(prev, next));
17
+ // The parts of return expressions that still resolve without the file's local
18
+ // bindings: members of enums / objects (`Kind.A`) and calls of other functions.
19
+ function crossFileRefs(exprs) {
20
+ const refs = [];
21
+ const add = (e) => {
22
+ e = unwrapParens(e);
23
+ if (e?.type === 'ConditionalExpression') {
24
+ add(e.consequent);
25
+ add(e.alternate);
26
+ }
27
+ else if (e?.type === 'MemberExpression' && e.object?.type === 'Identifier') {
28
+ refs.push(e);
29
+ }
30
+ else if (e?.type === 'CallExpression' && e.callee?.type === 'Identifier') {
31
+ refs.push({ type: 'CallExpression', callee: e.callee, arguments: [] });
32
+ }
33
+ };
34
+ exprs.forEach(add);
35
+ return refs;
36
+ }
3
37
  class ExpressionResolver {
4
38
  hooks;
5
39
  // Per-file symbol table for statically analyzable variables.
@@ -44,6 +78,22 @@ class ExpressionResolver {
44
78
  // Every other table is keyed by the *declared* name, so without this a type
45
79
  // referenced through an alias resolves to nothing.
46
80
  sharedImportAliases = new Map();
81
+ // Type parameters of generic object types, e.g. `type Base<T> = { type: T }`.
82
+ objectTypeParams = new Map();
83
+ // Values bound to type parameters while a generic type is being resolved.
84
+ typeParamBindings = new Map();
85
+ // Shared (cross-file) member maps of functions returning an object type,
86
+ // e.g. `const getAnimal = (): Animal => …` -> { getAnimal: { type: ['DUCK', 'DOG'] } }
87
+ sharedFunctionReturnMembers = new Map();
88
+ // Per-file identifiers holding an object type, from their annotation or from the
89
+ // function they were initialised by: `const animal = getAnimal()` -> { animal: { type: [...] } }
90
+ objectVariables = new Map();
91
+ // Set while the pre-scan runs. Captures that read other declarations queue a
92
+ // replay here, because what they read may be declared in a file scanned later.
93
+ recording = false;
94
+ replays = [];
95
+ replaying = false;
96
+ grew = false;
47
97
  constructor(hooks) {
48
98
  this.hooks = hooks;
49
99
  }
@@ -55,6 +105,45 @@ class ExpressionResolver {
55
105
  this.typeAliasTable.clear();
56
106
  this.temporaryVariables.clear();
57
107
  this.arrayElementMembers.clear();
108
+ this.objectVariables.clear();
109
+ }
110
+ /**
111
+ * Call once every file has been pre-scanned. Captures ran in file order, so one
112
+ * that refers to a declaration in a later file (`type Kind = Base | 'extra'`
113
+ * with `Base` declared further down the list) came out short. They are replayed
114
+ * against the complete tables until nothing grows, then renaming imports are
115
+ * mirrored.
116
+ */
117
+ finishPreScan() {
118
+ this.resetFileSymbols();
119
+ // ponytail: each round fixes one more link of a chain declared against file order; 10 is plenty
120
+ for (let round = 0; round < 10; round++) {
121
+ this.applyImportAliases();
122
+ this.grew = false;
123
+ this.replaying = true;
124
+ for (const replay of this.replays)
125
+ replay();
126
+ this.replaying = false;
127
+ if (!this.grew)
128
+ break;
129
+ }
130
+ this.applyImportAliases();
131
+ this.replays = [];
132
+ this.resetFileSymbols();
133
+ }
134
+ /**
135
+ * Write an entry of a cross-file table. While replaying, an entry only grows:
136
+ * a replayed declaration has lost its file's local bindings and must not shrink
137
+ * what the pre-scan resolved, and two same-named declarations in different files
138
+ * must not keep overwriting each other.
139
+ */
140
+ setShared(table, name, value) {
141
+ if (this.replaying) {
142
+ if (!grows(value, table.get(name)))
143
+ return;
144
+ this.grew = true;
145
+ }
146
+ table.set(name, value);
58
147
  }
59
148
  /**
60
149
  * Capture a VariableDeclarator node to record simple statically analyzable
@@ -105,11 +194,11 @@ class ExpressionResolver {
105
194
  }
106
195
  return;
107
196
  }
108
- // ── ObjectPattern id: `const { unit } = rate` ───────────────────────────
197
+ // ── ObjectPattern id: `const { unit } = rate` / `const { type } = getAnimal()`
109
198
  // Bind each destructured local to the source object's property values.
110
- if (node.id.type === 'ObjectPattern' && node.init?.type === 'Identifier') {
111
- const map = this.getObjectMap(node.init.value);
112
- const objMembers = this.temporaryObjectVariables.get(node.init.value);
199
+ if (node.id.type === 'ObjectPattern' && node.init) {
200
+ const map = node.init.type === 'Identifier' ? this.getObjectMap(node.init.value) : undefined;
201
+ const objMembers = this.objectMembersOf(node.init);
113
202
  if (!map && !objMembers)
114
203
  return;
115
204
  for (const prop of (node.id.properties ?? [])) {
@@ -138,6 +227,12 @@ class ExpressionResolver {
138
227
  if (elementMembers)
139
228
  this.arrayElementMembers.set(name, elementMembers);
140
229
  }
230
+ // `const animal: Animal = …` / `const animal = getAnimal()` → `animal.type`
231
+ // resolves to the member's values.
232
+ const objMembers = (idTypeAnnotation && this.resolveTypeMembers(idTypeAnnotation)) ||
233
+ (node.init && this.objectMembersOf(node.init));
234
+ if (objMembers)
235
+ this.objectVariables.set(name, objMembers);
141
236
  // pattern 1:
142
237
  // Handle `declare const x: 'a' | 'b'` and `declare const x: SomeUnion`
143
238
  // where there is no initializer but a TypeScript type annotation.
@@ -250,25 +345,9 @@ class ExpressionResolver {
250
345
  this.variableTable.set(name, vals);
251
346
  return;
252
347
  }
253
- // pattern 3 (arrow function variant):
254
- // `const fn = (): 'a' | 'b' => ...` — capture the explicit return type annotation,
255
- // OR fall back to walking the body's return expressions / expression body
256
- // when no annotation is present (mirrors TS's own return-type inference).
348
+ // pattern 3 (arrow function variant): `const fn = (): 'a' | 'b' => ...`
257
349
  if (unwrappedInit.type === 'ArrowFunctionExpression' || unwrappedInit.type === 'FunctionExpression') {
258
- let returnVals = [];
259
- const rawReturnType = unwrappedInit.returnType ?? unwrappedInit.typeAnnotation;
260
- if (rawReturnType) {
261
- // Explicit annotation — trust it even when it resolves to [].
262
- const tsType = rawReturnType.typeAnnotation ?? rawReturnType;
263
- returnVals = this.resolvePossibleStringValuesFromType(tsType);
264
- }
265
- else {
266
- returnVals = this.inferReturnValuesFromFunctionBody(unwrappedInit);
267
- }
268
- if (returnVals.length > 0) {
269
- this.variableTable.set(name, returnVals);
270
- this.sharedFunctionReturnTable.set(name, returnVals);
271
- }
350
+ this.captureFunctionReturn(name, unwrappedInit);
272
351
  }
273
352
  }
274
353
  catch {
@@ -292,20 +371,30 @@ class ExpressionResolver {
292
371
  const tsType = node.typeAnnotation ?? node.typeAnn;
293
372
  if (!tsType)
294
373
  return;
374
+ if (this.recording)
375
+ this.replays.push(() => this.captureTypeAliasDeclaration(node));
376
+ const params = node.typeParams?.parameters;
295
377
  // `type IProps = { size: ChangeType }` — object shape, not a string union.
296
378
  if (tsType.type === 'TsTypeLiteral') {
297
- this.objectTypeMembersRaw.set(name, tsType.members);
298
- const members = this.collectObjectTypeMembers(tsType.members);
379
+ if (!this.replaying)
380
+ this.setObjectTypeRaw(name, tsType.members, params);
381
+ const members = this.withTypeParams(params, undefined, () => this.collectObjectTypeMembers(tsType.members));
299
382
  if (members)
300
- this.objectTypeTable.set(name, members);
383
+ this.setShared(this.objectTypeTable, name, members);
301
384
  return;
302
385
  }
303
- const vals = this.resolvePossibleStringValuesFromType(tsType);
386
+ const vals = this.withTypeParams(params, undefined, () => this.resolvePossibleStringValuesFromType(tsType));
304
387
  if (vals.length > 0) {
305
- this.typeAliasTable.set(name, vals);
388
+ if (!this.replaying)
389
+ this.typeAliasTable.set(name, vals);
306
390
  // Also share so importing files can resolve this alias by name
307
- this.sharedTypeAliasTable.set(name, vals);
391
+ this.setShared(this.sharedTypeAliasTable, name, vals);
392
+ return;
308
393
  }
394
+ // `type Animal = Duck | Dog`, `type Duck = Base<'DUCK'> & { fly: true }`
395
+ const members = this.withTypeParams(params, undefined, () => this.resolveTypeMembers(tsType));
396
+ if (members)
397
+ this.setShared(this.objectTypeTable, name, members);
309
398
  }
310
399
  catch {
311
400
  // noop
@@ -347,12 +436,15 @@ class ExpressionResolver {
347
436
  this.sharedEnumTable,
348
437
  this.sharedVariableTable,
349
438
  this.sharedFunctionReturnTable,
439
+ this.sharedFunctionReturnMembers,
350
440
  this.objectTypeTable,
351
441
  this.objectTypeMembersRaw,
442
+ this.objectTypeParams,
352
443
  ];
353
444
  for (const [local, declared] of this.sharedImportAliases) {
354
445
  for (const table of tables) {
355
- if (table.has(declared) && !table.has(local))
446
+ // A replayed declaration may have grown since it was last mirrored
447
+ if (table.has(declared) && grows(table.get(declared), table.get(local)))
356
448
  table.set(local, table.get(declared));
357
449
  }
358
450
  }
@@ -369,16 +461,62 @@ class ExpressionResolver {
369
461
  const name = node?.id?.type === 'Identifier' ? node.id.value : undefined;
370
462
  if (!name)
371
463
  return;
372
- if (Array.isArray(node?.body?.body))
373
- this.objectTypeMembersRaw.set(name, node.body.body);
374
- const members = this.collectObjectTypeMembers(node?.body?.body);
464
+ if (this.recording)
465
+ this.replays.push(() => this.captureInterfaceDeclaration(node));
466
+ const params = node.typeParams?.parameters;
467
+ if (!this.replaying && Array.isArray(node?.body?.body))
468
+ this.setObjectTypeRaw(name, node.body.body, params);
469
+ const members = this.withTypeParams(params, undefined, () => this.collectObjectTypeMembers(node?.body?.body));
375
470
  if (members)
376
- this.objectTypeTable.set(name, members);
471
+ this.setShared(this.objectTypeTable, name, members);
377
472
  }
378
473
  catch {
379
474
  // noop
380
475
  }
381
476
  }
477
+ setObjectTypeRaw(name, members, params) {
478
+ this.objectTypeMembersRaw.set(name, members);
479
+ if (params?.length)
480
+ this.objectTypeParams.set(name, params);
481
+ else
482
+ this.objectTypeParams.delete(name);
483
+ }
484
+ /**
485
+ * Run `fn` with the parameters of a generic type bound to the values of their
486
+ * arguments, falling back to each one's default and then its constraint, so
487
+ * that `type Base<T extends Kind> = { type: T }` used bare has `type: Kind`.
488
+ */
489
+ withTypeParams(params, args, fn) {
490
+ if (!params?.length)
491
+ return fn();
492
+ const values = params.map((p, i) => {
493
+ const arg = args?.[i] ?? p.default ?? p.constraint;
494
+ return arg ? this.resolvePossibleStringValuesFromType(arg) : [];
495
+ });
496
+ const saved = this.typeParamBindings;
497
+ this.typeParamBindings = new Map(saved);
498
+ params.forEach((p, i) => { if (p.name?.value)
499
+ this.typeParamBindings.set(p.name.value, values[i]); });
500
+ try {
501
+ return fn();
502
+ }
503
+ finally {
504
+ this.typeParamBindings = saved;
505
+ }
506
+ }
507
+ /**
508
+ * The member map of an object held by `expr`: a parameter typed by an interface
509
+ * (`props`), a variable holding an object type (`animal`) or a call of a
510
+ * function returning one (`getAnimal()`).
511
+ */
512
+ objectMembersOf(expr) {
513
+ expr = unwrapParens(expr);
514
+ if (expr?.type === 'Identifier')
515
+ return this.temporaryObjectVariables.get(expr.value) ?? this.objectVariables.get(expr.value);
516
+ if (expr?.type === 'CallExpression' && expr.callee?.type === 'Identifier')
517
+ return this.sharedFunctionReturnMembers.get(expr.callee.value);
518
+ return undefined;
519
+ }
382
520
  /**
383
521
  * Build `{ memberName: possibleStringValues }` for an object-shaped type
384
522
  * (interface body or object type-literal members). Only members whose type
@@ -414,11 +552,31 @@ class ExpressionResolver {
414
552
  try {
415
553
  if (!tsType)
416
554
  return undefined;
555
+ if (tsType.type === 'TsParenthesizedType')
556
+ return this.resolveTypeMembers(tsType.typeAnnotation);
417
557
  if (tsType.type === 'TsTypeLiteral') {
418
558
  return this.collectObjectTypeMembers(tsType.members);
419
559
  }
560
+ // `Duck | Dog`, `Base<'DUCK'> & { fly: true }` → every member with the values
561
+ // it has in any of the parts (`animal.type` → 'DUCK' | 'DOG')
562
+ if (tsType.type === 'TsUnionType' || tsType.type === 'TsIntersectionType') {
563
+ const merged = {};
564
+ for (const part of tsType.types) {
565
+ for (const [member, vals] of Object.entries(this.resolveTypeMembers(part) ?? {})) {
566
+ merged[member] = [...new Set([...(merged[member] ?? []), ...vals])];
567
+ }
568
+ }
569
+ return Object.keys(merged).length > 0 ? merged : undefined;
570
+ }
420
571
  if (tsType.type === 'TsTypeReference' && tsType.typeName?.type === 'Identifier') {
421
- return this.objectTypeTable.get(tsType.typeName.value);
572
+ const name = tsType.typeName.value;
573
+ // `Base<'DUCK'>` → instantiate the generic type's members with the argument
574
+ const args = tsType.typeParams?.params;
575
+ const params = this.objectTypeParams.get(name);
576
+ if (args?.length && params) {
577
+ return this.withTypeParams(params, args, () => this.collectObjectTypeMembers(this.objectTypeMembersRaw.get(name) ?? []));
578
+ }
579
+ return this.objectTypeTable.get(name);
422
580
  }
423
581
  }
424
582
  catch { }
@@ -487,46 +645,64 @@ class ExpressionResolver {
487
645
  return;
488
646
  // SWC places the return type annotation in `.function.returnType` (FunctionDeclaration)
489
647
  // or directly in `.returnType` (FunctionExpression / ArrowFunctionExpression).
490
- const fn = node.function ?? node;
491
- const rawReturnType = fn.returnType ?? fn.typeAnnotation;
492
- let vals = [];
493
- if (rawReturnType) {
494
- // Unwrap TsTypeAnnotation wrapper if present. Explicit annotations are
495
- // authoritative: if the author declared the return type we trust it,
496
- // even when it resolves to [] (e.g. plain `string`). Falling back to
497
- // body inference in that case would invent keys the author deliberately
498
- // opted out of.
499
- const tsType = rawReturnType.typeAnnotation ?? rawReturnType;
500
- vals = this.resolvePossibleStringValuesFromType(tsType);
501
- }
502
- else {
503
- // No annotation — infer from body. Mirrors TS's own return-type
504
- // inference for functions like:
505
- // function getCurrentAppType() {
506
- // if (...) return OrganizationType.ROUTING;
507
- // if (...) return OrganizationType.CONTRACTOR;
508
- // }
509
- vals = this.inferReturnValuesFromFunctionBody(fn);
510
- }
511
- if (vals.length > 0) {
512
- this.variableTable.set(name, vals);
513
- this.sharedFunctionReturnTable.set(name, vals);
514
- }
648
+ this.captureFunctionReturn(name, node.function ?? node);
515
649
  }
516
650
  catch {
517
651
  // noop
518
652
  }
519
653
  }
520
654
  /**
521
- * Walk a function body's ReturnStatements and union the statically-resolvable
522
- * string values of their argument expressions. Does NOT descend into nested
523
- * function declarations (their returns belong to the inner function, not us).
655
+ * Record what a function returns: string values for `t(fn())`, and the members
656
+ * of an object return type for `fn().type` / `const x = fn(); x.type`.
657
+ */
658
+ captureFunctionReturn(name, fn) {
659
+ const rawReturnType = fn.returnType ?? fn.typeAnnotation;
660
+ // Unwrap TsTypeAnnotation wrapper if present. Explicit annotations are
661
+ // authoritative: if the author declared the return type we trust it,
662
+ // even when it resolves to [] (e.g. plain `string`). Falling back to
663
+ // body inference in that case would invent keys the author deliberately
664
+ // opted out of.
665
+ const returnType = rawReturnType?.typeAnnotation ?? rawReturnType;
666
+ // No annotation: infer from body. Mirrors TS's own return-type
667
+ // inference for functions like:
668
+ // function getCurrentAppType() {
669
+ // if (...) return OrganizationType.ROUTING;
670
+ // if (...) return OrganizationType.CONTRACTOR;
671
+ // }
672
+ const exprs = returnType ? [] : this.returnExpressions(fn);
673
+ const vals = returnType
674
+ ? this.resolvePossibleStringValuesFromType(returnType)
675
+ : [...new Set(exprs.flatMap(e => this.resolvePossibleStringValuesFromExpression(e)))];
676
+ if (vals.length > 0)
677
+ this.variableTable.set(name, vals);
678
+ // A replay has lost the file's local bindings, so it re-resolves only the
679
+ // return type, or the returned enum / object members and calls of other
680
+ // functions, kept as small nodes so no function body stays in memory.
681
+ const refs = this.recording ? crossFileRefs(exprs) : [];
682
+ const store = () => {
683
+ const all = returnType
684
+ ? this.resolvePossibleStringValuesFromType(returnType)
685
+ : [...new Set([...vals, ...refs.flatMap(e => this.resolvePossibleStringValuesFromExpression(e))])];
686
+ if (all.length > 0)
687
+ this.setShared(this.sharedFunctionReturnTable, name, all);
688
+ const members = returnType && this.resolveTypeMembers(returnType);
689
+ if (members)
690
+ this.setShared(this.sharedFunctionReturnMembers, name, members);
691
+ };
692
+ store();
693
+ if (this.recording && (returnType || refs.length > 0))
694
+ this.replays.push(store);
695
+ }
696
+ /**
697
+ * Collect a function's return expressions (the expression body of an arrow
698
+ * function, or the arguments of its ReturnStatements). Does NOT descend into
699
+ * nested function declarations (their returns belong to the inner function, not us).
524
700
  *
525
701
  * This is how we mirror TypeScript's implicit return-type inference for the
526
702
  * purpose of extracting translation keys — we don't need exhaustiveness, just
527
703
  * the set of string values any return statement could produce.
528
704
  */
529
- inferReturnValuesFromFunctionBody(fn) {
705
+ returnExpressions(fn) {
530
706
  const body = fn?.body;
531
707
  if (!body)
532
708
  return [];
@@ -539,11 +715,8 @@ class ExpressionResolver {
539
715
  n.type === 'FunctionExpression' ||
540
716
  n.type === 'ArrowFunctionExpression'))
541
717
  return;
542
- if (n.type === 'ReturnStatement' && n.argument) {
543
- const vals = this.resolvePossibleStringValuesFromExpression(n.argument);
544
- if (vals.length > 0)
545
- collected.push(...vals);
546
- }
718
+ if (n.type === 'ReturnStatement' && n.argument)
719
+ collected.push(n.argument);
547
720
  for (const key of Object.keys(n)) {
548
721
  const child = n[key];
549
722
  if (Array.isArray(child)) {
@@ -560,14 +733,10 @@ class ExpressionResolver {
560
733
  // Arrow functions with an expression body (no block) — `() => expr` —
561
734
  // have their return expression directly as `body`. swc >=1.16 types function
562
735
  // bodies as 'FunctionBody'; older versions used 'BlockStatement'.
563
- if (body.type !== 'BlockStatement' && body.type !== 'FunctionBody') {
564
- const vals = this.resolvePossibleStringValuesFromExpression(body);
565
- if (vals.length > 0)
566
- return Array.from(new Set(vals));
567
- return [];
568
- }
736
+ if (body.type !== 'BlockStatement' && body.type !== 'FunctionBody')
737
+ return [body];
569
738
  visit(body);
570
- return Array.from(new Set(collected));
739
+ return collected;
571
740
  }
572
741
  /**
573
742
  * Extract a raw TsType node from an identifier's type annotation.
@@ -798,28 +967,22 @@ class ExpressionResolver {
798
967
  try {
799
968
  const obj = expression.object;
800
969
  const prop = expression.property;
970
+ const propName = prop.type === 'Identifier'
971
+ ? prop.value
972
+ : prop.type === 'Computed' && prop.expression?.type === 'StringLiteral'
973
+ ? prop.expression.value
974
+ : undefined;
975
+ // Object type held by a parameter (`props.size`), a variable (`animal.type`)
976
+ // or returned by a call (`getAnimal().type`)
977
+ const objMembers = this.objectMembersOf(obj);
978
+ if (propName && objMembers?.[propName])
979
+ return objMembers[propName];
801
980
  // only handle simple identifier base + simple property (Identifier or computed StringLiteral)
802
981
  if (obj.type === 'Identifier') {
803
- // Parameter typed by an interface / object type: `props.size`
804
- const objMembers = this.temporaryObjectVariables.get(obj.value);
805
- if (objMembers) {
806
- const propName = prop.type === 'Identifier'
807
- ? prop.value
808
- : prop.type === 'Computed' && prop.expression?.type === 'StringLiteral'
809
- ? prop.expression.value
810
- : undefined;
811
- if (propName && objMembers[propName])
812
- return objMembers[propName];
813
- }
814
982
  const baseVar = this.variableTable.get(obj.value);
815
983
  const baseShared = this.sharedEnumTable.get(obj.value);
816
984
  const base = baseVar ?? baseShared;
817
985
  if (base && typeof base !== 'string' && !Array.isArray(base)) {
818
- let propName;
819
- if (prop.type === 'Identifier')
820
- propName = prop.value;
821
- else if (prop.type === 'Computed' && prop.expression?.type === 'StringLiteral')
822
- propName = prop.expression.value;
823
986
  if (propName && base[propName] !== undefined) {
824
987
  return [base[propName]];
825
988
  }
@@ -836,6 +999,13 @@ class ExpressionResolver {
836
999
  return Object.values(base);
837
1000
  }
838
1001
  }
1002
+ // `COLORS[i]` → one of the array's elements
1003
+ if (prop.type === 'Computed') {
1004
+ const elements = this.sharedVariableTable.get(obj.value);
1005
+ const index = prop.expression;
1006
+ if (elements)
1007
+ return index.type === 'NumericLiteral' && elements[index.value] !== undefined ? [elements[index.value]] : elements;
1008
+ }
839
1009
  }
840
1010
  }
841
1011
  catch { }
@@ -970,6 +1140,10 @@ class ExpressionResolver {
970
1140
  ? type.typeName.value
971
1141
  : undefined;
972
1142
  if (typeName) {
1143
+ // Inside a generic type: the parameter's argument, default or constraint
1144
+ const bound = this.typeParamBindings.get(typeName);
1145
+ if (bound)
1146
+ return bound;
973
1147
  // 1. Check type alias table first (exact match for string-literal unions)
974
1148
  const aliasVals = this.typeAliasTable.get(typeName) ?? this.sharedTypeAliasTable.get(typeName);
975
1149
  if (aliasVals && aliasVals.length > 0)
@@ -1007,6 +1181,13 @@ class ExpressionResolver {
1007
1181
  const vals = this.getVariableValues(varName);
1008
1182
  if (vals && vals.length > 0)
1009
1183
  return vals;
1184
+ // `(typeof COLOR)[keyof typeof COLOR]` → the as-const object's (or enum's) values
1185
+ const map = this.getObjectMap(varName);
1186
+ if (map) {
1187
+ const keys = this.resolvePossibleStringValuesFromType(type.indexType);
1188
+ const picked = keys.map(k => map[k]).filter((v) => v !== undefined);
1189
+ return picked.length > 0 ? picked : Object.values(map);
1190
+ }
1010
1191
  }
1011
1192
  }
1012
1193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.74.2",
3
+ "version": "1.74.3",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAQ,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC7G,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAoBtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,KAAK,CAAiB;IAE9B,IAAW,UAAU,gBAEpB;IAED,SAAgB,YAAY,EAAE,YAAY,CAAA;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAuB;IAC7D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,WAAW,CAAa;IAEhC;;;;;;OAMG;gBAED,M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DxB;;;;;;;;;OASG;IACH,OAAO,CAAC,0BAA0B;IAgDlC;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;;;;;;;OAQG;IACI,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAI5D;;OAEG;IACI,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAKxD;;;;;;OAMG;IACI,cAAc,IAAK,MAAM;IAIhC;;OAEG;IACI,cAAc,IAAK,MAAM;CAGjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"key-finder.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/key-finder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAmB,MAAM,gBAAgB,CAAA;AAOjG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,GAAE,MAA4B,EACpC,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CA2F1E"}
1
+ {"version":3,"file":"key-finder.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/key-finder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAmB,MAAM,gBAAgB,CAAA;AAOjG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,GAAE,MAA4B,EACpC,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IA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