i18next-cli 1.47.11 → 1.47.12
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 +1 -1
- package/dist/cjs/extractor/parsers/scope-manager.js +61 -6
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/parsers/scope-manager.js +61 -6
- package/package.json +1 -1
- package/types/extractor/parsers/scope-manager.d.ts +6 -0
- package/types/extractor/parsers/scope-manager.d.ts.map +1 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ const program = new commander.Command();
|
|
|
31
31
|
program
|
|
32
32
|
.name('i18next-cli')
|
|
33
33
|
.description('A unified, high-performance i18next CLI.')
|
|
34
|
-
.version('1.47.
|
|
34
|
+
.version('1.47.12'); // 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
|
|
@@ -8,6 +8,8 @@ class ScopeManager {
|
|
|
8
8
|
scope = new Map();
|
|
9
9
|
// Track simple local constants with string literal values to resolve identifier args
|
|
10
10
|
simpleConstants = new Map();
|
|
11
|
+
// Track simple local constant objects with string literal property values
|
|
12
|
+
simpleConstantObjects = new Map();
|
|
11
13
|
constructor(config) {
|
|
12
14
|
this.config = config;
|
|
13
15
|
}
|
|
@@ -56,6 +58,7 @@ class ScopeManager {
|
|
|
56
58
|
this.scopeStack = [];
|
|
57
59
|
this.scope = new Map();
|
|
58
60
|
this.simpleConstants.clear();
|
|
61
|
+
this.simpleConstantObjects.clear();
|
|
59
62
|
}
|
|
60
63
|
/**
|
|
61
64
|
* Enters a new variable scope by pushing a new scope map onto the stack.
|
|
@@ -134,6 +137,27 @@ class ScopeManager {
|
|
|
134
137
|
resolveSimpleStringIdentifier(name) {
|
|
135
138
|
return this.simpleConstants.get(name);
|
|
136
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolve a MemberExpression node (e.g., `ns.custom`) to its string value
|
|
142
|
+
* by looking up the object in `simpleConstantObjects`.
|
|
143
|
+
*/
|
|
144
|
+
resolveSimpleMemberExpression(node) {
|
|
145
|
+
if (node.object.type !== 'Identifier') {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const map = this.simpleConstantObjects.get(node.object.value);
|
|
149
|
+
if (!map) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const prop = node.property;
|
|
153
|
+
if (prop.type === 'Identifier') {
|
|
154
|
+
return map[prop.value];
|
|
155
|
+
}
|
|
156
|
+
if (prop.type === 'Computed' && prop.expression.type === 'StringLiteral') {
|
|
157
|
+
return map[prop.expression.value];
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
137
161
|
/**
|
|
138
162
|
* Handles variable declarations that might define translation functions.
|
|
139
163
|
*
|
|
@@ -157,6 +181,29 @@ class ScopeManager {
|
|
|
157
181
|
if (unwrapped?.type === 'StringLiteral') {
|
|
158
182
|
this.simpleConstants.set(node.id.value, unwrapped.value);
|
|
159
183
|
}
|
|
184
|
+
else if (unwrapped?.type === 'ObjectExpression' && Array.isArray(unwrapped.properties)) {
|
|
185
|
+
const map = {};
|
|
186
|
+
for (const p of unwrapped.properties) {
|
|
187
|
+
if (p.type !== 'KeyValueProperty') {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const keyName = p.key.type === 'Identifier'
|
|
191
|
+
? p.key.value
|
|
192
|
+
: p.key.type === 'StringLiteral'
|
|
193
|
+
? p.key.value
|
|
194
|
+
: undefined;
|
|
195
|
+
if (!keyName) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const val = ScopeManager.unwrapTsExpression(p.value);
|
|
199
|
+
if (val?.type === 'StringLiteral') {
|
|
200
|
+
map[keyName] = val.value;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (Object.keys(map).length > 0) {
|
|
204
|
+
this.simpleConstantObjects.set(node.id.value, map);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
160
207
|
else {
|
|
161
208
|
const fromType = ScopeManager.extractStringFromTypeAnnotation(node);
|
|
162
209
|
if (fromType !== undefined) {
|
|
@@ -272,15 +319,19 @@ class ScopeManager {
|
|
|
272
319
|
defaultNs = nsNode.value;
|
|
273
320
|
}
|
|
274
321
|
else if (nsNode?.type === 'Identifier') {
|
|
275
|
-
// ← FIX A: resolve const I18N_NS = 'users'
|
|
276
322
|
defaultNs = this.resolveSimpleStringIdentifier(nsNode.value);
|
|
277
323
|
}
|
|
324
|
+
else if (nsNode?.type === 'MemberExpression') {
|
|
325
|
+
defaultNs = this.resolveSimpleMemberExpression(nsNode);
|
|
326
|
+
}
|
|
278
327
|
else if (nsNode?.type === 'ArrayExpression') {
|
|
279
328
|
const first = nsNode.elements[0]?.expression;
|
|
280
|
-
if (first?.type === 'StringLiteral')
|
|
329
|
+
if (first?.type === 'StringLiteral') {
|
|
281
330
|
defaultNs = first.value;
|
|
282
|
-
|
|
331
|
+
}
|
|
332
|
+
else if (first?.type === 'Identifier') {
|
|
283
333
|
defaultNs = this.resolveSimpleStringIdentifier(first.value);
|
|
334
|
+
}
|
|
284
335
|
}
|
|
285
336
|
}
|
|
286
337
|
kpArg = kpArgIndex === -1 ? undefined : callExpr.arguments?.[kpArgIndex]?.expression;
|
|
@@ -353,15 +404,19 @@ class ScopeManager {
|
|
|
353
404
|
defaultNs = nsNode.value;
|
|
354
405
|
}
|
|
355
406
|
else if (nsNode?.type === 'Identifier') {
|
|
356
|
-
// ← FIX A: resolve const I18N_NS = 'users'
|
|
357
407
|
defaultNs = this.resolveSimpleStringIdentifier(nsNode.value);
|
|
358
408
|
}
|
|
409
|
+
else if (nsNode?.type === 'MemberExpression') {
|
|
410
|
+
defaultNs = this.resolveSimpleMemberExpression(nsNode);
|
|
411
|
+
}
|
|
359
412
|
else if (nsNode?.type === 'ArrayExpression') {
|
|
360
413
|
const first = nsNode.elements[0]?.expression;
|
|
361
|
-
if (first?.type === 'StringLiteral')
|
|
414
|
+
if (first?.type === 'StringLiteral') {
|
|
362
415
|
defaultNs = first.value;
|
|
363
|
-
|
|
416
|
+
}
|
|
417
|
+
else if (first?.type === 'Identifier') {
|
|
364
418
|
defaultNs = this.resolveSimpleStringIdentifier(first.value);
|
|
419
|
+
}
|
|
365
420
|
}
|
|
366
421
|
}
|
|
367
422
|
kpArg = kpArgIndex === -1 ? undefined : callExpr.arguments?.[kpArgIndex]?.expression;
|
package/dist/esm/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ const program = new Command();
|
|
|
29
29
|
program
|
|
30
30
|
.name('i18next-cli')
|
|
31
31
|
.description('A unified, high-performance i18next CLI.')
|
|
32
|
-
.version('1.47.
|
|
32
|
+
.version('1.47.12'); // This string is replaced with the actual version at build time by rollup
|
|
33
33
|
// new: global config override option
|
|
34
34
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
35
35
|
program
|
|
@@ -6,6 +6,8 @@ class ScopeManager {
|
|
|
6
6
|
scope = new Map();
|
|
7
7
|
// Track simple local constants with string literal values to resolve identifier args
|
|
8
8
|
simpleConstants = new Map();
|
|
9
|
+
// Track simple local constant objects with string literal property values
|
|
10
|
+
simpleConstantObjects = new Map();
|
|
9
11
|
constructor(config) {
|
|
10
12
|
this.config = config;
|
|
11
13
|
}
|
|
@@ -54,6 +56,7 @@ class ScopeManager {
|
|
|
54
56
|
this.scopeStack = [];
|
|
55
57
|
this.scope = new Map();
|
|
56
58
|
this.simpleConstants.clear();
|
|
59
|
+
this.simpleConstantObjects.clear();
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* Enters a new variable scope by pushing a new scope map onto the stack.
|
|
@@ -132,6 +135,27 @@ class ScopeManager {
|
|
|
132
135
|
resolveSimpleStringIdentifier(name) {
|
|
133
136
|
return this.simpleConstants.get(name);
|
|
134
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Resolve a MemberExpression node (e.g., `ns.custom`) to its string value
|
|
140
|
+
* by looking up the object in `simpleConstantObjects`.
|
|
141
|
+
*/
|
|
142
|
+
resolveSimpleMemberExpression(node) {
|
|
143
|
+
if (node.object.type !== 'Identifier') {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const map = this.simpleConstantObjects.get(node.object.value);
|
|
147
|
+
if (!map) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const prop = node.property;
|
|
151
|
+
if (prop.type === 'Identifier') {
|
|
152
|
+
return map[prop.value];
|
|
153
|
+
}
|
|
154
|
+
if (prop.type === 'Computed' && prop.expression.type === 'StringLiteral') {
|
|
155
|
+
return map[prop.expression.value];
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
135
159
|
/**
|
|
136
160
|
* Handles variable declarations that might define translation functions.
|
|
137
161
|
*
|
|
@@ -155,6 +179,29 @@ class ScopeManager {
|
|
|
155
179
|
if (unwrapped?.type === 'StringLiteral') {
|
|
156
180
|
this.simpleConstants.set(node.id.value, unwrapped.value);
|
|
157
181
|
}
|
|
182
|
+
else if (unwrapped?.type === 'ObjectExpression' && Array.isArray(unwrapped.properties)) {
|
|
183
|
+
const map = {};
|
|
184
|
+
for (const p of unwrapped.properties) {
|
|
185
|
+
if (p.type !== 'KeyValueProperty') {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const keyName = p.key.type === 'Identifier'
|
|
189
|
+
? p.key.value
|
|
190
|
+
: p.key.type === 'StringLiteral'
|
|
191
|
+
? p.key.value
|
|
192
|
+
: undefined;
|
|
193
|
+
if (!keyName) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const val = ScopeManager.unwrapTsExpression(p.value);
|
|
197
|
+
if (val?.type === 'StringLiteral') {
|
|
198
|
+
map[keyName] = val.value;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (Object.keys(map).length > 0) {
|
|
202
|
+
this.simpleConstantObjects.set(node.id.value, map);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
158
205
|
else {
|
|
159
206
|
const fromType = ScopeManager.extractStringFromTypeAnnotation(node);
|
|
160
207
|
if (fromType !== undefined) {
|
|
@@ -270,15 +317,19 @@ class ScopeManager {
|
|
|
270
317
|
defaultNs = nsNode.value;
|
|
271
318
|
}
|
|
272
319
|
else if (nsNode?.type === 'Identifier') {
|
|
273
|
-
// ← FIX A: resolve const I18N_NS = 'users'
|
|
274
320
|
defaultNs = this.resolveSimpleStringIdentifier(nsNode.value);
|
|
275
321
|
}
|
|
322
|
+
else if (nsNode?.type === 'MemberExpression') {
|
|
323
|
+
defaultNs = this.resolveSimpleMemberExpression(nsNode);
|
|
324
|
+
}
|
|
276
325
|
else if (nsNode?.type === 'ArrayExpression') {
|
|
277
326
|
const first = nsNode.elements[0]?.expression;
|
|
278
|
-
if (first?.type === 'StringLiteral')
|
|
327
|
+
if (first?.type === 'StringLiteral') {
|
|
279
328
|
defaultNs = first.value;
|
|
280
|
-
|
|
329
|
+
}
|
|
330
|
+
else if (first?.type === 'Identifier') {
|
|
281
331
|
defaultNs = this.resolveSimpleStringIdentifier(first.value);
|
|
332
|
+
}
|
|
282
333
|
}
|
|
283
334
|
}
|
|
284
335
|
kpArg = kpArgIndex === -1 ? undefined : callExpr.arguments?.[kpArgIndex]?.expression;
|
|
@@ -351,15 +402,19 @@ class ScopeManager {
|
|
|
351
402
|
defaultNs = nsNode.value;
|
|
352
403
|
}
|
|
353
404
|
else if (nsNode?.type === 'Identifier') {
|
|
354
|
-
// ← FIX A: resolve const I18N_NS = 'users'
|
|
355
405
|
defaultNs = this.resolveSimpleStringIdentifier(nsNode.value);
|
|
356
406
|
}
|
|
407
|
+
else if (nsNode?.type === 'MemberExpression') {
|
|
408
|
+
defaultNs = this.resolveSimpleMemberExpression(nsNode);
|
|
409
|
+
}
|
|
357
410
|
else if (nsNode?.type === 'ArrayExpression') {
|
|
358
411
|
const first = nsNode.elements[0]?.expression;
|
|
359
|
-
if (first?.type === 'StringLiteral')
|
|
412
|
+
if (first?.type === 'StringLiteral') {
|
|
360
413
|
defaultNs = first.value;
|
|
361
|
-
|
|
414
|
+
}
|
|
415
|
+
else if (first?.type === 'Identifier') {
|
|
362
416
|
defaultNs = this.resolveSimpleStringIdentifier(first.value);
|
|
417
|
+
}
|
|
363
418
|
}
|
|
364
419
|
}
|
|
365
420
|
kpArg = kpArgIndex === -1 ? undefined : callExpr.arguments?.[kpArgIndex]?.expression;
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ export declare class ScopeManager {
|
|
|
5
5
|
private config;
|
|
6
6
|
private scope;
|
|
7
7
|
private simpleConstants;
|
|
8
|
+
private simpleConstantObjects;
|
|
8
9
|
constructor(config: Omit<I18nextToolkitConfig, 'plugins'>);
|
|
9
10
|
/**
|
|
10
11
|
* Recursively unwraps TypeScript type assertion wrappers to reach the
|
|
@@ -55,6 +56,11 @@ export declare class ScopeManager {
|
|
|
55
56
|
* Resolve simple identifier declared in-file to its string literal value, if known.
|
|
56
57
|
*/
|
|
57
58
|
resolveSimpleStringIdentifier(name: string): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a MemberExpression node (e.g., `ns.custom`) to its string value
|
|
61
|
+
* by looking up the object in `simpleConstantObjects`.
|
|
62
|
+
*/
|
|
63
|
+
private resolveSimpleMemberExpression;
|
|
58
64
|
/**
|
|
59
65
|
* Handles variable declarations that might define translation functions.
|
|
60
66
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/scope-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"scope-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/scope-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAMnB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,SAA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