i18next-cli 1.74.5 → 1.74.6
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/core/ast-visitors.js +9 -17
- package/dist/cjs/extractor/parsers/expression-resolver.js +139 -44
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/ast-visitors.js +9 -17
- package/dist/esm/extractor/parsers/expression-resolver.js +139 -44
- package/package.json +1 -1
- package/types/extractor/core/ast-visitors.d.ts.map +1 -1
- package/types/extractor/parsers/expression-resolver.d.ts +13 -1
- package/types/extractor/parsers/expression-resolver.d.ts.map +1 -1
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.74.
|
|
40
|
+
.version('1.74.6') // This string is replaced with the actual version at build time by rollup
|
|
41
41
|
.addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
|
|
42
42
|
// new: global config override option
|
|
43
43
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
@@ -809,15 +809,11 @@ class ASTVisitors {
|
|
|
809
809
|
const elementParamIndex = ITERATION_METHODS[prop.value];
|
|
810
810
|
if (elementParamIndex === undefined)
|
|
811
811
|
return undefined;
|
|
812
|
-
// The object must be an identifier whose value is a known string array
|
|
813
812
|
const obj = callee.object;
|
|
814
|
-
// ── Case 1: KNOWN_ARRAY.map(x => ...)
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
return this.extractCallbackParam(node, values, elementParamIndex);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
813
|
+
// ── Case 1: KNOWN_ARRAY.map(x => ...) / ([1, 2] as const).map(x => ...)
|
|
814
|
+
const values = this.expressionResolver.arrayValuesOf(obj);
|
|
815
|
+
if (values?.length)
|
|
816
|
+
return this.extractCallbackParam(node, values, elementParamIndex);
|
|
821
817
|
// ── Case 2: Object.keys(MAP).map(k => ...) ────────────────────────────
|
|
822
818
|
// Object.values(MAP).map(v => ...)
|
|
823
819
|
// callee.object is a CallExpression: Object.keys(...) / Object.values(...)
|
|
@@ -859,20 +855,18 @@ class ASTVisitors {
|
|
|
859
855
|
*/
|
|
860
856
|
tryBindForOfLoop(node) {
|
|
861
857
|
try {
|
|
862
|
-
|
|
863
|
-
return undefined;
|
|
864
|
-
const source = node.right.value;
|
|
858
|
+
const source = node.right;
|
|
865
859
|
const left = node.left;
|
|
866
860
|
const pat = left?.type === 'VariableDeclaration' ? left.declarations?.[0]?.id : left;
|
|
867
861
|
// `for (const unit of ['day', 'hour'] as const)`
|
|
868
862
|
if (pat?.type === 'Identifier') {
|
|
869
|
-
const values = this.expressionResolver.
|
|
863
|
+
const values = this.expressionResolver.arrayValuesOf(source);
|
|
870
864
|
if (values?.length) {
|
|
871
865
|
this.expressionResolver.setTemporaryVariable(pat.value, values);
|
|
872
866
|
return () => this.expressionResolver.deleteTemporaryVariable(pat.value);
|
|
873
867
|
}
|
|
874
868
|
// `for (const item of items)` so `item.unit` resolves
|
|
875
|
-
const members = this.expressionResolver.
|
|
869
|
+
const members = this.expressionResolver.arrayMembersOf(source);
|
|
876
870
|
if (members) {
|
|
877
871
|
this.expressionResolver.setTemporaryObjectVariable(pat.value, members);
|
|
878
872
|
return () => this.expressionResolver.deleteTemporaryObjectVariable(pat.value);
|
|
@@ -881,7 +875,7 @@ class ASTVisitors {
|
|
|
881
875
|
}
|
|
882
876
|
// `for (const { unit } of [{ unit: 'day' }, …] as const)`
|
|
883
877
|
if (pat?.type === 'ObjectPattern') {
|
|
884
|
-
const members = this.expressionResolver.
|
|
878
|
+
const members = this.expressionResolver.arrayMembersOf(source);
|
|
885
879
|
if (!members)
|
|
886
880
|
return undefined;
|
|
887
881
|
const bound = [];
|
|
@@ -927,9 +921,7 @@ class ASTVisitors {
|
|
|
927
921
|
const elementParamIndex = ITERATION_METHODS[prop.value];
|
|
928
922
|
if (elementParamIndex === undefined)
|
|
929
923
|
return undefined;
|
|
930
|
-
|
|
931
|
-
return undefined;
|
|
932
|
-
const members = this.expressionResolver.getArrayElementMembers(callee.object.value);
|
|
924
|
+
const members = this.expressionResolver.arrayMembersOf(callee.object);
|
|
933
925
|
if (!members)
|
|
934
926
|
return undefined;
|
|
935
927
|
const callbackArg = node.arguments?.[0]?.expression;
|
|
@@ -14,6 +14,41 @@ const covers = (next, prev) => {
|
|
|
14
14
|
}
|
|
15
15
|
return next === prev;
|
|
16
16
|
};
|
|
17
|
+
// `(x)`, `x as const`, `x as T`, `x satisfies T` -> `x`
|
|
18
|
+
const unwrapExpr = (expr) => {
|
|
19
|
+
while (['ParenthesisExpression', 'TsConstAssertion', 'TsAsExpression', 'TsSatisfiesExpression'].includes(expr?.type))
|
|
20
|
+
expr = expr.expression;
|
|
21
|
+
return expr;
|
|
22
|
+
};
|
|
23
|
+
// Nested object members are flattened to dotted paths (`{ 'Foo.Bar.status': [...] }`).
|
|
24
|
+
// ponytail: capped so recursive types (`interface Node { child: Node }`) stay small;
|
|
25
|
+
// raise it if real code reads deeper chains in a key.
|
|
26
|
+
const MAX_MEMBER_DEPTH = 5;
|
|
27
|
+
// The members nested under `name`: { 'Bar.status': v } -> { status: v }. Member maps
|
|
28
|
+
// are never changed once built, so each is split by its first segment only once:
|
|
29
|
+
// resolving every `components['schemas'][X]` of an OpenAPI schema stays linear.
|
|
30
|
+
const nestedIndex = new WeakMap();
|
|
31
|
+
const nestedMembers = (members, name) => {
|
|
32
|
+
if (!members)
|
|
33
|
+
return undefined;
|
|
34
|
+
let index = nestedIndex.get(members);
|
|
35
|
+
if (!index) {
|
|
36
|
+
index = new Map();
|
|
37
|
+
for (const [path, vals] of Object.entries(members)) {
|
|
38
|
+
const dot = path.indexOf('.');
|
|
39
|
+
if (dot < 0)
|
|
40
|
+
continue;
|
|
41
|
+
const head = path.slice(0, dot);
|
|
42
|
+
if (!index.has(head))
|
|
43
|
+
index.set(head, {});
|
|
44
|
+
index.get(head)[path.slice(dot + 1)] = vals;
|
|
45
|
+
}
|
|
46
|
+
nestedIndex.set(members, index);
|
|
47
|
+
}
|
|
48
|
+
return index.get(name);
|
|
49
|
+
};
|
|
50
|
+
// `T['a']` -> 'a'
|
|
51
|
+
const indexedKey = (type) => type?.indexType?.type === 'TsLiteralType' && type.indexType.literal?.type === 'StringLiteral' ? type.indexType.literal.value : undefined;
|
|
17
52
|
// Whether replacing `prev` by `next` only adds to it.
|
|
18
53
|
const grows = (next, prev) => prev === undefined || (covers(next, prev) && !covers(prev, next));
|
|
19
54
|
// The parts of return expressions that still resolve without the file's local
|
|
@@ -96,6 +131,7 @@ class ExpressionResolver {
|
|
|
96
131
|
replays = [];
|
|
97
132
|
replaying = false;
|
|
98
133
|
grew = false;
|
|
134
|
+
memberDepth = 0;
|
|
99
135
|
constructor(hooks) {
|
|
100
136
|
this.hooks = hooks;
|
|
101
137
|
}
|
|
@@ -252,12 +288,7 @@ class ExpressionResolver {
|
|
|
252
288
|
// Unwrap TS type assertion wrappers before inspecting the shape of the initializer.
|
|
253
289
|
// `{ ... } as const` → TsConstAssertion; `x as Type` → TsAsExpression; etc.
|
|
254
290
|
// We need the raw expression to detect ObjectExpression and ArrowFunctionExpression.
|
|
255
|
-
|
|
256
|
-
while (unwrappedInit?.type === 'TsConstAssertion' ||
|
|
257
|
-
unwrappedInit?.type === 'TsAsExpression' ||
|
|
258
|
-
unwrappedInit?.type === 'TsSatisfiesExpression') {
|
|
259
|
-
unwrappedInit = unwrappedInit.expression;
|
|
260
|
-
}
|
|
291
|
+
const unwrappedInit = unwrapExpr(init);
|
|
261
292
|
// ObjectExpression -> map of string props
|
|
262
293
|
if (unwrappedInit.type === 'ObjectExpression' && Array.isArray(unwrappedInit.properties)) {
|
|
263
294
|
const map = {};
|
|
@@ -284,15 +315,8 @@ class ExpressionResolver {
|
|
|
284
315
|
// ArrayExpression -> list of string values
|
|
285
316
|
// Handles `const OPTS = ['a', 'b', 'c'] as const`
|
|
286
317
|
if (unwrappedInit.type === 'ArrayExpression' && Array.isArray(unwrappedInit.elements)) {
|
|
287
|
-
const vals =
|
|
288
|
-
|
|
289
|
-
if (!elem || !elem.expression)
|
|
290
|
-
continue;
|
|
291
|
-
const resolved = this.resolvePossibleStringValuesFromExpression(elem.expression);
|
|
292
|
-
if (resolved.length === 1)
|
|
293
|
-
vals.push(resolved[0]);
|
|
294
|
-
}
|
|
295
|
-
if (vals.length > 0) {
|
|
318
|
+
const vals = this.arrayLiteralValues(unwrappedInit);
|
|
319
|
+
if (vals) {
|
|
296
320
|
this.variableTable.set(name, vals);
|
|
297
321
|
// Also share so importing files can see this array
|
|
298
322
|
this.sharedVariableTable.set(name, vals);
|
|
@@ -301,30 +325,8 @@ class ExpressionResolver {
|
|
|
301
325
|
// Array of object literals — `const UNITS = [{ unit: 'day' }, …] as const`.
|
|
302
326
|
// Collect each property's possible values so `UNITS.map(({ unit }) => …)`
|
|
303
327
|
// and `for (const { unit } of UNITS)` can bind the destructured names.
|
|
304
|
-
const members =
|
|
305
|
-
|
|
306
|
-
let objExpr = elem?.expression;
|
|
307
|
-
while (objExpr?.type === 'TsConstAssertion' ||
|
|
308
|
-
objExpr?.type === 'TsAsExpression' ||
|
|
309
|
-
objExpr?.type === 'TsSatisfiesExpression')
|
|
310
|
-
objExpr = objExpr.expression;
|
|
311
|
-
if (objExpr?.type !== 'ObjectExpression')
|
|
312
|
-
continue;
|
|
313
|
-
for (const p of (objExpr.properties ?? [])) {
|
|
314
|
-
if (p?.type !== 'KeyValueProperty')
|
|
315
|
-
continue;
|
|
316
|
-
const keyName = p.key?.type === 'Identifier' || p.key?.type === 'StringLiteral' ? p.key.value : undefined;
|
|
317
|
-
if (!keyName)
|
|
318
|
-
continue;
|
|
319
|
-
const resolved = this.resolvePossibleStringValuesFromExpression(p.value);
|
|
320
|
-
if (resolved.length !== 1)
|
|
321
|
-
continue;
|
|
322
|
-
const list = members[keyName] ??= [];
|
|
323
|
-
if (!list.includes(resolved[0]))
|
|
324
|
-
list.push(resolved[0]);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (Object.keys(members).length > 0) {
|
|
328
|
+
const members = this.arrayLiteralMembers(unwrappedInit);
|
|
329
|
+
if (members) {
|
|
328
330
|
this.arrayElementMembers.set(name, members);
|
|
329
331
|
return;
|
|
330
332
|
}
|
|
@@ -513,10 +515,18 @@ class ExpressionResolver {
|
|
|
513
515
|
*/
|
|
514
516
|
objectMembersOf(expr) {
|
|
515
517
|
expr = astUtils.unwrapParens(expr);
|
|
518
|
+
if (expr?.type === 'OptionalChainingExpression')
|
|
519
|
+
return this.objectMembersOf(expr.base);
|
|
516
520
|
if (expr?.type === 'Identifier')
|
|
517
521
|
return this.temporaryObjectVariables.get(expr.value) ?? this.objectVariables.get(expr.value);
|
|
518
522
|
if (expr?.type === 'CallExpression' && expr.callee?.type === 'Identifier')
|
|
519
523
|
return this.sharedFunctionReturnMembers.get(expr.callee.value);
|
|
524
|
+
// `deepObject.Foo.Bar` → the members nested under `Foo.Bar`
|
|
525
|
+
if (expr?.type === 'MemberExpression') {
|
|
526
|
+
const prop = expr.property;
|
|
527
|
+
const name = prop?.type === 'Identifier' ? prop.value : prop?.type === 'Computed' && prop.expression?.type === 'StringLiteral' ? prop.expression.value : undefined;
|
|
528
|
+
return name === undefined ? undefined : nestedMembers(this.objectMembersOf(expr.object), name);
|
|
529
|
+
}
|
|
520
530
|
return undefined;
|
|
521
531
|
}
|
|
522
532
|
/**
|
|
@@ -525,7 +535,7 @@ class ExpressionResolver {
|
|
|
525
535
|
* resolves to a finite string set are kept; returns undefined when none do.
|
|
526
536
|
*/
|
|
527
537
|
collectObjectTypeMembers(members) {
|
|
528
|
-
if (!Array.isArray(members))
|
|
538
|
+
if (!Array.isArray(members) || this.memberDepth >= MAX_MEMBER_DEPTH)
|
|
529
539
|
return undefined;
|
|
530
540
|
const map = {};
|
|
531
541
|
for (const m of members) {
|
|
@@ -538,8 +548,23 @@ class ExpressionResolver {
|
|
|
538
548
|
if (!tsType)
|
|
539
549
|
continue;
|
|
540
550
|
const vals = this.resolvePossibleStringValuesFromType(tsType);
|
|
541
|
-
if (vals.length > 0)
|
|
551
|
+
if (vals.length > 0) {
|
|
542
552
|
map[memberName] = vals;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
// `Bar: { status: '201' | '400' }` → `Bar.status`
|
|
556
|
+
this.memberDepth++;
|
|
557
|
+
let nested;
|
|
558
|
+
try {
|
|
559
|
+
nested = this.resolveTypeMembers(tsType);
|
|
560
|
+
}
|
|
561
|
+
finally {
|
|
562
|
+
this.memberDepth--;
|
|
563
|
+
}
|
|
564
|
+
for (const [path, v] of Object.entries(nested ?? {})) {
|
|
565
|
+
if (path.split('.').length < MAX_MEMBER_DEPTH)
|
|
566
|
+
map[`${memberName}.${path}`] = v;
|
|
567
|
+
}
|
|
543
568
|
}
|
|
544
569
|
return Object.keys(map).length > 0 ? map : undefined;
|
|
545
570
|
}
|
|
@@ -556,6 +581,11 @@ class ExpressionResolver {
|
|
|
556
581
|
return undefined;
|
|
557
582
|
if (tsType.type === 'TsParenthesizedType')
|
|
558
583
|
return this.resolveTypeMembers(tsType.typeAnnotation);
|
|
584
|
+
// `components['schemas']['Pet']` → the members nested under `schemas.Pet`
|
|
585
|
+
if (tsType.type === 'TsIndexedAccessType') {
|
|
586
|
+
const key = indexedKey(tsType);
|
|
587
|
+
return key === undefined ? undefined : nestedMembers(this.resolveTypeMembers(tsType.objectType), key);
|
|
588
|
+
}
|
|
559
589
|
if (tsType.type === 'TsTypeLiteral') {
|
|
560
590
|
return this.collectObjectTypeMembers(tsType.members);
|
|
561
591
|
}
|
|
@@ -607,6 +637,65 @@ class ExpressionResolver {
|
|
|
607
637
|
catch { }
|
|
608
638
|
return undefined;
|
|
609
639
|
}
|
|
640
|
+
// `['day', 'hour']` -> ['day', 'hour']
|
|
641
|
+
arrayLiteralValues(arr) {
|
|
642
|
+
const vals = [];
|
|
643
|
+
for (const elem of arr.elements ?? []) {
|
|
644
|
+
if (!elem?.expression)
|
|
645
|
+
continue;
|
|
646
|
+
const resolved = this.resolvePossibleStringValuesFromExpression(elem.expression);
|
|
647
|
+
if (resolved.length === 1)
|
|
648
|
+
vals.push(resolved[0]);
|
|
649
|
+
}
|
|
650
|
+
return vals.length > 0 ? vals : undefined;
|
|
651
|
+
}
|
|
652
|
+
// `[{ unit: 'day' }, { unit: 'hour' }]` -> { unit: ['day', 'hour'] }
|
|
653
|
+
arrayLiteralMembers(arr) {
|
|
654
|
+
const members = {};
|
|
655
|
+
for (const elem of arr.elements ?? []) {
|
|
656
|
+
const objExpr = unwrapExpr(elem?.expression);
|
|
657
|
+
if (objExpr?.type !== 'ObjectExpression')
|
|
658
|
+
continue;
|
|
659
|
+
for (const p of (objExpr.properties ?? [])) {
|
|
660
|
+
if (p?.type !== 'KeyValueProperty')
|
|
661
|
+
continue;
|
|
662
|
+
const keyName = p.key?.type === 'Identifier' || p.key?.type === 'StringLiteral' ? p.key.value : undefined;
|
|
663
|
+
if (!keyName)
|
|
664
|
+
continue;
|
|
665
|
+
const resolved = this.resolvePossibleStringValuesFromExpression(p.value);
|
|
666
|
+
if (resolved.length !== 1)
|
|
667
|
+
continue;
|
|
668
|
+
const list = members[keyName] ??= [];
|
|
669
|
+
if (!list.includes(resolved[0]))
|
|
670
|
+
list.push(resolved[0]);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return Object.keys(members).length > 0 ? members : undefined;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* The values an iterated array holds: a known constant (`QUARTERS.map(…)`) or an
|
|
677
|
+
* inline literal (`([1, 2, 3, 4] as const).map(…)`).
|
|
678
|
+
*/
|
|
679
|
+
arrayValuesOf(expr) {
|
|
680
|
+
expr = unwrapExpr(expr);
|
|
681
|
+
if (expr?.type === 'Identifier')
|
|
682
|
+
return this.getVariableValues(expr.value);
|
|
683
|
+
if (expr?.type === 'ArrayExpression')
|
|
684
|
+
return this.arrayLiteralValues(expr);
|
|
685
|
+
return undefined;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* The element member map of an iterated array of objects: a typed or constant
|
|
689
|
+
* identifier (`items: IProps[]`) or an inline literal (`[{ unit: 'day' }]`).
|
|
690
|
+
*/
|
|
691
|
+
arrayMembersOf(expr) {
|
|
692
|
+
expr = unwrapExpr(expr);
|
|
693
|
+
if (expr?.type === 'Identifier')
|
|
694
|
+
return this.arrayElementMembers.get(expr.value);
|
|
695
|
+
if (expr?.type === 'ArrayExpression')
|
|
696
|
+
return this.arrayLiteralMembers(expr);
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
610
699
|
/**
|
|
611
700
|
* Bind an identifier to the member map of its array element type
|
|
612
701
|
* (`items: IProps[]`).
|
|
@@ -614,9 +703,6 @@ class ExpressionResolver {
|
|
|
614
703
|
setArrayElementMembers(name, members) {
|
|
615
704
|
this.arrayElementMembers.set(name, members);
|
|
616
705
|
}
|
|
617
|
-
getArrayElementMembers(name) {
|
|
618
|
-
return this.arrayElementMembers.get(name);
|
|
619
|
-
}
|
|
620
706
|
deleteArrayElementMembers(name) {
|
|
621
707
|
this.arrayElementMembers.delete(name);
|
|
622
708
|
}
|
|
@@ -887,6 +973,10 @@ class ExpressionResolver {
|
|
|
887
973
|
resolvePossibleStringValuesFromExpression(expression, returnEmptyStrings = false) {
|
|
888
974
|
// `t(('key'))` / `t(cond ? 'a' : ('b'))`: parens are just a wrapper node (#295).
|
|
889
975
|
expression = astUtils.unwrapParens(expression);
|
|
976
|
+
// `pet.category?.kind` → `pet.category.kind`
|
|
977
|
+
if (expression.type === 'OptionalChainingExpression') {
|
|
978
|
+
return this.resolvePossibleStringValuesFromExpression(expression.base, returnEmptyStrings);
|
|
979
|
+
}
|
|
890
980
|
// Support selector-style arrow functions used by the selector API:
|
|
891
981
|
// e.g. ($) => $.path.to.key -> ['path.to.key']
|
|
892
982
|
// e.g. ($) => $.table.columns[field] -> ['table.columns.name', 'table.columns.age']
|
|
@@ -1206,6 +1296,11 @@ class ExpressionResolver {
|
|
|
1206
1296
|
}
|
|
1207
1297
|
}
|
|
1208
1298
|
}
|
|
1299
|
+
// `DeepObject['Bar']['status']` → that member's values
|
|
1300
|
+
const key = indexedKey(type);
|
|
1301
|
+
const vals = key === undefined ? undefined : this.resolveTypeMembers(type.objectType)?.[key];
|
|
1302
|
+
if (vals)
|
|
1303
|
+
return vals;
|
|
1209
1304
|
}
|
|
1210
1305
|
catch { }
|
|
1211
1306
|
}
|
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.74.
|
|
34
|
+
.version('1.74.6') // This string is replaced with the actual version at build time by rollup
|
|
35
35
|
.addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
|
|
36
36
|
// new: global config override option
|
|
37
37
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
@@ -807,15 +807,11 @@ class ASTVisitors {
|
|
|
807
807
|
const elementParamIndex = ITERATION_METHODS[prop.value];
|
|
808
808
|
if (elementParamIndex === undefined)
|
|
809
809
|
return undefined;
|
|
810
|
-
// The object must be an identifier whose value is a known string array
|
|
811
810
|
const obj = callee.object;
|
|
812
|
-
// ── Case 1: KNOWN_ARRAY.map(x => ...)
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
return this.extractCallbackParam(node, values, elementParamIndex);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
811
|
+
// ── Case 1: KNOWN_ARRAY.map(x => ...) / ([1, 2] as const).map(x => ...)
|
|
812
|
+
const values = this.expressionResolver.arrayValuesOf(obj);
|
|
813
|
+
if (values?.length)
|
|
814
|
+
return this.extractCallbackParam(node, values, elementParamIndex);
|
|
819
815
|
// ── Case 2: Object.keys(MAP).map(k => ...) ────────────────────────────
|
|
820
816
|
// Object.values(MAP).map(v => ...)
|
|
821
817
|
// callee.object is a CallExpression: Object.keys(...) / Object.values(...)
|
|
@@ -857,20 +853,18 @@ class ASTVisitors {
|
|
|
857
853
|
*/
|
|
858
854
|
tryBindForOfLoop(node) {
|
|
859
855
|
try {
|
|
860
|
-
|
|
861
|
-
return undefined;
|
|
862
|
-
const source = node.right.value;
|
|
856
|
+
const source = node.right;
|
|
863
857
|
const left = node.left;
|
|
864
858
|
const pat = left?.type === 'VariableDeclaration' ? left.declarations?.[0]?.id : left;
|
|
865
859
|
// `for (const unit of ['day', 'hour'] as const)`
|
|
866
860
|
if (pat?.type === 'Identifier') {
|
|
867
|
-
const values = this.expressionResolver.
|
|
861
|
+
const values = this.expressionResolver.arrayValuesOf(source);
|
|
868
862
|
if (values?.length) {
|
|
869
863
|
this.expressionResolver.setTemporaryVariable(pat.value, values);
|
|
870
864
|
return () => this.expressionResolver.deleteTemporaryVariable(pat.value);
|
|
871
865
|
}
|
|
872
866
|
// `for (const item of items)` so `item.unit` resolves
|
|
873
|
-
const members = this.expressionResolver.
|
|
867
|
+
const members = this.expressionResolver.arrayMembersOf(source);
|
|
874
868
|
if (members) {
|
|
875
869
|
this.expressionResolver.setTemporaryObjectVariable(pat.value, members);
|
|
876
870
|
return () => this.expressionResolver.deleteTemporaryObjectVariable(pat.value);
|
|
@@ -879,7 +873,7 @@ class ASTVisitors {
|
|
|
879
873
|
}
|
|
880
874
|
// `for (const { unit } of [{ unit: 'day' }, …] as const)`
|
|
881
875
|
if (pat?.type === 'ObjectPattern') {
|
|
882
|
-
const members = this.expressionResolver.
|
|
876
|
+
const members = this.expressionResolver.arrayMembersOf(source);
|
|
883
877
|
if (!members)
|
|
884
878
|
return undefined;
|
|
885
879
|
const bound = [];
|
|
@@ -925,9 +919,7 @@ class ASTVisitors {
|
|
|
925
919
|
const elementParamIndex = ITERATION_METHODS[prop.value];
|
|
926
920
|
if (elementParamIndex === undefined)
|
|
927
921
|
return undefined;
|
|
928
|
-
|
|
929
|
-
return undefined;
|
|
930
|
-
const members = this.expressionResolver.getArrayElementMembers(callee.object.value);
|
|
922
|
+
const members = this.expressionResolver.arrayMembersOf(callee.object);
|
|
931
923
|
if (!members)
|
|
932
924
|
return undefined;
|
|
933
925
|
const callbackArg = node.arguments?.[0]?.expression;
|
|
@@ -12,6 +12,41 @@ const covers = (next, prev) => {
|
|
|
12
12
|
}
|
|
13
13
|
return next === prev;
|
|
14
14
|
};
|
|
15
|
+
// `(x)`, `x as const`, `x as T`, `x satisfies T` -> `x`
|
|
16
|
+
const unwrapExpr = (expr) => {
|
|
17
|
+
while (['ParenthesisExpression', 'TsConstAssertion', 'TsAsExpression', 'TsSatisfiesExpression'].includes(expr?.type))
|
|
18
|
+
expr = expr.expression;
|
|
19
|
+
return expr;
|
|
20
|
+
};
|
|
21
|
+
// Nested object members are flattened to dotted paths (`{ 'Foo.Bar.status': [...] }`).
|
|
22
|
+
// ponytail: capped so recursive types (`interface Node { child: Node }`) stay small;
|
|
23
|
+
// raise it if real code reads deeper chains in a key.
|
|
24
|
+
const MAX_MEMBER_DEPTH = 5;
|
|
25
|
+
// The members nested under `name`: { 'Bar.status': v } -> { status: v }. Member maps
|
|
26
|
+
// are never changed once built, so each is split by its first segment only once:
|
|
27
|
+
// resolving every `components['schemas'][X]` of an OpenAPI schema stays linear.
|
|
28
|
+
const nestedIndex = new WeakMap();
|
|
29
|
+
const nestedMembers = (members, name) => {
|
|
30
|
+
if (!members)
|
|
31
|
+
return undefined;
|
|
32
|
+
let index = nestedIndex.get(members);
|
|
33
|
+
if (!index) {
|
|
34
|
+
index = new Map();
|
|
35
|
+
for (const [path, vals] of Object.entries(members)) {
|
|
36
|
+
const dot = path.indexOf('.');
|
|
37
|
+
if (dot < 0)
|
|
38
|
+
continue;
|
|
39
|
+
const head = path.slice(0, dot);
|
|
40
|
+
if (!index.has(head))
|
|
41
|
+
index.set(head, {});
|
|
42
|
+
index.get(head)[path.slice(dot + 1)] = vals;
|
|
43
|
+
}
|
|
44
|
+
nestedIndex.set(members, index);
|
|
45
|
+
}
|
|
46
|
+
return index.get(name);
|
|
47
|
+
};
|
|
48
|
+
// `T['a']` -> 'a'
|
|
49
|
+
const indexedKey = (type) => type?.indexType?.type === 'TsLiteralType' && type.indexType.literal?.type === 'StringLiteral' ? type.indexType.literal.value : undefined;
|
|
15
50
|
// Whether replacing `prev` by `next` only adds to it.
|
|
16
51
|
const grows = (next, prev) => prev === undefined || (covers(next, prev) && !covers(prev, next));
|
|
17
52
|
// The parts of return expressions that still resolve without the file's local
|
|
@@ -94,6 +129,7 @@ class ExpressionResolver {
|
|
|
94
129
|
replays = [];
|
|
95
130
|
replaying = false;
|
|
96
131
|
grew = false;
|
|
132
|
+
memberDepth = 0;
|
|
97
133
|
constructor(hooks) {
|
|
98
134
|
this.hooks = hooks;
|
|
99
135
|
}
|
|
@@ -250,12 +286,7 @@ class ExpressionResolver {
|
|
|
250
286
|
// Unwrap TS type assertion wrappers before inspecting the shape of the initializer.
|
|
251
287
|
// `{ ... } as const` → TsConstAssertion; `x as Type` → TsAsExpression; etc.
|
|
252
288
|
// We need the raw expression to detect ObjectExpression and ArrowFunctionExpression.
|
|
253
|
-
|
|
254
|
-
while (unwrappedInit?.type === 'TsConstAssertion' ||
|
|
255
|
-
unwrappedInit?.type === 'TsAsExpression' ||
|
|
256
|
-
unwrappedInit?.type === 'TsSatisfiesExpression') {
|
|
257
|
-
unwrappedInit = unwrappedInit.expression;
|
|
258
|
-
}
|
|
289
|
+
const unwrappedInit = unwrapExpr(init);
|
|
259
290
|
// ObjectExpression -> map of string props
|
|
260
291
|
if (unwrappedInit.type === 'ObjectExpression' && Array.isArray(unwrappedInit.properties)) {
|
|
261
292
|
const map = {};
|
|
@@ -282,15 +313,8 @@ class ExpressionResolver {
|
|
|
282
313
|
// ArrayExpression -> list of string values
|
|
283
314
|
// Handles `const OPTS = ['a', 'b', 'c'] as const`
|
|
284
315
|
if (unwrappedInit.type === 'ArrayExpression' && Array.isArray(unwrappedInit.elements)) {
|
|
285
|
-
const vals =
|
|
286
|
-
|
|
287
|
-
if (!elem || !elem.expression)
|
|
288
|
-
continue;
|
|
289
|
-
const resolved = this.resolvePossibleStringValuesFromExpression(elem.expression);
|
|
290
|
-
if (resolved.length === 1)
|
|
291
|
-
vals.push(resolved[0]);
|
|
292
|
-
}
|
|
293
|
-
if (vals.length > 0) {
|
|
316
|
+
const vals = this.arrayLiteralValues(unwrappedInit);
|
|
317
|
+
if (vals) {
|
|
294
318
|
this.variableTable.set(name, vals);
|
|
295
319
|
// Also share so importing files can see this array
|
|
296
320
|
this.sharedVariableTable.set(name, vals);
|
|
@@ -299,30 +323,8 @@ class ExpressionResolver {
|
|
|
299
323
|
// Array of object literals — `const UNITS = [{ unit: 'day' }, …] as const`.
|
|
300
324
|
// Collect each property's possible values so `UNITS.map(({ unit }) => …)`
|
|
301
325
|
// and `for (const { unit } of UNITS)` can bind the destructured names.
|
|
302
|
-
const members =
|
|
303
|
-
|
|
304
|
-
let objExpr = elem?.expression;
|
|
305
|
-
while (objExpr?.type === 'TsConstAssertion' ||
|
|
306
|
-
objExpr?.type === 'TsAsExpression' ||
|
|
307
|
-
objExpr?.type === 'TsSatisfiesExpression')
|
|
308
|
-
objExpr = objExpr.expression;
|
|
309
|
-
if (objExpr?.type !== 'ObjectExpression')
|
|
310
|
-
continue;
|
|
311
|
-
for (const p of (objExpr.properties ?? [])) {
|
|
312
|
-
if (p?.type !== 'KeyValueProperty')
|
|
313
|
-
continue;
|
|
314
|
-
const keyName = p.key?.type === 'Identifier' || p.key?.type === 'StringLiteral' ? p.key.value : undefined;
|
|
315
|
-
if (!keyName)
|
|
316
|
-
continue;
|
|
317
|
-
const resolved = this.resolvePossibleStringValuesFromExpression(p.value);
|
|
318
|
-
if (resolved.length !== 1)
|
|
319
|
-
continue;
|
|
320
|
-
const list = members[keyName] ??= [];
|
|
321
|
-
if (!list.includes(resolved[0]))
|
|
322
|
-
list.push(resolved[0]);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (Object.keys(members).length > 0) {
|
|
326
|
+
const members = this.arrayLiteralMembers(unwrappedInit);
|
|
327
|
+
if (members) {
|
|
326
328
|
this.arrayElementMembers.set(name, members);
|
|
327
329
|
return;
|
|
328
330
|
}
|
|
@@ -511,10 +513,18 @@ class ExpressionResolver {
|
|
|
511
513
|
*/
|
|
512
514
|
objectMembersOf(expr) {
|
|
513
515
|
expr = unwrapParens(expr);
|
|
516
|
+
if (expr?.type === 'OptionalChainingExpression')
|
|
517
|
+
return this.objectMembersOf(expr.base);
|
|
514
518
|
if (expr?.type === 'Identifier')
|
|
515
519
|
return this.temporaryObjectVariables.get(expr.value) ?? this.objectVariables.get(expr.value);
|
|
516
520
|
if (expr?.type === 'CallExpression' && expr.callee?.type === 'Identifier')
|
|
517
521
|
return this.sharedFunctionReturnMembers.get(expr.callee.value);
|
|
522
|
+
// `deepObject.Foo.Bar` → the members nested under `Foo.Bar`
|
|
523
|
+
if (expr?.type === 'MemberExpression') {
|
|
524
|
+
const prop = expr.property;
|
|
525
|
+
const name = prop?.type === 'Identifier' ? prop.value : prop?.type === 'Computed' && prop.expression?.type === 'StringLiteral' ? prop.expression.value : undefined;
|
|
526
|
+
return name === undefined ? undefined : nestedMembers(this.objectMembersOf(expr.object), name);
|
|
527
|
+
}
|
|
518
528
|
return undefined;
|
|
519
529
|
}
|
|
520
530
|
/**
|
|
@@ -523,7 +533,7 @@ class ExpressionResolver {
|
|
|
523
533
|
* resolves to a finite string set are kept; returns undefined when none do.
|
|
524
534
|
*/
|
|
525
535
|
collectObjectTypeMembers(members) {
|
|
526
|
-
if (!Array.isArray(members))
|
|
536
|
+
if (!Array.isArray(members) || this.memberDepth >= MAX_MEMBER_DEPTH)
|
|
527
537
|
return undefined;
|
|
528
538
|
const map = {};
|
|
529
539
|
for (const m of members) {
|
|
@@ -536,8 +546,23 @@ class ExpressionResolver {
|
|
|
536
546
|
if (!tsType)
|
|
537
547
|
continue;
|
|
538
548
|
const vals = this.resolvePossibleStringValuesFromType(tsType);
|
|
539
|
-
if (vals.length > 0)
|
|
549
|
+
if (vals.length > 0) {
|
|
540
550
|
map[memberName] = vals;
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
// `Bar: { status: '201' | '400' }` → `Bar.status`
|
|
554
|
+
this.memberDepth++;
|
|
555
|
+
let nested;
|
|
556
|
+
try {
|
|
557
|
+
nested = this.resolveTypeMembers(tsType);
|
|
558
|
+
}
|
|
559
|
+
finally {
|
|
560
|
+
this.memberDepth--;
|
|
561
|
+
}
|
|
562
|
+
for (const [path, v] of Object.entries(nested ?? {})) {
|
|
563
|
+
if (path.split('.').length < MAX_MEMBER_DEPTH)
|
|
564
|
+
map[`${memberName}.${path}`] = v;
|
|
565
|
+
}
|
|
541
566
|
}
|
|
542
567
|
return Object.keys(map).length > 0 ? map : undefined;
|
|
543
568
|
}
|
|
@@ -554,6 +579,11 @@ class ExpressionResolver {
|
|
|
554
579
|
return undefined;
|
|
555
580
|
if (tsType.type === 'TsParenthesizedType')
|
|
556
581
|
return this.resolveTypeMembers(tsType.typeAnnotation);
|
|
582
|
+
// `components['schemas']['Pet']` → the members nested under `schemas.Pet`
|
|
583
|
+
if (tsType.type === 'TsIndexedAccessType') {
|
|
584
|
+
const key = indexedKey(tsType);
|
|
585
|
+
return key === undefined ? undefined : nestedMembers(this.resolveTypeMembers(tsType.objectType), key);
|
|
586
|
+
}
|
|
557
587
|
if (tsType.type === 'TsTypeLiteral') {
|
|
558
588
|
return this.collectObjectTypeMembers(tsType.members);
|
|
559
589
|
}
|
|
@@ -605,6 +635,65 @@ class ExpressionResolver {
|
|
|
605
635
|
catch { }
|
|
606
636
|
return undefined;
|
|
607
637
|
}
|
|
638
|
+
// `['day', 'hour']` -> ['day', 'hour']
|
|
639
|
+
arrayLiteralValues(arr) {
|
|
640
|
+
const vals = [];
|
|
641
|
+
for (const elem of arr.elements ?? []) {
|
|
642
|
+
if (!elem?.expression)
|
|
643
|
+
continue;
|
|
644
|
+
const resolved = this.resolvePossibleStringValuesFromExpression(elem.expression);
|
|
645
|
+
if (resolved.length === 1)
|
|
646
|
+
vals.push(resolved[0]);
|
|
647
|
+
}
|
|
648
|
+
return vals.length > 0 ? vals : undefined;
|
|
649
|
+
}
|
|
650
|
+
// `[{ unit: 'day' }, { unit: 'hour' }]` -> { unit: ['day', 'hour'] }
|
|
651
|
+
arrayLiteralMembers(arr) {
|
|
652
|
+
const members = {};
|
|
653
|
+
for (const elem of arr.elements ?? []) {
|
|
654
|
+
const objExpr = unwrapExpr(elem?.expression);
|
|
655
|
+
if (objExpr?.type !== 'ObjectExpression')
|
|
656
|
+
continue;
|
|
657
|
+
for (const p of (objExpr.properties ?? [])) {
|
|
658
|
+
if (p?.type !== 'KeyValueProperty')
|
|
659
|
+
continue;
|
|
660
|
+
const keyName = p.key?.type === 'Identifier' || p.key?.type === 'StringLiteral' ? p.key.value : undefined;
|
|
661
|
+
if (!keyName)
|
|
662
|
+
continue;
|
|
663
|
+
const resolved = this.resolvePossibleStringValuesFromExpression(p.value);
|
|
664
|
+
if (resolved.length !== 1)
|
|
665
|
+
continue;
|
|
666
|
+
const list = members[keyName] ??= [];
|
|
667
|
+
if (!list.includes(resolved[0]))
|
|
668
|
+
list.push(resolved[0]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return Object.keys(members).length > 0 ? members : undefined;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* The values an iterated array holds: a known constant (`QUARTERS.map(…)`) or an
|
|
675
|
+
* inline literal (`([1, 2, 3, 4] as const).map(…)`).
|
|
676
|
+
*/
|
|
677
|
+
arrayValuesOf(expr) {
|
|
678
|
+
expr = unwrapExpr(expr);
|
|
679
|
+
if (expr?.type === 'Identifier')
|
|
680
|
+
return this.getVariableValues(expr.value);
|
|
681
|
+
if (expr?.type === 'ArrayExpression')
|
|
682
|
+
return this.arrayLiteralValues(expr);
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The element member map of an iterated array of objects: a typed or constant
|
|
687
|
+
* identifier (`items: IProps[]`) or an inline literal (`[{ unit: 'day' }]`).
|
|
688
|
+
*/
|
|
689
|
+
arrayMembersOf(expr) {
|
|
690
|
+
expr = unwrapExpr(expr);
|
|
691
|
+
if (expr?.type === 'Identifier')
|
|
692
|
+
return this.arrayElementMembers.get(expr.value);
|
|
693
|
+
if (expr?.type === 'ArrayExpression')
|
|
694
|
+
return this.arrayLiteralMembers(expr);
|
|
695
|
+
return undefined;
|
|
696
|
+
}
|
|
608
697
|
/**
|
|
609
698
|
* Bind an identifier to the member map of its array element type
|
|
610
699
|
* (`items: IProps[]`).
|
|
@@ -612,9 +701,6 @@ class ExpressionResolver {
|
|
|
612
701
|
setArrayElementMembers(name, members) {
|
|
613
702
|
this.arrayElementMembers.set(name, members);
|
|
614
703
|
}
|
|
615
|
-
getArrayElementMembers(name) {
|
|
616
|
-
return this.arrayElementMembers.get(name);
|
|
617
|
-
}
|
|
618
704
|
deleteArrayElementMembers(name) {
|
|
619
705
|
this.arrayElementMembers.delete(name);
|
|
620
706
|
}
|
|
@@ -885,6 +971,10 @@ class ExpressionResolver {
|
|
|
885
971
|
resolvePossibleStringValuesFromExpression(expression, returnEmptyStrings = false) {
|
|
886
972
|
// `t(('key'))` / `t(cond ? 'a' : ('b'))`: parens are just a wrapper node (#295).
|
|
887
973
|
expression = unwrapParens(expression);
|
|
974
|
+
// `pet.category?.kind` → `pet.category.kind`
|
|
975
|
+
if (expression.type === 'OptionalChainingExpression') {
|
|
976
|
+
return this.resolvePossibleStringValuesFromExpression(expression.base, returnEmptyStrings);
|
|
977
|
+
}
|
|
888
978
|
// Support selector-style arrow functions used by the selector API:
|
|
889
979
|
// e.g. ($) => $.path.to.key -> ['path.to.key']
|
|
890
980
|
// e.g. ($) => $.table.columns[field] -> ['table.columns.name', 'table.columns.age']
|
|
@@ -1204,6 +1294,11 @@ class ExpressionResolver {
|
|
|
1204
1294
|
}
|
|
1205
1295
|
}
|
|
1206
1296
|
}
|
|
1297
|
+
// `DeepObject['Bar']['status']` → that member's values
|
|
1298
|
+
const key = indexedKey(type);
|
|
1299
|
+
const vals = key === undefined ? undefined : this.resolveTypeMembers(type.objectType)?.[key];
|
|
1300
|
+
if (vals)
|
|
1301
|
+
return vals;
|
|
1207
1302
|
}
|
|
1208
1303
|
catch { }
|
|
1209
1304
|
}
|
package/package.json
CHANGED
|
@@ -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,CAA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,MAAM;CAGjC"}
|
|
@@ -22,6 +22,7 @@ export declare class ExpressionResolver {
|
|
|
22
22
|
private replays;
|
|
23
23
|
private replaying;
|
|
24
24
|
private grew;
|
|
25
|
+
private memberDepth;
|
|
25
26
|
constructor(hooks: ASTVisitorHooks);
|
|
26
27
|
/**
|
|
27
28
|
* Clear per-file captured variables. Enums / shared maps are kept.
|
|
@@ -118,12 +119,23 @@ export declare class ExpressionResolver {
|
|
|
118
119
|
* that `items.map(({ size }) => …)` can bind the callback parameter.
|
|
119
120
|
*/
|
|
120
121
|
resolveArrayElementMembers(tsType: any): Record<string, string[]> | undefined;
|
|
122
|
+
private arrayLiteralValues;
|
|
123
|
+
private arrayLiteralMembers;
|
|
124
|
+
/**
|
|
125
|
+
* The values an iterated array holds: a known constant (`QUARTERS.map(…)`) or an
|
|
126
|
+
* inline literal (`([1, 2, 3, 4] as const).map(…)`).
|
|
127
|
+
*/
|
|
128
|
+
arrayValuesOf(expr: any): string[] | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The element member map of an iterated array of objects: a typed or constant
|
|
131
|
+
* identifier (`items: IProps[]`) or an inline literal (`[{ unit: 'day' }]`).
|
|
132
|
+
*/
|
|
133
|
+
arrayMembersOf(expr: any): Record<string, string[]> | undefined;
|
|
121
134
|
/**
|
|
122
135
|
* Bind an identifier to the member map of its array element type
|
|
123
136
|
* (`items: IProps[]`).
|
|
124
137
|
*/
|
|
125
138
|
setArrayElementMembers(name: string, members: Record<string, string[]>): void;
|
|
126
|
-
getArrayElementMembers(name: string): Record<string, string[]> | undefined;
|
|
127
139
|
deleteArrayElementMembers(name: string): void;
|
|
128
140
|
/**
|
|
129
141
|
* Temporarily bind an identifier to an object-shaped type's members, so that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-resolver.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/expression-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkD,MAAM,WAAW,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