i18next-cli 1.47.10 → 1.47.11
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 +48 -3
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/parsers/scope-manager.js +48 -3
- package/package.json +1 -1
- package/types/extractor/parsers/scope-manager.d.ts +10 -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.11'); // 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
|
|
@@ -11,6 +11,40 @@ class ScopeManager {
|
|
|
11
11
|
constructor(config) {
|
|
12
12
|
this.config = config;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Recursively unwraps TypeScript type assertion wrappers to reach the
|
|
16
|
+
* underlying expression node.
|
|
17
|
+
*/
|
|
18
|
+
static unwrapTsExpression(node) {
|
|
19
|
+
if (!node)
|
|
20
|
+
return node;
|
|
21
|
+
switch (node.type) {
|
|
22
|
+
case 'TsConstAssertion':
|
|
23
|
+
case 'TsAsExpression':
|
|
24
|
+
case 'TsSatisfiesExpression':
|
|
25
|
+
return ScopeManager.unwrapTsExpression(node.expression);
|
|
26
|
+
default:
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts a string value from a variable declarator's TypeScript type
|
|
32
|
+
* annotation when it is a literal string type (e.g., `const ns: 'users'`).
|
|
33
|
+
*/
|
|
34
|
+
static extractStringFromTypeAnnotation(node) {
|
|
35
|
+
if (!node?.id || node.id.type !== 'Identifier')
|
|
36
|
+
return undefined;
|
|
37
|
+
if ('typeAnnotation' in node.id) {
|
|
38
|
+
const rawTypeAnn = node.id.typeAnnotation;
|
|
39
|
+
if (!rawTypeAnn)
|
|
40
|
+
return undefined;
|
|
41
|
+
const tsType = rawTypeAnn.typeAnnotation;
|
|
42
|
+
if (tsType?.type === 'TsLiteralType' && tsType.literal?.type === 'StringLiteral') {
|
|
43
|
+
return tsType.literal.value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
14
48
|
/**
|
|
15
49
|
* Reset per-file scope state.
|
|
16
50
|
*
|
|
@@ -115,9 +149,20 @@ class ScopeManager {
|
|
|
115
149
|
const init = node.init;
|
|
116
150
|
if (!init)
|
|
117
151
|
return;
|
|
118
|
-
// Record simple const/let string initializers for later resolution
|
|
119
|
-
|
|
120
|
-
|
|
152
|
+
// Record simple const/let string initializers for later resolution.
|
|
153
|
+
// Unwrap TS type assertion wrappers (as const, satisfies, as 'x') and fall
|
|
154
|
+
// back to the variable's type annotation when the init is not a string literal.
|
|
155
|
+
if (node.id.type === 'Identifier') {
|
|
156
|
+
const unwrapped = ScopeManager.unwrapTsExpression(init);
|
|
157
|
+
if (unwrapped?.type === 'StringLiteral') {
|
|
158
|
+
this.simpleConstants.set(node.id.value, unwrapped.value);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const fromType = ScopeManager.extractStringFromTypeAnnotation(node);
|
|
162
|
+
if (fromType !== undefined) {
|
|
163
|
+
this.simpleConstants.set(node.id.value, fromType);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
121
166
|
// continue processing; still may be a useTranslation/getFixedT call below
|
|
122
167
|
}
|
|
123
168
|
// Determine the actual call expression, looking inside AwaitExpressions.
|
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.11'); // 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
|
|
@@ -9,6 +9,40 @@ class ScopeManager {
|
|
|
9
9
|
constructor(config) {
|
|
10
10
|
this.config = config;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Recursively unwraps TypeScript type assertion wrappers to reach the
|
|
14
|
+
* underlying expression node.
|
|
15
|
+
*/
|
|
16
|
+
static unwrapTsExpression(node) {
|
|
17
|
+
if (!node)
|
|
18
|
+
return node;
|
|
19
|
+
switch (node.type) {
|
|
20
|
+
case 'TsConstAssertion':
|
|
21
|
+
case 'TsAsExpression':
|
|
22
|
+
case 'TsSatisfiesExpression':
|
|
23
|
+
return ScopeManager.unwrapTsExpression(node.expression);
|
|
24
|
+
default:
|
|
25
|
+
return node;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extracts a string value from a variable declarator's TypeScript type
|
|
30
|
+
* annotation when it is a literal string type (e.g., `const ns: 'users'`).
|
|
31
|
+
*/
|
|
32
|
+
static extractStringFromTypeAnnotation(node) {
|
|
33
|
+
if (!node?.id || node.id.type !== 'Identifier')
|
|
34
|
+
return undefined;
|
|
35
|
+
if ('typeAnnotation' in node.id) {
|
|
36
|
+
const rawTypeAnn = node.id.typeAnnotation;
|
|
37
|
+
if (!rawTypeAnn)
|
|
38
|
+
return undefined;
|
|
39
|
+
const tsType = rawTypeAnn.typeAnnotation;
|
|
40
|
+
if (tsType?.type === 'TsLiteralType' && tsType.literal?.type === 'StringLiteral') {
|
|
41
|
+
return tsType.literal.value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
12
46
|
/**
|
|
13
47
|
* Reset per-file scope state.
|
|
14
48
|
*
|
|
@@ -113,9 +147,20 @@ class ScopeManager {
|
|
|
113
147
|
const init = node.init;
|
|
114
148
|
if (!init)
|
|
115
149
|
return;
|
|
116
|
-
// Record simple const/let string initializers for later resolution
|
|
117
|
-
|
|
118
|
-
|
|
150
|
+
// Record simple const/let string initializers for later resolution.
|
|
151
|
+
// Unwrap TS type assertion wrappers (as const, satisfies, as 'x') and fall
|
|
152
|
+
// back to the variable's type annotation when the init is not a string literal.
|
|
153
|
+
if (node.id.type === 'Identifier') {
|
|
154
|
+
const unwrapped = ScopeManager.unwrapTsExpression(init);
|
|
155
|
+
if (unwrapped?.type === 'StringLiteral') {
|
|
156
|
+
this.simpleConstants.set(node.id.value, unwrapped.value);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const fromType = ScopeManager.extractStringFromTypeAnnotation(node);
|
|
160
|
+
if (fromType !== undefined) {
|
|
161
|
+
this.simpleConstants.set(node.id.value, fromType);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
119
164
|
// continue processing; still may be a useTranslation/getFixedT call below
|
|
120
165
|
}
|
|
121
166
|
// Determine the actual call expression, looking inside AwaitExpressions.
|
package/package.json
CHANGED
|
@@ -6,6 +6,16 @@ export declare class ScopeManager {
|
|
|
6
6
|
private scope;
|
|
7
7
|
private simpleConstants;
|
|
8
8
|
constructor(config: Omit<I18nextToolkitConfig, 'plugins'>);
|
|
9
|
+
/**
|
|
10
|
+
* Recursively unwraps TypeScript type assertion wrappers to reach the
|
|
11
|
+
* underlying expression node.
|
|
12
|
+
*/
|
|
13
|
+
private static unwrapTsExpression;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a string value from a variable declarator's TypeScript type
|
|
16
|
+
* annotation when it is a literal string type (e.g., `const ns: 'users'`).
|
|
17
|
+
*/
|
|
18
|
+
private static extractStringFromTypeAnnotation;
|
|
9
19
|
/**
|
|
10
20
|
* Reset per-file scope state.
|
|
11
21
|
*
|
|
@@ -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,EAEV,kBAAkB,EAMnB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,SAAS,EAA4B,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAG5F,qBAAa,YAAY;IACvB,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,KAAK,CAAqE;IAGlF,OAAO,CAAC,eAAe,CAAiC;gBAE3C,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IAI1D;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAcjC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,+BAA+B;IAgB9C;;;;;;OAMG;IACI,KAAK,IAAK,IAAI;IAMrB;;;OAGG;IACH,UAAU,IAAK,IAAI;IAInB;;;OAGG;IACH,SAAS,IAAK,IAAI;IAIlB;;;;;;OAMG;IACH,aAAa,CAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAUnD;;;;;;OAMG;IACH,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAkBrD,OAAO,CAAC,uBAAuB;IAoB/B;;OAEG;IACI,6BAA6B,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvE;;;;;;;;;;OAUG;IACH,wBAAwB,CAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAiEzD;;;;;;;;OAQG;IACH,OAAO,CAAC,+BAA+B;IAsGvC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,8BAA8B;IA+EtC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,yBAAyB;IAoBjC;;;;;;;;;OASG;IACH,OAAO,CAAC,qCAAqC;CAuB9C"}
|