i18next-cli 1.71.0 → 1.71.1

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/dist/cjs/cli.js CHANGED
@@ -37,7 +37,7 @@ const program = new commander.Command();
37
37
  program
38
38
  .name('i18next-cli')
39
39
  .description('A unified, high-performance i18next CLI.')
40
- .version('1.71.0'); // This string is replaced with the actual version at build time by rollup
40
+ .version('1.71.1'); // This string is replaced with the actual version at build time by rollup
41
41
  // new: global config override option
42
42
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
43
43
  program
@@ -5,6 +5,21 @@ var expressionResolver = require('../parsers/expression-resolver.js');
5
5
  var callExpressionHandler = require('../parsers/call-expression-handler.js');
6
6
  var jsxHandler = require('../parsers/jsx-handler.js');
7
7
 
8
+ /**
9
+ * Array iteration methods whose callback we can bind, mapped to the position of
10
+ * the *element* parameter: `map(el, i)` → 0, `reduce((acc, el) => …)` → 1.
11
+ */
12
+ const ITERATION_METHODS = {
13
+ map: 0,
14
+ forEach: 0,
15
+ flatMap: 0,
16
+ filter: 0,
17
+ find: 0,
18
+ some: 0,
19
+ every: 0,
20
+ reduce: 1,
21
+ reduceRight: 1,
22
+ };
8
23
  /**
9
24
  * AST visitor class that traverses JavaScript/TypeScript syntax trees to extract translation keys.
10
25
  *
@@ -777,7 +792,8 @@ class ASTVisitors {
777
792
  const prop = callee.property;
778
793
  if (prop?.type !== 'Identifier')
779
794
  return undefined;
780
- if (!['map', 'forEach', 'flatMap', 'filter', 'find', 'some', 'every'].includes(prop.value))
795
+ const elementParamIndex = ITERATION_METHODS[prop.value];
796
+ if (elementParamIndex === undefined)
781
797
  return undefined;
782
798
  // The object must be an identifier whose value is a known string array
783
799
  const obj = callee.object;
@@ -785,7 +801,7 @@ class ASTVisitors {
785
801
  if (obj?.type === 'Identifier') {
786
802
  const values = this.expressionResolver.getVariableValues(obj.value);
787
803
  if (values && values.length > 0) {
788
- return this.extractCallbackParam(node, values);
804
+ return this.extractCallbackParam(node, values, elementParamIndex);
789
805
  }
790
806
  }
791
807
  // ── Case 2: Object.keys(MAP).map(k => ...) ────────────────────────────
@@ -807,7 +823,7 @@ class ASTVisitors {
807
823
  if (mapEntry) {
808
824
  const values = isKeys ? Object.keys(mapEntry) : Object.values(mapEntry);
809
825
  if (values.length > 0) {
810
- return this.extractCallbackParam(node, values);
826
+ return this.extractCallbackParam(node, values, elementParamIndex);
811
827
  }
812
828
  }
813
829
  }
@@ -837,7 +853,8 @@ class ASTVisitors {
837
853
  const prop = callee.property;
838
854
  if (prop?.type !== 'Identifier')
839
855
  return undefined;
840
- if (!['map', 'forEach', 'flatMap', 'filter', 'find', 'some', 'every'].includes(prop.value))
856
+ const elementParamIndex = ITERATION_METHODS[prop.value];
857
+ if (elementParamIndex === undefined)
841
858
  return undefined;
842
859
  if (callee.object?.type !== 'Identifier')
843
860
  return undefined;
@@ -846,7 +863,7 @@ class ASTVisitors {
846
863
  return undefined;
847
864
  const callbackArg = node.arguments?.[0]?.expression;
848
865
  const params = callbackArg?.params ?? callbackArg?.parameters ?? [];
849
- const firstParam = params[0];
866
+ const firstParam = params[elementParamIndex];
850
867
  if (!firstParam)
851
868
  return undefined;
852
869
  const pat = firstParam.pat ?? firstParam.pattern ?? firstParam;
@@ -880,15 +897,16 @@ class ASTVisitors {
880
897
  }
881
898
  }
882
899
  /**
883
- * Extracts the first callback parameter identifier from an iteration call node
884
- * and pairs it with the provided values array.
900
+ * Extracts the element callback parameter identifier from an iteration call node
901
+ * and pairs it with the provided values array. `paramIndex` is the position of
902
+ * the element parameter (0 for map/forEach/…, 1 for reduce's `(acc, el)`).
885
903
  */
886
- extractCallbackParam(node, values) {
904
+ extractCallbackParam(node, values, paramIndex = 0) {
887
905
  const callbackArg = node.arguments?.[0]?.expression;
888
906
  if (!callbackArg)
889
907
  return undefined;
890
908
  const params = callbackArg.params ?? callbackArg.parameters ?? [];
891
- const firstParam = params[0];
909
+ const firstParam = params[paramIndex];
892
910
  if (!firstParam)
893
911
  return undefined;
894
912
  const ident = firstParam.type === 'Identifier'
package/dist/esm/cli.js CHANGED
@@ -31,7 +31,7 @@ const program = new Command();
31
31
  program
32
32
  .name('i18next-cli')
33
33
  .description('A unified, high-performance i18next CLI.')
34
- .version('1.71.0'); // This string is replaced with the actual version at build time by rollup
34
+ .version('1.71.1'); // This string is replaced with the actual version at build time by rollup
35
35
  // new: global config override option
36
36
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
37
37
  program
@@ -3,6 +3,21 @@ import { ExpressionResolver } from '../parsers/expression-resolver.js';
3
3
  import { CallExpressionHandler } from '../parsers/call-expression-handler.js';
4
4
  import { JSXHandler } from '../parsers/jsx-handler.js';
5
5
 
6
+ /**
7
+ * Array iteration methods whose callback we can bind, mapped to the position of
8
+ * the *element* parameter: `map(el, i)` → 0, `reduce((acc, el) => …)` → 1.
9
+ */
10
+ const ITERATION_METHODS = {
11
+ map: 0,
12
+ forEach: 0,
13
+ flatMap: 0,
14
+ filter: 0,
15
+ find: 0,
16
+ some: 0,
17
+ every: 0,
18
+ reduce: 1,
19
+ reduceRight: 1,
20
+ };
6
21
  /**
7
22
  * AST visitor class that traverses JavaScript/TypeScript syntax trees to extract translation keys.
8
23
  *
@@ -775,7 +790,8 @@ class ASTVisitors {
775
790
  const prop = callee.property;
776
791
  if (prop?.type !== 'Identifier')
777
792
  return undefined;
778
- if (!['map', 'forEach', 'flatMap', 'filter', 'find', 'some', 'every'].includes(prop.value))
793
+ const elementParamIndex = ITERATION_METHODS[prop.value];
794
+ if (elementParamIndex === undefined)
779
795
  return undefined;
780
796
  // The object must be an identifier whose value is a known string array
781
797
  const obj = callee.object;
@@ -783,7 +799,7 @@ class ASTVisitors {
783
799
  if (obj?.type === 'Identifier') {
784
800
  const values = this.expressionResolver.getVariableValues(obj.value);
785
801
  if (values && values.length > 0) {
786
- return this.extractCallbackParam(node, values);
802
+ return this.extractCallbackParam(node, values, elementParamIndex);
787
803
  }
788
804
  }
789
805
  // ── Case 2: Object.keys(MAP).map(k => ...) ────────────────────────────
@@ -805,7 +821,7 @@ class ASTVisitors {
805
821
  if (mapEntry) {
806
822
  const values = isKeys ? Object.keys(mapEntry) : Object.values(mapEntry);
807
823
  if (values.length > 0) {
808
- return this.extractCallbackParam(node, values);
824
+ return this.extractCallbackParam(node, values, elementParamIndex);
809
825
  }
810
826
  }
811
827
  }
@@ -835,7 +851,8 @@ class ASTVisitors {
835
851
  const prop = callee.property;
836
852
  if (prop?.type !== 'Identifier')
837
853
  return undefined;
838
- if (!['map', 'forEach', 'flatMap', 'filter', 'find', 'some', 'every'].includes(prop.value))
854
+ const elementParamIndex = ITERATION_METHODS[prop.value];
855
+ if (elementParamIndex === undefined)
839
856
  return undefined;
840
857
  if (callee.object?.type !== 'Identifier')
841
858
  return undefined;
@@ -844,7 +861,7 @@ class ASTVisitors {
844
861
  return undefined;
845
862
  const callbackArg = node.arguments?.[0]?.expression;
846
863
  const params = callbackArg?.params ?? callbackArg?.parameters ?? [];
847
- const firstParam = params[0];
864
+ const firstParam = params[elementParamIndex];
848
865
  if (!firstParam)
849
866
  return undefined;
850
867
  const pat = firstParam.pat ?? firstParam.pattern ?? firstParam;
@@ -878,15 +895,16 @@ class ASTVisitors {
878
895
  }
879
896
  }
880
897
  /**
881
- * Extracts the first callback parameter identifier from an iteration call node
882
- * and pairs it with the provided values array.
898
+ * Extracts the element callback parameter identifier from an iteration call node
899
+ * and pairs it with the provided values array. `paramIndex` is the position of
900
+ * the element parameter (0 for map/forEach/…, 1 for reduce's `(acc, el)`).
883
901
  */
884
- extractCallbackParam(node, values) {
902
+ extractCallbackParam(node, values, paramIndex = 0) {
885
903
  const callbackArg = node.arguments?.[0]?.expression;
886
904
  if (!callbackArg)
887
905
  return undefined;
888
906
  const params = callbackArg.params ?? callbackArg.parameters ?? [];
889
- const firstParam = params[0];
907
+ const firstParam = params[paramIndex];
890
908
  if (!firstParam)
891
909
  return undefined;
892
910
  const ident = firstParam.type === 'Identifier'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.71.0",
3
+ "version": "1.71.1",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -59,8 +59,8 @@
59
59
  "@types/node": "^26.2.0",
60
60
  "@types/react": "^19.2.18",
61
61
  "@typescript-eslint/parser": "^8.67.0",
62
- "@vitest/coverage-v8": "^4.1.10",
63
- "eslint": "^9.39.4",
62
+ "@vitest/coverage-v8": "^4.1.11",
63
+ "eslint": "^9.39.5",
64
64
  "eslint-import-resolver-typescript": "^4.4.5",
65
65
  "eslint-plugin-import": "^2.32.0",
66
66
  "memfs": "^4.68.1",
@@ -68,25 +68,25 @@
68
68
  "rollup": "^4.62.4",
69
69
  "typescript": "^6.0.3",
70
70
  "unplugin-swc": "^1.5.11",
71
- "vitest": "^4.1.10"
71
+ "vitest": "^4.1.11"
72
72
  },
73
73
  "dependencies": {
74
74
  "@croct/json5-parser": "^0.2.2",
75
- "@swc/core": "^1.16.0",
75
+ "@swc/core": "^1.16.1",
76
76
  "chokidar": "^5.0.0",
77
77
  "commander": "^15.0.0",
78
78
  "execa": "^10.0.1",
79
79
  "glob": "^13.0.6",
80
- "i18next": "^26.3.6",
80
+ "i18next": "^26.4.0",
81
81
  "i18next-resources-for-ts": "^2.1.0",
82
- "inquirer": "^14.0.2",
82
+ "inquirer": "^14.1.0",
83
83
  "jiti": "^2.7.0",
84
84
  "jsonc-parser": "^3.3.1",
85
- "magic-string": "^1.2.0",
85
+ "magic-string": "^1.2.2",
86
86
  "minimatch": "^10.2.6",
87
87
  "ora": "^9.4.1",
88
88
  "react": "^19.2.8",
89
- "react-i18next": "^17.0.11",
89
+ "react-i18next": "^17.0.12",
90
90
  "yaml": "^2.9.0"
91
91
  }
92
92
  }
@@ -120,8 +120,9 @@ export declare class ASTVisitors {
120
120
  */
121
121
  private tryBindObjectArrayCallback;
122
122
  /**
123
- * Extracts the first callback parameter identifier from an iteration call node
124
- * and pairs it with the provided values array.
123
+ * Extracts the element callback parameter identifier from an iteration call node
124
+ * and pairs it with the provided values array. `paramIndex` is the position of
125
+ * the element parameter (0 for map/forEach/…, 1 for reduce's `(acc, el)`).
125
126
  */
126
127
  private extractCallbackParam;
127
128
  /**
@@ -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;AAItE;;;;;;;;;;;;;;;;;;;;;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,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,eAAe,EACvB,kBAAkB,CAAC,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