i18next-cli 1.69.2 → 1.70.0
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 +147 -113
- package/dist/cjs/extractor/parsers/expression-resolver.js +8 -0
- package/dist/cjs/extractor/parsers/scope-manager.js +6 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/ast-visitors.js +147 -113
- package/dist/esm/extractor/parsers/expression-resolver.js +8 -0
- package/dist/esm/extractor/parsers/scope-manager.js +6 -0
- package/package.json +1 -1
- package/types/extractor/core/ast-visitors.d.ts +11 -0
- package/types/extractor/core/ast-visitors.d.ts.map +1 -1
- package/types/extractor/parsers/expression-resolver.d.ts +2 -0
- package/types/extractor/parsers/expression-resolver.d.ts.map +1 -1
- package/types/extractor/parsers/scope-manager.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.
|
|
40
|
+
.version('1.70.0'); // 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
|
|
@@ -230,22 +230,24 @@ class ASTVisitors {
|
|
|
230
230
|
if (pat.type === 'ObjectPattern') {
|
|
231
231
|
const patType = pat.typeAnnotation?.typeAnnotation ?? pat.typeAnnotation;
|
|
232
232
|
const members = this.expressionResolver.resolveTypeMembers(patType);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
233
|
+
for (const prop of (pat.properties ?? [])) {
|
|
234
|
+
// `{ size }` / `{ size = 'all' }` → AssignmentPatternProperty (local name is the key)
|
|
235
|
+
// `{ size: s }` / `{ size: s = 'all' }` → KeyValuePatternProperty
|
|
236
|
+
const memberName = prop?.key?.value;
|
|
237
|
+
let localNode = prop?.type === 'KeyValuePatternProperty' ? prop.value : prop?.key;
|
|
238
|
+
if (localNode?.type === 'AssignmentPattern')
|
|
239
|
+
localNode = localNode.left;
|
|
240
|
+
const localName = localNode?.type === 'Identifier' ? localNode.value : undefined;
|
|
241
|
+
if (!memberName || !localName)
|
|
242
|
+
continue;
|
|
243
|
+
// `({ t }: { t: TFunction<'ns'> })` → bind `t` to that namespace
|
|
244
|
+
this.bindTFunctionParam(localName, this.getMemberTypeNode(patType, memberName));
|
|
245
|
+
if (!members?.[memberName])
|
|
246
|
+
continue;
|
|
247
|
+
this.expressionResolver.setTemporaryVariable(localName, members[memberName]);
|
|
248
|
+
if (!paramTemporaries)
|
|
249
|
+
paramTemporaries = [];
|
|
250
|
+
paramTemporaries.push(localName);
|
|
249
251
|
}
|
|
250
252
|
continue;
|
|
251
253
|
}
|
|
@@ -292,103 +294,7 @@ class ASTVisitors {
|
|
|
292
294
|
else {
|
|
293
295
|
typeAnn = undefined;
|
|
294
296
|
}
|
|
295
|
-
|
|
296
|
-
const extractTypeName = (ta) => {
|
|
297
|
-
if (!ta)
|
|
298
|
-
return undefined;
|
|
299
|
-
// Identifier style: { type: 'Identifier', value: 'TFunction' } OR { name: 'TFunction' }
|
|
300
|
-
if (ta.typeName && (ta.typeName.type === 'Identifier'))
|
|
301
|
-
return ta.typeName.value ?? ta.typeName.name;
|
|
302
|
-
if (ta.typeName && ta.typeName.type === 'TsQualifiedName') {
|
|
303
|
-
// Qualified like Foo.TFunction -> try right side
|
|
304
|
-
const right = (ta.typeName.right ?? ta.typeName);
|
|
305
|
-
return right?.value ?? right?.name;
|
|
306
|
-
}
|
|
307
|
-
if (ta.typeName && typeof ta.typeName === 'string')
|
|
308
|
-
return ta.typeName;
|
|
309
|
-
if (ta.type === 'Identifier')
|
|
310
|
-
return ta.value ?? ta.name;
|
|
311
|
-
if (ta.id)
|
|
312
|
-
return ta.id?.value ?? ta.id?.name ?? ta.id;
|
|
313
|
-
return undefined;
|
|
314
|
-
};
|
|
315
|
-
const extractStringLiteralValue = (node) => {
|
|
316
|
-
if (!node)
|
|
317
|
-
return undefined;
|
|
318
|
-
// Handle: typeof SomeConst → TsTypeQuery { exprName: { value: 'SomeConst' } }
|
|
319
|
-
if (node?.type === 'TsTypeQuery') {
|
|
320
|
-
const name = node.exprName?.value ?? node.exprName?.name;
|
|
321
|
-
if (name)
|
|
322
|
-
return this.scopeManager.resolveSimpleStringIdentifier(name);
|
|
323
|
-
}
|
|
324
|
-
// shapes: TsLiteralType -> { literal: { type: 'StringLiteral', value: 'x' } }
|
|
325
|
-
if (node.type === 'TsLiteralType' && node.literal)
|
|
326
|
-
return node.literal.value ?? node.literal.raw;
|
|
327
|
-
if (node.type === 'StringLiteral' || node.type === 'Str' || node.type === 'Literal')
|
|
328
|
-
return node.value ?? node.raw ?? node.value;
|
|
329
|
-
if (node.literal && (node.literal.type === 'StringLiteral' || node.literal.type === 'Str'))
|
|
330
|
-
return node.literal.value;
|
|
331
|
-
// some SWC builds put the string directly on .value
|
|
332
|
-
if (typeof node.value === 'string')
|
|
333
|
-
return node.value;
|
|
334
|
-
// handle wrapped parameter like { params: [ ... ] } where a literal might be one level deeper
|
|
335
|
-
if (node.params && Array.isArray(node.params) && node.params[0])
|
|
336
|
-
return extractStringLiteralValue(node.params[0]);
|
|
337
|
-
if (node.typeArguments && Array.isArray(node.typeArguments) && node.typeArguments[0])
|
|
338
|
-
return extractStringLiteralValue(node.typeArguments[0]);
|
|
339
|
-
if (node.typeParameters && Array.isArray(node.typeParameters) && node.typeParameters[0])
|
|
340
|
-
return extractStringLiteralValue(node.typeParameters[0]);
|
|
341
|
-
if (node.typeParams && Array.isArray(node.typeParams) && node.typeParams[0])
|
|
342
|
-
return extractStringLiteralValue(node.typeParams[0]);
|
|
343
|
-
return undefined;
|
|
344
|
-
};
|
|
345
|
-
// Detect TsTypeReference like: TFunction<"my-custom-namespace">
|
|
346
|
-
if (typeAnn && (typeAnn.type === 'TsTypeReference' || typeAnn.type === 'TsTypeRef' || typeAnn.type === 'TsTypeReference')) {
|
|
347
|
-
const finalTypeName = extractTypeName(typeAnn);
|
|
348
|
-
if (finalTypeName === 'TFunction') {
|
|
349
|
-
// support multiple AST shapes for type parameters:
|
|
350
|
-
// - typeAnn.typeParameters?.params?.[0]
|
|
351
|
-
// - typeAnn.typeArguments?.params?.[0]
|
|
352
|
-
// - typeAnn.typeParams?.[0] / typeAnn.params?.[0]
|
|
353
|
-
const candidates = [
|
|
354
|
-
typeAnn.typeParameters?.params?.[0],
|
|
355
|
-
typeAnn.typeParameters?.[0],
|
|
356
|
-
typeAnn.typeArguments?.params?.[0],
|
|
357
|
-
typeAnn.typeArguments?.[0],
|
|
358
|
-
typeAnn.typeParams?.params?.[0],
|
|
359
|
-
typeAnn.typeParams?.[0],
|
|
360
|
-
typeAnn.params?.[0],
|
|
361
|
-
typeAnn.args?.[0],
|
|
362
|
-
typeAnn.typeParameters, // fallback if it's directly the literal
|
|
363
|
-
typeAnn.typeArguments,
|
|
364
|
-
typeAnn.typeParams,
|
|
365
|
-
];
|
|
366
|
-
let tp;
|
|
367
|
-
for (const c of candidates) {
|
|
368
|
-
if (c) {
|
|
369
|
-
tp = c;
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const ns = extractStringLiteralValue(tp);
|
|
374
|
-
// Extract the second type parameter for KPrefix
|
|
375
|
-
// We need to find the second element from the same type parameter list
|
|
376
|
-
const typeParams = typeAnn.typeParameters?.params ??
|
|
377
|
-
typeAnn.typeArguments?.params ??
|
|
378
|
-
typeAnn.typeParams?.params ??
|
|
379
|
-
undefined;
|
|
380
|
-
let kpFromType;
|
|
381
|
-
if (typeParams && typeParams.length >= 2) {
|
|
382
|
-
kpFromType = extractStringLiteralValue(typeParams[1]);
|
|
383
|
-
}
|
|
384
|
-
if (ns || kpFromType) {
|
|
385
|
-
this.scopeManager.setVarInScope(paramKey, {
|
|
386
|
-
defaultNs: ns,
|
|
387
|
-
keyPrefix: kpFromType // honour TFunction<Ns, KPrefix>
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
297
|
+
this.bindTFunctionParam(paramKey, typeAnn);
|
|
392
298
|
// Capture parameter type annotations as temporary variables in the
|
|
393
299
|
// expression resolver so that dynamic bracket expressions like
|
|
394
300
|
// `t(($) => $.table.columns[field])` can resolve `field` to its
|
|
@@ -650,6 +556,134 @@ class ASTVisitors {
|
|
|
650
556
|
this.scopeManager.exitClassScope();
|
|
651
557
|
}
|
|
652
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* If `typeAnn` is a `TFunction<Ns, KPrefix>` type reference, register
|
|
561
|
+
* `paramKey` in the current scope with that namespace / keyPrefix.
|
|
562
|
+
*/
|
|
563
|
+
bindTFunctionParam(paramKey, typeAnn) {
|
|
564
|
+
// Small helpers to robustly extract the referenced type name and literal string
|
|
565
|
+
const extractTypeName = (ta) => {
|
|
566
|
+
if (!ta)
|
|
567
|
+
return undefined;
|
|
568
|
+
// Identifier style: { type: 'Identifier', value: 'TFunction' } OR { name: 'TFunction' }
|
|
569
|
+
if (ta.typeName && (ta.typeName.type === 'Identifier'))
|
|
570
|
+
return ta.typeName.value ?? ta.typeName.name;
|
|
571
|
+
if (ta.typeName && ta.typeName.type === 'TsQualifiedName') {
|
|
572
|
+
// Qualified like Foo.TFunction -> try right side
|
|
573
|
+
const right = (ta.typeName.right ?? ta.typeName);
|
|
574
|
+
return right?.value ?? right?.name;
|
|
575
|
+
}
|
|
576
|
+
if (ta.typeName && typeof ta.typeName === 'string')
|
|
577
|
+
return ta.typeName;
|
|
578
|
+
if (ta.type === 'Identifier')
|
|
579
|
+
return ta.value ?? ta.name;
|
|
580
|
+
if (ta.id)
|
|
581
|
+
return ta.id?.value ?? ta.id?.name ?? ta.id;
|
|
582
|
+
return undefined;
|
|
583
|
+
};
|
|
584
|
+
const extractStringLiteralValue = (node) => {
|
|
585
|
+
if (!node)
|
|
586
|
+
return undefined;
|
|
587
|
+
// Handle: typeof SomeConst → TsTypeQuery { exprName: { value: 'SomeConst' } }
|
|
588
|
+
if (node?.type === 'TsTypeQuery') {
|
|
589
|
+
const name = node.exprName?.value ?? node.exprName?.name;
|
|
590
|
+
if (name)
|
|
591
|
+
return this.scopeManager.resolveSimpleStringIdentifier(name);
|
|
592
|
+
}
|
|
593
|
+
// shapes: TsLiteralType -> { literal: { type: 'StringLiteral', value: 'x' } }
|
|
594
|
+
if (node.type === 'TsLiteralType' && node.literal)
|
|
595
|
+
return node.literal.value ?? node.literal.raw;
|
|
596
|
+
if (node.type === 'StringLiteral' || node.type === 'Str' || node.type === 'Literal')
|
|
597
|
+
return node.value ?? node.raw ?? node.value;
|
|
598
|
+
if (node.literal && (node.literal.type === 'StringLiteral' || node.literal.type === 'Str'))
|
|
599
|
+
return node.literal.value;
|
|
600
|
+
// some SWC builds put the string directly on .value
|
|
601
|
+
if (typeof node.value === 'string')
|
|
602
|
+
return node.value;
|
|
603
|
+
// handle wrapped parameter like { params: [ ... ] } where a literal might be one level deeper
|
|
604
|
+
if (node.params && Array.isArray(node.params) && node.params[0])
|
|
605
|
+
return extractStringLiteralValue(node.params[0]);
|
|
606
|
+
if (node.typeArguments && Array.isArray(node.typeArguments) && node.typeArguments[0])
|
|
607
|
+
return extractStringLiteralValue(node.typeArguments[0]);
|
|
608
|
+
if (node.typeParameters && Array.isArray(node.typeParameters) && node.typeParameters[0])
|
|
609
|
+
return extractStringLiteralValue(node.typeParameters[0]);
|
|
610
|
+
if (node.typeParams && Array.isArray(node.typeParams) && node.typeParams[0])
|
|
611
|
+
return extractStringLiteralValue(node.typeParams[0]);
|
|
612
|
+
return undefined;
|
|
613
|
+
};
|
|
614
|
+
// Detect TsTypeReference like: TFunction<"my-custom-namespace">
|
|
615
|
+
if (typeAnn && (typeAnn.type === 'TsTypeReference' || typeAnn.type === 'TsTypeRef' || typeAnn.type === 'TsTypeReference')) {
|
|
616
|
+
const finalTypeName = extractTypeName(typeAnn);
|
|
617
|
+
if (finalTypeName === 'TFunction') {
|
|
618
|
+
// support multiple AST shapes for type parameters:
|
|
619
|
+
// - typeAnn.typeParameters?.params?.[0]
|
|
620
|
+
// - typeAnn.typeArguments?.params?.[0]
|
|
621
|
+
// - typeAnn.typeParams?.[0] / typeAnn.params?.[0]
|
|
622
|
+
const candidates = [
|
|
623
|
+
typeAnn.typeParameters?.params?.[0],
|
|
624
|
+
typeAnn.typeParameters?.[0],
|
|
625
|
+
typeAnn.typeArguments?.params?.[0],
|
|
626
|
+
typeAnn.typeArguments?.[0],
|
|
627
|
+
typeAnn.typeParams?.params?.[0],
|
|
628
|
+
typeAnn.typeParams?.[0],
|
|
629
|
+
typeAnn.params?.[0],
|
|
630
|
+
typeAnn.args?.[0],
|
|
631
|
+
typeAnn.typeParameters, // fallback if it's directly the literal
|
|
632
|
+
typeAnn.typeArguments,
|
|
633
|
+
typeAnn.typeParams,
|
|
634
|
+
];
|
|
635
|
+
let tp;
|
|
636
|
+
for (const c of candidates) {
|
|
637
|
+
if (c) {
|
|
638
|
+
tp = c;
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const ns = extractStringLiteralValue(tp);
|
|
643
|
+
// Extract the second type parameter for KPrefix
|
|
644
|
+
// We need to find the second element from the same type parameter list
|
|
645
|
+
const typeParams = typeAnn.typeParameters?.params ??
|
|
646
|
+
typeAnn.typeArguments?.params ??
|
|
647
|
+
typeAnn.typeParams?.params ??
|
|
648
|
+
undefined;
|
|
649
|
+
let kpFromType;
|
|
650
|
+
if (typeParams && typeParams.length >= 2) {
|
|
651
|
+
kpFromType = extractStringLiteralValue(typeParams[1]);
|
|
652
|
+
}
|
|
653
|
+
if (ns || kpFromType) {
|
|
654
|
+
this.scopeManager.setVarInScope(paramKey, {
|
|
655
|
+
defaultNs: ns,
|
|
656
|
+
keyPrefix: kpFromType // honour TFunction<Ns, KPrefix>
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Find the raw type node of a named member on an object-shaped type
|
|
664
|
+
* annotation (inline `{ t: TFunction<'ns'> }` or a local interface / type
|
|
665
|
+
* alias name).
|
|
666
|
+
*/
|
|
667
|
+
getMemberTypeNode(tsType, memberName) {
|
|
668
|
+
if (!tsType)
|
|
669
|
+
return undefined;
|
|
670
|
+
let members;
|
|
671
|
+
if (tsType.type === 'TsTypeLiteral')
|
|
672
|
+
members = tsType.members;
|
|
673
|
+
else if (tsType.type === 'TsTypeReference' && tsType.typeName?.type === 'Identifier') {
|
|
674
|
+
members = this.expressionResolver.getObjectTypeMembersRaw(tsType.typeName.value);
|
|
675
|
+
}
|
|
676
|
+
if (!Array.isArray(members))
|
|
677
|
+
return undefined;
|
|
678
|
+
for (const m of members) {
|
|
679
|
+
if (m?.type !== 'TsPropertySignature')
|
|
680
|
+
continue;
|
|
681
|
+
const name = m.key?.type === 'Identifier' || m.key?.type === 'StringLiteral' ? m.key.value : undefined;
|
|
682
|
+
if (name === memberName)
|
|
683
|
+
return m.typeAnnotation?.typeAnnotation ?? m.typeAnnotation;
|
|
684
|
+
}
|
|
685
|
+
return undefined;
|
|
686
|
+
}
|
|
653
687
|
/**
|
|
654
688
|
* If `node` is a call like `ARRAY.map(param => ...)` where ARRAY is a known
|
|
655
689
|
* string-array constant, returns the callback's first parameter name and the
|
|
@@ -30,6 +30,8 @@ class ExpressionResolver {
|
|
|
30
30
|
// type aliases. Maps typeName -> { memberName: possible string values }.
|
|
31
31
|
// e.g. `interface IProps { size: ChangeType }` -> { IProps: { size: ['all','next'] } }
|
|
32
32
|
objectTypeTable = new Map();
|
|
33
|
+
// Raw TS member nodes of local interfaces / object type aliases, keyed by type name.
|
|
34
|
+
objectTypeMembersRaw = new Map();
|
|
33
35
|
// Temporary per-scope bindings for identifiers holding an object-shaped type,
|
|
34
36
|
// e.g. `function f(props: IProps)` -> { props: { size: ['all','next'] } }.
|
|
35
37
|
temporaryObjectVariables = new Map();
|
|
@@ -236,6 +238,7 @@ class ExpressionResolver {
|
|
|
236
238
|
return;
|
|
237
239
|
// `type IProps = { size: ChangeType }` — object shape, not a string union.
|
|
238
240
|
if (tsType.type === 'TsTypeLiteral') {
|
|
241
|
+
this.objectTypeMembersRaw.set(name, tsType.members);
|
|
239
242
|
const members = this.collectObjectTypeMembers(tsType.members);
|
|
240
243
|
if (members)
|
|
241
244
|
this.objectTypeTable.set(name, members);
|
|
@@ -264,6 +267,8 @@ class ExpressionResolver {
|
|
|
264
267
|
const name = node?.id?.type === 'Identifier' ? node.id.value : undefined;
|
|
265
268
|
if (!name)
|
|
266
269
|
return;
|
|
270
|
+
if (Array.isArray(node?.body?.body))
|
|
271
|
+
this.objectTypeMembersRaw.set(name, node.body.body);
|
|
267
272
|
const members = this.collectObjectTypeMembers(node?.body?.body);
|
|
268
273
|
if (members)
|
|
269
274
|
this.objectTypeTable.set(name, members);
|
|
@@ -300,6 +305,9 @@ class ExpressionResolver {
|
|
|
300
305
|
* Resolve a type annotation that refers to an object shape (interface, object
|
|
301
306
|
* type alias, or inline type literal) to its member → string values map.
|
|
302
307
|
*/
|
|
308
|
+
getObjectTypeMembersRaw(name) {
|
|
309
|
+
return this.objectTypeMembersRaw.get(name);
|
|
310
|
+
}
|
|
303
311
|
resolveTypeMembers(tsType) {
|
|
304
312
|
try {
|
|
305
313
|
if (!tsType)
|
|
@@ -550,6 +550,12 @@ class ScopeManager {
|
|
|
550
550
|
return { defaultNs: this.resolveSimpleStringIdentifier(nsNode.value) };
|
|
551
551
|
if (nsNode.type === 'MemberExpression')
|
|
552
552
|
return { defaultNs: this.resolveSimpleMemberExpression(nsNode) };
|
|
553
|
+
// `useTranslation(ns ?? 'fallback')` / `useTranslation(ns || 'fallback')`:
|
|
554
|
+
// prefer a statically resolvable left side, otherwise use the fallback.
|
|
555
|
+
if (nsNode.type === 'BinaryExpression' && (nsNode.operator === '??' || nsNode.operator === '||')) {
|
|
556
|
+
const left = this.resolveNsArg(nsNode.left);
|
|
557
|
+
return left.defaultNs !== undefined ? left : this.resolveNsArg(nsNode.right);
|
|
558
|
+
}
|
|
553
559
|
if (nsNode.type === 'ArrayExpression') {
|
|
554
560
|
const namespaces = [];
|
|
555
561
|
for (const el of nsNode.elements) {
|
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.
|
|
34
|
+
.version('1.70.0'); // 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
|
|
@@ -228,22 +228,24 @@ class ASTVisitors {
|
|
|
228
228
|
if (pat.type === 'ObjectPattern') {
|
|
229
229
|
const patType = pat.typeAnnotation?.typeAnnotation ?? pat.typeAnnotation;
|
|
230
230
|
const members = this.expressionResolver.resolveTypeMembers(patType);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
231
|
+
for (const prop of (pat.properties ?? [])) {
|
|
232
|
+
// `{ size }` / `{ size = 'all' }` → AssignmentPatternProperty (local name is the key)
|
|
233
|
+
// `{ size: s }` / `{ size: s = 'all' }` → KeyValuePatternProperty
|
|
234
|
+
const memberName = prop?.key?.value;
|
|
235
|
+
let localNode = prop?.type === 'KeyValuePatternProperty' ? prop.value : prop?.key;
|
|
236
|
+
if (localNode?.type === 'AssignmentPattern')
|
|
237
|
+
localNode = localNode.left;
|
|
238
|
+
const localName = localNode?.type === 'Identifier' ? localNode.value : undefined;
|
|
239
|
+
if (!memberName || !localName)
|
|
240
|
+
continue;
|
|
241
|
+
// `({ t }: { t: TFunction<'ns'> })` → bind `t` to that namespace
|
|
242
|
+
this.bindTFunctionParam(localName, this.getMemberTypeNode(patType, memberName));
|
|
243
|
+
if (!members?.[memberName])
|
|
244
|
+
continue;
|
|
245
|
+
this.expressionResolver.setTemporaryVariable(localName, members[memberName]);
|
|
246
|
+
if (!paramTemporaries)
|
|
247
|
+
paramTemporaries = [];
|
|
248
|
+
paramTemporaries.push(localName);
|
|
247
249
|
}
|
|
248
250
|
continue;
|
|
249
251
|
}
|
|
@@ -290,103 +292,7 @@ class ASTVisitors {
|
|
|
290
292
|
else {
|
|
291
293
|
typeAnn = undefined;
|
|
292
294
|
}
|
|
293
|
-
|
|
294
|
-
const extractTypeName = (ta) => {
|
|
295
|
-
if (!ta)
|
|
296
|
-
return undefined;
|
|
297
|
-
// Identifier style: { type: 'Identifier', value: 'TFunction' } OR { name: 'TFunction' }
|
|
298
|
-
if (ta.typeName && (ta.typeName.type === 'Identifier'))
|
|
299
|
-
return ta.typeName.value ?? ta.typeName.name;
|
|
300
|
-
if (ta.typeName && ta.typeName.type === 'TsQualifiedName') {
|
|
301
|
-
// Qualified like Foo.TFunction -> try right side
|
|
302
|
-
const right = (ta.typeName.right ?? ta.typeName);
|
|
303
|
-
return right?.value ?? right?.name;
|
|
304
|
-
}
|
|
305
|
-
if (ta.typeName && typeof ta.typeName === 'string')
|
|
306
|
-
return ta.typeName;
|
|
307
|
-
if (ta.type === 'Identifier')
|
|
308
|
-
return ta.value ?? ta.name;
|
|
309
|
-
if (ta.id)
|
|
310
|
-
return ta.id?.value ?? ta.id?.name ?? ta.id;
|
|
311
|
-
return undefined;
|
|
312
|
-
};
|
|
313
|
-
const extractStringLiteralValue = (node) => {
|
|
314
|
-
if (!node)
|
|
315
|
-
return undefined;
|
|
316
|
-
// Handle: typeof SomeConst → TsTypeQuery { exprName: { value: 'SomeConst' } }
|
|
317
|
-
if (node?.type === 'TsTypeQuery') {
|
|
318
|
-
const name = node.exprName?.value ?? node.exprName?.name;
|
|
319
|
-
if (name)
|
|
320
|
-
return this.scopeManager.resolveSimpleStringIdentifier(name);
|
|
321
|
-
}
|
|
322
|
-
// shapes: TsLiteralType -> { literal: { type: 'StringLiteral', value: 'x' } }
|
|
323
|
-
if (node.type === 'TsLiteralType' && node.literal)
|
|
324
|
-
return node.literal.value ?? node.literal.raw;
|
|
325
|
-
if (node.type === 'StringLiteral' || node.type === 'Str' || node.type === 'Literal')
|
|
326
|
-
return node.value ?? node.raw ?? node.value;
|
|
327
|
-
if (node.literal && (node.literal.type === 'StringLiteral' || node.literal.type === 'Str'))
|
|
328
|
-
return node.literal.value;
|
|
329
|
-
// some SWC builds put the string directly on .value
|
|
330
|
-
if (typeof node.value === 'string')
|
|
331
|
-
return node.value;
|
|
332
|
-
// handle wrapped parameter like { params: [ ... ] } where a literal might be one level deeper
|
|
333
|
-
if (node.params && Array.isArray(node.params) && node.params[0])
|
|
334
|
-
return extractStringLiteralValue(node.params[0]);
|
|
335
|
-
if (node.typeArguments && Array.isArray(node.typeArguments) && node.typeArguments[0])
|
|
336
|
-
return extractStringLiteralValue(node.typeArguments[0]);
|
|
337
|
-
if (node.typeParameters && Array.isArray(node.typeParameters) && node.typeParameters[0])
|
|
338
|
-
return extractStringLiteralValue(node.typeParameters[0]);
|
|
339
|
-
if (node.typeParams && Array.isArray(node.typeParams) && node.typeParams[0])
|
|
340
|
-
return extractStringLiteralValue(node.typeParams[0]);
|
|
341
|
-
return undefined;
|
|
342
|
-
};
|
|
343
|
-
// Detect TsTypeReference like: TFunction<"my-custom-namespace">
|
|
344
|
-
if (typeAnn && (typeAnn.type === 'TsTypeReference' || typeAnn.type === 'TsTypeRef' || typeAnn.type === 'TsTypeReference')) {
|
|
345
|
-
const finalTypeName = extractTypeName(typeAnn);
|
|
346
|
-
if (finalTypeName === 'TFunction') {
|
|
347
|
-
// support multiple AST shapes for type parameters:
|
|
348
|
-
// - typeAnn.typeParameters?.params?.[0]
|
|
349
|
-
// - typeAnn.typeArguments?.params?.[0]
|
|
350
|
-
// - typeAnn.typeParams?.[0] / typeAnn.params?.[0]
|
|
351
|
-
const candidates = [
|
|
352
|
-
typeAnn.typeParameters?.params?.[0],
|
|
353
|
-
typeAnn.typeParameters?.[0],
|
|
354
|
-
typeAnn.typeArguments?.params?.[0],
|
|
355
|
-
typeAnn.typeArguments?.[0],
|
|
356
|
-
typeAnn.typeParams?.params?.[0],
|
|
357
|
-
typeAnn.typeParams?.[0],
|
|
358
|
-
typeAnn.params?.[0],
|
|
359
|
-
typeAnn.args?.[0],
|
|
360
|
-
typeAnn.typeParameters, // fallback if it's directly the literal
|
|
361
|
-
typeAnn.typeArguments,
|
|
362
|
-
typeAnn.typeParams,
|
|
363
|
-
];
|
|
364
|
-
let tp;
|
|
365
|
-
for (const c of candidates) {
|
|
366
|
-
if (c) {
|
|
367
|
-
tp = c;
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const ns = extractStringLiteralValue(tp);
|
|
372
|
-
// Extract the second type parameter for KPrefix
|
|
373
|
-
// We need to find the second element from the same type parameter list
|
|
374
|
-
const typeParams = typeAnn.typeParameters?.params ??
|
|
375
|
-
typeAnn.typeArguments?.params ??
|
|
376
|
-
typeAnn.typeParams?.params ??
|
|
377
|
-
undefined;
|
|
378
|
-
let kpFromType;
|
|
379
|
-
if (typeParams && typeParams.length >= 2) {
|
|
380
|
-
kpFromType = extractStringLiteralValue(typeParams[1]);
|
|
381
|
-
}
|
|
382
|
-
if (ns || kpFromType) {
|
|
383
|
-
this.scopeManager.setVarInScope(paramKey, {
|
|
384
|
-
defaultNs: ns,
|
|
385
|
-
keyPrefix: kpFromType // honour TFunction<Ns, KPrefix>
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
295
|
+
this.bindTFunctionParam(paramKey, typeAnn);
|
|
390
296
|
// Capture parameter type annotations as temporary variables in the
|
|
391
297
|
// expression resolver so that dynamic bracket expressions like
|
|
392
298
|
// `t(($) => $.table.columns[field])` can resolve `field` to its
|
|
@@ -648,6 +554,134 @@ class ASTVisitors {
|
|
|
648
554
|
this.scopeManager.exitClassScope();
|
|
649
555
|
}
|
|
650
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* If `typeAnn` is a `TFunction<Ns, KPrefix>` type reference, register
|
|
559
|
+
* `paramKey` in the current scope with that namespace / keyPrefix.
|
|
560
|
+
*/
|
|
561
|
+
bindTFunctionParam(paramKey, typeAnn) {
|
|
562
|
+
// Small helpers to robustly extract the referenced type name and literal string
|
|
563
|
+
const extractTypeName = (ta) => {
|
|
564
|
+
if (!ta)
|
|
565
|
+
return undefined;
|
|
566
|
+
// Identifier style: { type: 'Identifier', value: 'TFunction' } OR { name: 'TFunction' }
|
|
567
|
+
if (ta.typeName && (ta.typeName.type === 'Identifier'))
|
|
568
|
+
return ta.typeName.value ?? ta.typeName.name;
|
|
569
|
+
if (ta.typeName && ta.typeName.type === 'TsQualifiedName') {
|
|
570
|
+
// Qualified like Foo.TFunction -> try right side
|
|
571
|
+
const right = (ta.typeName.right ?? ta.typeName);
|
|
572
|
+
return right?.value ?? right?.name;
|
|
573
|
+
}
|
|
574
|
+
if (ta.typeName && typeof ta.typeName === 'string')
|
|
575
|
+
return ta.typeName;
|
|
576
|
+
if (ta.type === 'Identifier')
|
|
577
|
+
return ta.value ?? ta.name;
|
|
578
|
+
if (ta.id)
|
|
579
|
+
return ta.id?.value ?? ta.id?.name ?? ta.id;
|
|
580
|
+
return undefined;
|
|
581
|
+
};
|
|
582
|
+
const extractStringLiteralValue = (node) => {
|
|
583
|
+
if (!node)
|
|
584
|
+
return undefined;
|
|
585
|
+
// Handle: typeof SomeConst → TsTypeQuery { exprName: { value: 'SomeConst' } }
|
|
586
|
+
if (node?.type === 'TsTypeQuery') {
|
|
587
|
+
const name = node.exprName?.value ?? node.exprName?.name;
|
|
588
|
+
if (name)
|
|
589
|
+
return this.scopeManager.resolveSimpleStringIdentifier(name);
|
|
590
|
+
}
|
|
591
|
+
// shapes: TsLiteralType -> { literal: { type: 'StringLiteral', value: 'x' } }
|
|
592
|
+
if (node.type === 'TsLiteralType' && node.literal)
|
|
593
|
+
return node.literal.value ?? node.literal.raw;
|
|
594
|
+
if (node.type === 'StringLiteral' || node.type === 'Str' || node.type === 'Literal')
|
|
595
|
+
return node.value ?? node.raw ?? node.value;
|
|
596
|
+
if (node.literal && (node.literal.type === 'StringLiteral' || node.literal.type === 'Str'))
|
|
597
|
+
return node.literal.value;
|
|
598
|
+
// some SWC builds put the string directly on .value
|
|
599
|
+
if (typeof node.value === 'string')
|
|
600
|
+
return node.value;
|
|
601
|
+
// handle wrapped parameter like { params: [ ... ] } where a literal might be one level deeper
|
|
602
|
+
if (node.params && Array.isArray(node.params) && node.params[0])
|
|
603
|
+
return extractStringLiteralValue(node.params[0]);
|
|
604
|
+
if (node.typeArguments && Array.isArray(node.typeArguments) && node.typeArguments[0])
|
|
605
|
+
return extractStringLiteralValue(node.typeArguments[0]);
|
|
606
|
+
if (node.typeParameters && Array.isArray(node.typeParameters) && node.typeParameters[0])
|
|
607
|
+
return extractStringLiteralValue(node.typeParameters[0]);
|
|
608
|
+
if (node.typeParams && Array.isArray(node.typeParams) && node.typeParams[0])
|
|
609
|
+
return extractStringLiteralValue(node.typeParams[0]);
|
|
610
|
+
return undefined;
|
|
611
|
+
};
|
|
612
|
+
// Detect TsTypeReference like: TFunction<"my-custom-namespace">
|
|
613
|
+
if (typeAnn && (typeAnn.type === 'TsTypeReference' || typeAnn.type === 'TsTypeRef' || typeAnn.type === 'TsTypeReference')) {
|
|
614
|
+
const finalTypeName = extractTypeName(typeAnn);
|
|
615
|
+
if (finalTypeName === 'TFunction') {
|
|
616
|
+
// support multiple AST shapes for type parameters:
|
|
617
|
+
// - typeAnn.typeParameters?.params?.[0]
|
|
618
|
+
// - typeAnn.typeArguments?.params?.[0]
|
|
619
|
+
// - typeAnn.typeParams?.[0] / typeAnn.params?.[0]
|
|
620
|
+
const candidates = [
|
|
621
|
+
typeAnn.typeParameters?.params?.[0],
|
|
622
|
+
typeAnn.typeParameters?.[0],
|
|
623
|
+
typeAnn.typeArguments?.params?.[0],
|
|
624
|
+
typeAnn.typeArguments?.[0],
|
|
625
|
+
typeAnn.typeParams?.params?.[0],
|
|
626
|
+
typeAnn.typeParams?.[0],
|
|
627
|
+
typeAnn.params?.[0],
|
|
628
|
+
typeAnn.args?.[0],
|
|
629
|
+
typeAnn.typeParameters, // fallback if it's directly the literal
|
|
630
|
+
typeAnn.typeArguments,
|
|
631
|
+
typeAnn.typeParams,
|
|
632
|
+
];
|
|
633
|
+
let tp;
|
|
634
|
+
for (const c of candidates) {
|
|
635
|
+
if (c) {
|
|
636
|
+
tp = c;
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
const ns = extractStringLiteralValue(tp);
|
|
641
|
+
// Extract the second type parameter for KPrefix
|
|
642
|
+
// We need to find the second element from the same type parameter list
|
|
643
|
+
const typeParams = typeAnn.typeParameters?.params ??
|
|
644
|
+
typeAnn.typeArguments?.params ??
|
|
645
|
+
typeAnn.typeParams?.params ??
|
|
646
|
+
undefined;
|
|
647
|
+
let kpFromType;
|
|
648
|
+
if (typeParams && typeParams.length >= 2) {
|
|
649
|
+
kpFromType = extractStringLiteralValue(typeParams[1]);
|
|
650
|
+
}
|
|
651
|
+
if (ns || kpFromType) {
|
|
652
|
+
this.scopeManager.setVarInScope(paramKey, {
|
|
653
|
+
defaultNs: ns,
|
|
654
|
+
keyPrefix: kpFromType // honour TFunction<Ns, KPrefix>
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Find the raw type node of a named member on an object-shaped type
|
|
662
|
+
* annotation (inline `{ t: TFunction<'ns'> }` or a local interface / type
|
|
663
|
+
* alias name).
|
|
664
|
+
*/
|
|
665
|
+
getMemberTypeNode(tsType, memberName) {
|
|
666
|
+
if (!tsType)
|
|
667
|
+
return undefined;
|
|
668
|
+
let members;
|
|
669
|
+
if (tsType.type === 'TsTypeLiteral')
|
|
670
|
+
members = tsType.members;
|
|
671
|
+
else if (tsType.type === 'TsTypeReference' && tsType.typeName?.type === 'Identifier') {
|
|
672
|
+
members = this.expressionResolver.getObjectTypeMembersRaw(tsType.typeName.value);
|
|
673
|
+
}
|
|
674
|
+
if (!Array.isArray(members))
|
|
675
|
+
return undefined;
|
|
676
|
+
for (const m of members) {
|
|
677
|
+
if (m?.type !== 'TsPropertySignature')
|
|
678
|
+
continue;
|
|
679
|
+
const name = m.key?.type === 'Identifier' || m.key?.type === 'StringLiteral' ? m.key.value : undefined;
|
|
680
|
+
if (name === memberName)
|
|
681
|
+
return m.typeAnnotation?.typeAnnotation ?? m.typeAnnotation;
|
|
682
|
+
}
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
651
685
|
/**
|
|
652
686
|
* If `node` is a call like `ARRAY.map(param => ...)` where ARRAY is a known
|
|
653
687
|
* string-array constant, returns the callback's first parameter name and the
|
|
@@ -28,6 +28,8 @@ class ExpressionResolver {
|
|
|
28
28
|
// type aliases. Maps typeName -> { memberName: possible string values }.
|
|
29
29
|
// e.g. `interface IProps { size: ChangeType }` -> { IProps: { size: ['all','next'] } }
|
|
30
30
|
objectTypeTable = new Map();
|
|
31
|
+
// Raw TS member nodes of local interfaces / object type aliases, keyed by type name.
|
|
32
|
+
objectTypeMembersRaw = new Map();
|
|
31
33
|
// Temporary per-scope bindings for identifiers holding an object-shaped type,
|
|
32
34
|
// e.g. `function f(props: IProps)` -> { props: { size: ['all','next'] } }.
|
|
33
35
|
temporaryObjectVariables = new Map();
|
|
@@ -234,6 +236,7 @@ class ExpressionResolver {
|
|
|
234
236
|
return;
|
|
235
237
|
// `type IProps = { size: ChangeType }` — object shape, not a string union.
|
|
236
238
|
if (tsType.type === 'TsTypeLiteral') {
|
|
239
|
+
this.objectTypeMembersRaw.set(name, tsType.members);
|
|
237
240
|
const members = this.collectObjectTypeMembers(tsType.members);
|
|
238
241
|
if (members)
|
|
239
242
|
this.objectTypeTable.set(name, members);
|
|
@@ -262,6 +265,8 @@ class ExpressionResolver {
|
|
|
262
265
|
const name = node?.id?.type === 'Identifier' ? node.id.value : undefined;
|
|
263
266
|
if (!name)
|
|
264
267
|
return;
|
|
268
|
+
if (Array.isArray(node?.body?.body))
|
|
269
|
+
this.objectTypeMembersRaw.set(name, node.body.body);
|
|
265
270
|
const members = this.collectObjectTypeMembers(node?.body?.body);
|
|
266
271
|
if (members)
|
|
267
272
|
this.objectTypeTable.set(name, members);
|
|
@@ -298,6 +303,9 @@ class ExpressionResolver {
|
|
|
298
303
|
* Resolve a type annotation that refers to an object shape (interface, object
|
|
299
304
|
* type alias, or inline type literal) to its member → string values map.
|
|
300
305
|
*/
|
|
306
|
+
getObjectTypeMembersRaw(name) {
|
|
307
|
+
return this.objectTypeMembersRaw.get(name);
|
|
308
|
+
}
|
|
301
309
|
resolveTypeMembers(tsType) {
|
|
302
310
|
try {
|
|
303
311
|
if (!tsType)
|
|
@@ -548,6 +548,12 @@ class ScopeManager {
|
|
|
548
548
|
return { defaultNs: this.resolveSimpleStringIdentifier(nsNode.value) };
|
|
549
549
|
if (nsNode.type === 'MemberExpression')
|
|
550
550
|
return { defaultNs: this.resolveSimpleMemberExpression(nsNode) };
|
|
551
|
+
// `useTranslation(ns ?? 'fallback')` / `useTranslation(ns || 'fallback')`:
|
|
552
|
+
// prefer a statically resolvable left side, otherwise use the fallback.
|
|
553
|
+
if (nsNode.type === 'BinaryExpression' && (nsNode.operator === '??' || nsNode.operator === '||')) {
|
|
554
|
+
const left = this.resolveNsArg(nsNode.left);
|
|
555
|
+
return left.defaultNs !== undefined ? left : this.resolveNsArg(nsNode.right);
|
|
556
|
+
}
|
|
551
557
|
if (nsNode.type === 'ArrayExpression') {
|
|
552
558
|
const namespaces = [];
|
|
553
559
|
for (const el of nsNode.elements) {
|
package/package.json
CHANGED
|
@@ -85,6 +85,17 @@ export declare class ASTVisitors {
|
|
|
85
85
|
* @private
|
|
86
86
|
*/
|
|
87
87
|
private walk;
|
|
88
|
+
/**
|
|
89
|
+
* If `typeAnn` is a `TFunction<Ns, KPrefix>` type reference, register
|
|
90
|
+
* `paramKey` in the current scope with that namespace / keyPrefix.
|
|
91
|
+
*/
|
|
92
|
+
private bindTFunctionParam;
|
|
93
|
+
/**
|
|
94
|
+
* Find the raw type node of a named member on an object-shaped type
|
|
95
|
+
* annotation (inline `{ t: TFunction<'ns'> }` or a local interface / type
|
|
96
|
+
* alias name).
|
|
97
|
+
*/
|
|
98
|
+
private getMemberTypeNode;
|
|
88
99
|
/**
|
|
89
100
|
* If `node` is a call like `ARRAY.map(param => ...)` where ARRAY is a known
|
|
90
101
|
* string-array constant, returns the callback's first parameter name and the
|
|
@@ -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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,cAAc,IAAK,MAAM;IAIhC;;OAEG;IACI,cAAc,IAAK,MAAM;CAGjC"}
|
|
@@ -10,6 +10,7 @@ export declare class ExpressionResolver {
|
|
|
10
10
|
private sharedFunctionReturnTable;
|
|
11
11
|
private temporaryVariables;
|
|
12
12
|
private objectTypeTable;
|
|
13
|
+
private objectTypeMembersRaw;
|
|
13
14
|
private temporaryObjectVariables;
|
|
14
15
|
private arrayElementMembers;
|
|
15
16
|
constructor(hooks: ASTVisitorHooks);
|
|
@@ -55,6 +56,7 @@ export declare class ExpressionResolver {
|
|
|
55
56
|
* Resolve a type annotation that refers to an object shape (interface, object
|
|
56
57
|
* type alias, or inline type literal) to its member → string values map.
|
|
57
58
|
*/
|
|
59
|
+
getObjectTypeMembersRaw(name: string): any[] | undefined;
|
|
58
60
|
resolveTypeMembers(tsType: any): Record<string, string[]> | undefined;
|
|
59
61
|
/**
|
|
60
62
|
* Resolve a type annotation for an array of an object shape (`IProps[]`,
|
|
@@ -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,CAAA;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAiB;IAK9B,OAAO,CAAC,aAAa,CAA4D;IAGjF,OAAO,CAAC,eAAe,CAAiD;IAIxE,OAAO,CAAC,cAAc,CAAmC;IAIzD,OAAO,CAAC,mBAAmB,CAAmC;IAI9D,OAAO,CAAC,oBAAoB,CAAmC;IAM/D,OAAO,CAAC,yBAAyB,CAAmC;IAIpE,OAAO,CAAC,kBAAkB,CAAmC;IAK7D,OAAO,CAAC,eAAe,CAAmD;
|
|
1
|
+
{"version":3,"file":"expression-resolver.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/expression-resolver.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