i18next-cli 1.10.1 → 1.10.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +3 -0
  3. package/dist/cjs/cli.js +1 -1
  4. package/dist/cjs/extractor/core/ast-visitors.js +1 -0
  5. package/dist/cjs/extractor/core/key-finder.js +1 -1
  6. package/dist/cjs/extractor/core/translation-manager.js +1 -1
  7. package/dist/cjs/extractor/parsers/call-expression-handler.js +1 -0
  8. package/dist/cjs/extractor/parsers/expression-resolver.js +1 -0
  9. package/dist/cjs/extractor/parsers/jsx-handler.js +1 -0
  10. package/dist/cjs/extractor/parsers/scope-manager.js +1 -0
  11. package/dist/esm/cli.js +1 -1
  12. package/dist/esm/extractor/core/ast-visitors.js +1 -0
  13. package/dist/esm/extractor/core/key-finder.js +1 -1
  14. package/dist/esm/extractor/core/translation-manager.js +1 -1
  15. package/dist/esm/extractor/parsers/call-expression-handler.js +1 -0
  16. package/dist/esm/extractor/parsers/expression-resolver.js +1 -0
  17. package/dist/esm/extractor/parsers/jsx-handler.js +1 -0
  18. package/dist/esm/extractor/parsers/scope-manager.js +1 -0
  19. package/package.json +1 -1
  20. package/src/cli.ts +1 -1
  21. package/src/extractor/core/ast-visitors.ts +170 -0
  22. package/src/extractor/core/extractor.ts +1 -1
  23. package/src/extractor/core/key-finder.ts +2 -2
  24. package/src/extractor/core/translation-manager.ts +88 -8
  25. package/src/extractor/index.ts +1 -1
  26. package/src/extractor/parsers/call-expression-handler.ts +506 -0
  27. package/src/extractor/parsers/expression-resolver.ts +178 -0
  28. package/src/extractor/parsers/jsx-handler.ts +358 -0
  29. package/src/extractor/parsers/scope-manager.ts +327 -0
  30. package/src/extractor.ts +1 -1
  31. package/src/types.ts +82 -0
  32. package/types/extractor/core/ast-visitors.d.ts +75 -0
  33. package/types/extractor/core/ast-visitors.d.ts.map +1 -0
  34. package/types/extractor/core/extractor.d.ts +1 -1
  35. package/types/extractor/core/extractor.d.ts.map +1 -1
  36. package/types/extractor/core/key-finder.d.ts.map +1 -1
  37. package/types/extractor/core/translation-manager.d.ts.map +1 -1
  38. package/types/extractor/index.d.ts +1 -1
  39. package/types/extractor/index.d.ts.map +1 -1
  40. package/types/extractor/parsers/call-expression-handler.d.ts +74 -0
  41. package/types/extractor/parsers/call-expression-handler.d.ts.map +1 -0
  42. package/types/extractor/parsers/expression-resolver.d.ts +62 -0
  43. package/types/extractor/parsers/expression-resolver.d.ts.map +1 -0
  44. package/types/extractor/parsers/jsx-handler.d.ts +44 -0
  45. package/types/extractor/parsers/jsx-handler.d.ts.map +1 -0
  46. package/types/extractor/parsers/scope-manager.d.ts +99 -0
  47. package/types/extractor/parsers/scope-manager.d.ts.map +1 -0
  48. package/types/extractor.d.ts +1 -1
  49. package/types/extractor.d.ts.map +1 -1
  50. package/types/types.d.ts +77 -0
  51. package/types/types.d.ts.map +1 -1
  52. package/dist/cjs/extractor/parsers/ast-visitors.js +0 -1
  53. package/dist/esm/extractor/parsers/ast-visitors.js +0 -1
  54. package/src/extractor/parsers/ast-visitors.ts +0 -1510
  55. package/types/extractor/parsers/ast-visitors.d.ts +0 -352
  56. package/types/extractor/parsers/ast-visitors.d.ts.map +0 -1
@@ -0,0 +1,62 @@
1
+ import type { Expression } from '@swc/core';
2
+ import type { ASTVisitorHooks } from '../../types';
3
+ export declare class ExpressionResolver {
4
+ private hooks;
5
+ constructor(hooks: ASTVisitorHooks);
6
+ /**
7
+ * Resolves an expression to one or more possible context string values that can be
8
+ * determined statically from the AST. This is a wrapper around the plugin hook
9
+ * `extractContextFromExpression` and {@link resolvePossibleStringValuesFromExpression}.
10
+ *
11
+ * @param expression - The SWC AST expression node to resolve
12
+ * @returns An array of possible context string values that the expression may produce.
13
+ */
14
+ resolvePossibleContextStringValues(expression: Expression): string[];
15
+ /**
16
+ * Resolves an expression to one or more possible key string values that can be
17
+ * determined statically from the AST. This is a wrapper around the plugin hook
18
+ * `extractKeysFromExpression` and {@link resolvePossibleStringValuesFromExpression}.
19
+ *
20
+ * @param expression - The SWC AST expression node to resolve
21
+ * @returns An array of possible key string values that the expression may produce.
22
+ */
23
+ resolvePossibleKeyStringValues(expression: Expression): string[];
24
+ /**
25
+ * Resolves an expression to one or more possible string values that can be
26
+ * determined statically from the AST.
27
+ *
28
+ * Supports:
29
+ * - StringLiteral -> single value (filtered to exclude empty strings for context)
30
+ * - NumericLiteral -> single value
31
+ * - BooleanLiteral -> single value
32
+ * - ConditionalExpression (ternary) -> union of consequent and alternate resolved values
33
+ * - TemplateLiteral -> union of all possible string values
34
+ * - The identifier `undefined` -> empty array
35
+ *
36
+ * For any other expression types (identifiers, function calls, member expressions,
37
+ * etc.) the value cannot be determined statically and an empty array is returned.
38
+ *
39
+ * @param expression - The SWC AST expression node to resolve
40
+ * @param returnEmptyStrings - Whether to include empty strings in the result
41
+ * @returns An array of possible string values that the expression may produce.
42
+ */
43
+ private resolvePossibleStringValuesFromExpression;
44
+ private resolvePossibleStringValuesFromType;
45
+ /**
46
+ * Resolves a template literal string to one or more possible strings that can be
47
+ * determined statically from the AST.
48
+ *
49
+ * @param templateString - The SWC AST template literal string to resolve
50
+ * @returns An array of possible string values that the template may produce.
51
+ */
52
+ private resolvePossibleStringValuesFromTemplateString;
53
+ /**
54
+ * Resolves a template literal type to one or more possible strings that can be
55
+ * determined statically from the AST.
56
+ *
57
+ * @param templateLiteralType - The SWC AST template literal type to resolve
58
+ * @returns An array of possible string values that the template may produce.
59
+ */
60
+ private resolvePossibleStringValuesFromTemplateLiteralType;
61
+ }
62
+ //# sourceMappingURL=expression-resolver.d.ts.map
@@ -0,0 +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,aAAa,CAAA;AAElD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAiB;gBAEjB,KAAK,EAAE,eAAe;IAInC;;;;;;;OAOG;IACH,kCAAkC,CAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE;IAKrE;;;;;;;OAOG;IACH,8BAA8B,CAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE;IAKjE;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,yCAAyC;IAmCjD,OAAO,CAAC,mCAAmC;IAwB3C;;;;;;OAMG;IACH,OAAO,CAAC,6CAA6C;IAyBrD;;;;;;OAMG;IACH,OAAO,CAAC,kDAAkD;CAwB3D"}
@@ -0,0 +1,44 @@
1
+ import type { JSXElement } from '@swc/core';
2
+ import type { PluginContext, I18nextToolkitConfig } from '../../types';
3
+ import { ExpressionResolver } from './expression-resolver';
4
+ export declare class JSXHandler {
5
+ private config;
6
+ private pluginContext;
7
+ private expressionResolver;
8
+ constructor(config: Omit<I18nextToolkitConfig, 'plugins'>, pluginContext: PluginContext, expressionResolver: ExpressionResolver);
9
+ /**
10
+ * Processes JSX elements to extract translation keys from Trans components.
11
+ *
12
+ * Identifies configured Trans components and delegates to the JSX parser
13
+ * for complex children serialization and attribute extraction.
14
+ *
15
+ * @param node - JSX element node to process
16
+ * @param getScopeInfo - Function to retrieve scope information for variables
17
+ */
18
+ handleJSXElement(node: JSXElement, getScopeInfo: (name: string) => {
19
+ defaultNs?: string;
20
+ keyPrefix?: string;
21
+ } | undefined): void;
22
+ /**
23
+ * Generates plural keys for Trans components, with support for tOptions plural defaults.
24
+ *
25
+ * @param key - Base key name for pluralization
26
+ * @param defaultValue - Default value for the keys
27
+ * @param ns - Namespace for the keys
28
+ * @param isOrdinal - Whether to generate ordinal plural forms
29
+ * @param optionsNode - Optional tOptions object expression for plural-specific defaults
30
+ */
31
+ private generatePluralKeysForTrans;
32
+ /**
33
+ * Extracts element name from JSX opening tag.
34
+ *
35
+ * Handles both simple identifiers and member expressions:
36
+ * - `<Trans>` → 'Trans'
37
+ * - `<React.Trans>` → 'React.Trans'
38
+ *
39
+ * @param node - JSX element node
40
+ * @returns Element name or undefined if not extractable
41
+ */
42
+ private getElementName;
43
+ }
44
+ //# sourceMappingURL=jsx-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAgB,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAI1D,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,kBAAkB,CAAoB;gBAG5C,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB;IAOxC;;;;;;;;OAQG;IACH,gBAAgB,CAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,IAAI;IAyOjI;;;;;;;;OAQG;IACH,OAAO,CAAC,0BAA0B;IA4DlC;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
@@ -0,0 +1,99 @@
1
+ import type { VariableDeclarator } from '@swc/core';
2
+ import type { ScopeInfo, I18nextToolkitConfig } from '../../types';
3
+ export declare class ScopeManager {
4
+ private scopeStack;
5
+ private config;
6
+ private scope;
7
+ constructor(config: Omit<I18nextToolkitConfig, 'plugins'>);
8
+ /**
9
+ * Enters a new variable scope by pushing a new scope map onto the stack.
10
+ * Used when entering functions to isolate variable declarations.
11
+ */
12
+ enterScope(): void;
13
+ /**
14
+ * Exits the current variable scope by popping the top scope map.
15
+ * Used when leaving functions to clean up variable tracking.
16
+ */
17
+ exitScope(): void;
18
+ /**
19
+ * Stores variable information in the current scope.
20
+ * Used to track translation functions and their configuration.
21
+ *
22
+ * @param name - Variable name to store
23
+ * @param info - Scope information about the variable
24
+ */
25
+ setVarInScope(name: string, info: ScopeInfo): void;
26
+ /**
27
+ * Retrieves variable information from the scope chain.
28
+ * Searches from innermost to outermost scope.
29
+ *
30
+ * @param name - Variable name to look up
31
+ * @returns Scope information if found, undefined otherwise
32
+ */
33
+ getVarFromScope(name: string): ScopeInfo | undefined;
34
+ /**
35
+ * Handles variable declarations that might define translation functions.
36
+ *
37
+ * Processes two patterns:
38
+ * 1. `const { t } = useTranslation(...)` - React i18next pattern
39
+ * 2. `const t = i18next.getFixedT(...)` - Core i18next pattern
40
+ *
41
+ * Extracts namespace and key prefix information for later use.
42
+ *
43
+ * @param node - Variable declarator node to process
44
+ */
45
+ handleVariableDeclarator(node: VariableDeclarator): void;
46
+ /**
47
+ * Handles useTranslation calls for comment scope resolution.
48
+ * This is a separate method to store scope info in the legacy scope map
49
+ * that the comment parser can access.
50
+ *
51
+ * @param node - Variable declarator with useTranslation call
52
+ * @param callExpr - The CallExpression node representing the useTranslation invocation
53
+ * @param hookConfig - Configuration describing argument positions for namespace and keyPrefix
54
+ */
55
+ private getUseTranslationConfig;
56
+ /**
57
+ * Processes useTranslation hook declarations to extract scope information.
58
+ *
59
+ * Handles various destructuring patterns:
60
+ * - `const [t] = useTranslation('ns')` - Array destructuring
61
+ * - `const { t } = useTranslation('ns')` - Object destructuring
62
+ * - `const { t: myT } = useTranslation('ns')` - Aliased destructuring
63
+ *
64
+ * Extracts namespace from the first argument and keyPrefix from options.
65
+ *
66
+ * @param node - Variable declarator with useTranslation call
67
+ * @param callExpr - The CallExpression node representing the useTranslation invocation
68
+ * @param hookConfig - Configuration describing argument positions for namespace and keyPrefix
69
+ */
70
+ private handleUseTranslationForComments;
71
+ /**
72
+ * Processes useTranslation hook declarations to extract scope information.
73
+ *
74
+ * Handles various destructuring patterns:
75
+ * - `const [t] = useTranslation('ns')` - Array destructuring
76
+ * - `const { t } = useTranslation('ns')` - Object destructuring
77
+ * - `const { t: myT } = useTranslation('ns')` - Aliased destructuring
78
+ *
79
+ * Extracts namespace from the first argument and keyPrefix from options.
80
+ *
81
+ * @param node - Variable declarator with useTranslation call
82
+ * @param callExpr - The CallExpression node representing the useTranslation invocation
83
+ * @param hookConfig - Configuration describing argument positions for namespace and keyPrefix
84
+ */
85
+ private handleUseTranslationDeclarator;
86
+ /**
87
+ * Processes getFixedT function declarations to extract scope information.
88
+ *
89
+ * Handles the pattern: `const t = i18next.getFixedT(lng, ns, keyPrefix)`
90
+ * - Ignores the first argument (language)
91
+ * - Extracts namespace from the second argument
92
+ * - Extracts key prefix from the third argument
93
+ *
94
+ * @param node - Variable declarator with getFixedT call
95
+ * @param callExpr - The CallExpression node representing the getFixedT invocation
96
+ */
97
+ private handleGetFixedTDeclarator;
98
+ }
99
+ //# sourceMappingURL=scope-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/scope-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,WAAW,CAAA;AACnE,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;gBAErE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IAI1D;;;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;IAMnD;;;;;;OAMG;IACH,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAkBrD;;;;;;;;;;OAUG;IACH,wBAAwB,CAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAsCzD;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IAoB/B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,+BAA+B;IAmEvC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,8BAA8B;IAwDtC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,yBAAyB;CAmBlC"}
@@ -1,7 +1,7 @@
1
1
  import { runExtractor, extract } from './extractor/core/extractor';
2
2
  import { findKeys } from './extractor/core/key-finder';
3
3
  import { getTranslations } from './extractor/core/translation-manager';
4
- import { ASTVisitors } from './extractor/parsers/ast-visitors';
4
+ import { ASTVisitors } from './extractor/core/ast-visitors';
5
5
  import type { PluginContext } from './types';
6
6
  export { runExtractor, extract, findKeys, getTranslations, ASTVisitors, PluginContext, };
7
7
  //# sourceMappingURL=extractor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../src/extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,WAAW,EACX,aAAa,GACd,CAAA"}
1
+ {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../src/extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,WAAW,EACX,aAAa,GACd,CAAA"}
package/types/types.d.ts CHANGED
@@ -354,4 +354,81 @@ export interface ScopeInfo {
354
354
  /** Key prefix to prepend to all translation keys in this scope */
355
355
  keyPrefix?: string;
356
356
  }
357
+ /**
358
+ * Configuration for useTranslation hook patterns.
359
+ * Defines how to extract namespace and key prefix information from hook calls.
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * // For: const { t } = useTranslation('common', { keyPrefix: 'user' })
364
+ * const config: UseTranslationHookConfig = {
365
+ * name: 'useTranslation',
366
+ * nsArg: 0, // namespace is first argument
367
+ * keyPrefixArg: 1 // keyPrefix is in second argument (options object)
368
+ * }
369
+ * ```
370
+ */
371
+ export interface UseTranslationHookConfig {
372
+ /** The name of the hook function (e.g., 'useTranslation', 'getT') */
373
+ name: string;
374
+ /** Zero-based index of the argument containing the namespace */
375
+ nsArg: number;
376
+ /** Zero-based index of the argument containing options with keyPrefix */
377
+ keyPrefixArg: number;
378
+ }
379
+ /**
380
+ * Optional hooks for customizing AST visitor behavior during extraction.
381
+ * Allows plugins and external code to extend the visitor's capabilities.
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * const hooks: ASTVisitorHooks = {
386
+ * onBeforeVisitNode: (node) => {
387
+ * console.log(`Visiting ${node.type}`)
388
+ * },
389
+ *
390
+ * resolvePossibleKeyStringValues: (expression) => {
391
+ * // Custom logic to extract keys from complex expressions
392
+ * if (isCustomKeyExpression(expression)) {
393
+ * return ['custom.key.1', 'custom.key.2']
394
+ * }
395
+ * return []
396
+ * }
397
+ * }
398
+ * ```
399
+ */
400
+ export interface ASTVisitorHooks {
401
+ /**
402
+ * Called before visiting each AST node during traversal.
403
+ * Useful for logging, debugging, or pre-processing nodes.
404
+ *
405
+ * @param node - The AST node about to be visited
406
+ */
407
+ onBeforeVisitNode?: (node: Node) => void;
408
+ /**
409
+ * Called after visiting each AST node during traversal.
410
+ * Useful for cleanup, post-processing, or collecting statistics.
411
+ *
412
+ * @param node - The AST node that was just visited
413
+ */
414
+ onAfterVisitNode?: (node: Node) => void;
415
+ /**
416
+ * Custom resolver for extracting context values from expressions.
417
+ * Supplements the built-in expression resolution with plugin-specific logic.
418
+ *
419
+ * @param expression - The expression to extract context from
420
+ * @param returnEmptyStrings - Whether to include empty strings in results
421
+ * @returns Array of possible context string values
422
+ */
423
+ resolvePossibleContextStringValues?: (expression: Expression, returnEmptyStrings?: boolean) => string[];
424
+ /**
425
+ * Custom resolver for extracting translation keys from expressions.
426
+ * Supplements the built-in expression resolution with plugin-specific logic.
427
+ *
428
+ * @param expression - The expression to extract keys from
429
+ * @param returnEmptyStrings - Whether to include empty strings in results
430
+ * @returns Array of possible translation key values
431
+ */
432
+ resolvePossibleKeyStringValues?: (expression: Expression, returnEmptyStrings?: boolean) => string[];
433
+ }
357
434
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,2DAA2D;IAC3D,OAAO,EAAE;QACP,oEAAoE;QACpE,KAAK,EAAE,MAAM,GA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,CAAA;IAEvG;;;;;;;OAOG;IACH,8BAA8B,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,kBAAkB,CAAC,EAAE,OAAO,KAAK,MAAM,EAAE,CAAA;CACpG"}
@@ -1 +0,0 @@
1
- "use strict";var e=require("./jsx-parser.js"),t=require("./ast-utils.js");exports.ASTVisitors=class{pluginContext;config;logger;scopeStack=[];hooks;objectKeys=new Set;scope=new Map;constructor(e,t,s,r){this.pluginContext=t,this.config=e,this.logger=s,this.hooks={onBeforeVisitNode:r?.onBeforeVisitNode,onAfterVisitNode:r?.onAfterVisitNode,resolvePossibleKeyStringValues:r?.resolvePossibleKeyStringValues,resolvePossibleContextStringValues:r?.resolvePossibleContextStringValues}}visit(e){this.enterScope(),this.walk(e),this.exitScope()}walk(e){if(!e)return;let t=!1;switch("Function"!==e.type&&"ArrowFunctionExpression"!==e.type&&"FunctionExpression"!==e.type||(this.enterScope(),t=!0),this.hooks.onBeforeVisitNode?.(e),e.type){case"VariableDeclarator":this.handleVariableDeclarator(e);break;case"CallExpression":this.handleCallExpression(e);break;case"JSXElement":this.handleJSXElement(e)}this.hooks.onAfterVisitNode?.(e);for(const t in e){if("span"===t)continue;const s=e[t];if(Array.isArray(s))for(const e of s)e&&"object"==typeof e&&this.walk(e);else s&&"object"==typeof s&&this.walk(s)}t&&this.exitScope()}enterScope(){this.scopeStack.push(new Map)}exitScope(){this.scopeStack.pop()}setVarInScope(e,t){this.scopeStack.length>0&&this.scopeStack[this.scopeStack.length-1].set(e,t)}getVarFromScope(e){for(let t=this.scopeStack.length-1;t>=0;t--)if(this.scopeStack[t].has(e)){return this.scopeStack[t].get(e)}const t=this.scope.get(e);if(t)return t}handleVariableDeclarator(e){const t=e.init;if(!t)return;const s="AwaitExpression"===t.type&&"CallExpression"===t.argument.type?t.argument:"CallExpression"===t.type?t:null;if(!s)return;const r=s.callee;if("Identifier"===r.type){const t=this.getUseTranslationConfig(r.value);if(t)return this.handleUseTranslationDeclarator(e,s,t),void this.handleUseTranslationForComments(e,s,t)}"MemberExpression"===r.type&&"Identifier"===r.property.type&&"getFixedT"===r.property.value&&this.handleGetFixedTDeclarator(e,s)}handleUseTranslationForComments(e,t,s){let r;if("Identifier"===e.id.type&&(r=e.id.value),"ArrayPattern"===e.id.type){const t=e.id.elements[0];"Identifier"===t?.type&&(r=t.value)}if("ObjectPattern"===e.id.type)for(const t of e.id.properties){if("AssignmentPatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value){r="t";break}if("KeyValuePatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value&&"Identifier"===t.value.type){r=t.value.value;break}}if(!r)return;const n=t.arguments?.[s.nsArg]?.expression,i=t.arguments?.[s.keyPrefixArg]?.expression;let o,a;if("StringLiteral"===n?.type?o=n.value:"ArrayExpression"===n?.type&&"StringLiteral"===n.elements[0]?.expression.type&&(o=n.elements[0].expression.value),"ObjectExpression"===i?.type){const e=i.properties.find(e=>"KeyValueProperty"===e.type&&"Identifier"===e.key.type&&"keyPrefix"===e.key.value);"KeyValueProperty"===e?.type&&"StringLiteral"===e.value.type&&(a=e.value.value)}(o||a)&&this.scope.set(r,{defaultNs:o,keyPrefix:a})}handleUseTranslationDeclarator(e,s,r){let n;if("Identifier"===e.id.type&&(n=e.id.value),"ArrayPattern"===e.id.type){const t=e.id.elements[0];"Identifier"===t?.type&&(n=t.value)}if("ObjectPattern"===e.id.type)for(const t of e.id.properties){if("AssignmentPatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value){n="t";break}if("KeyValuePatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value&&"Identifier"===t.value.type){n=t.value.value;break}}if(!n)return;const i=s.arguments?.[r.nsArg]?.expression;let o;"StringLiteral"===i?.type?o=i.value:"ArrayExpression"===i?.type&&"StringLiteral"===i.elements[0]?.expression.type&&(o=i.elements[0].expression.value);const a=s.arguments?.[r.keyPrefixArg]?.expression;let l;if("ObjectExpression"===a?.type){const e=t.getObjectPropValue(a,"keyPrefix");l="string"==typeof e?e:void 0}this.setVarInScope(n,{defaultNs:o,keyPrefix:l})}handleGetFixedTDeclarator(e,t){if("Identifier"!==e.id.type||!e.init||"CallExpression"!==e.init.type)return;const s=e.id.value,r=t.arguments,n=r[1]?.expression,i=r[2]?.expression,o="StringLiteral"===n?.type?n.value:void 0,a="StringLiteral"===i?.type?i.value:void 0;(o||a)&&this.setVarInScope(s,{defaultNs:o,keyPrefix:a})}handleCallExpression(e){const s=this.getFunctionName(e.callee);if(!s)return;const r=this.getVarFromScope(s),n=this.config.extract.functions||["t","*.t"];let i=void 0!==r;if(!i)for(const e of n)if(e.startsWith("*.")){if(s.endsWith(e.substring(1))){i=!0;break}}else if(e===s){i=!0;break}if(!i||0===e.arguments.length)return;const{keysToProcess:o,isSelectorAPI:a}=this.handleCallExpressionArgument(e,0);if(0===o.length)return;let l=!1;const u=this.config.extract.pluralSeparator??"_";for(let e=0;e<o.length;e++)o[e].endsWith(`${u}ordinal`)&&(l=!0,o[e]=o[e].slice(0,-8));let p,f;if(e.arguments.length>1){const t=e.arguments[1].expression;"ObjectExpression"===t.type?f=t:"StringLiteral"===t.type&&(p=t.value)}if(e.arguments.length>2){const t=e.arguments[2].expression;"ObjectExpression"===t.type&&(f=t)}const c=f?t.getObjectPropValue(f,"defaultValue"):void 0,y="string"==typeof c?c:p;for(let e=0;e<o.length;e++){let s,n=o[e];if(f){const e=t.getObjectPropValue(f,"ns");"string"==typeof e&&(s=e)}const i=this.config.extract.nsSeparator??":";if(!s&&i&&n.includes(i)){const e=n.split(i);if(s=e.shift(),n=e.join(i),!n||""===n.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${s}${i}'`);continue}}!s&&r?.defaultNs&&(s=r.defaultNs),s||(s=this.config.extract.defaultNS);let u=n;if(r?.keyPrefix){const e=this.config.extract.keySeparator??".";if(u=!1!==e?r.keyPrefix.endsWith(e)?`${r.keyPrefix}${n}`:`${r.keyPrefix}${e}${n}`:`${r.keyPrefix}${n}`,!1!==e){if(u.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${u}' (keyPrefix: '${r.keyPrefix}', key: '${n}')`);continue}}}const p=e===o.length-1&&y||n;if(f){const e=t.getObjectProperty(f,"context"),r=[];if("StringLiteral"===e?.value?.type||"NumericLiteral"===e?.value.type||"BooleanLiteral"===e?.value.type){const t=`${e.value.value}`,n=this.config.extract.contextSeparator??"_";""!==t&&r.push({key:`${u}${n}${t}`,ns:s,defaultValue:p})}else if(e?.value){const t=this.resolvePossibleContextStringValues(e.value),n=this.config.extract.contextSeparator??"_";t.length>0&&(t.forEach(e=>{r.push({key:`${u}${n}${e}`,ns:s,defaultValue:p})}),r.push({key:u,ns:s,defaultValue:p}))}const n=void 0!==t.getObjectPropValue(f,"count"),i=!0===t.getObjectPropValue(f,"ordinal");if(n||l){this.config.extract.disablePlurals?r.length>0?r.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:u,ns:s,defaultValue:p}):this.handlePluralKeys(u,s,f,i||l,y);continue}if(r.length>0){r.forEach(this.pluginContext.addKey);continue}!0===t.getObjectPropValue(f,"returnObjects")&&this.objectKeys.add(u)}a&&this.objectKeys.add(u),this.pluginContext.addKey({key:u,ns:s,defaultValue:p})}}handleCallExpressionArgument(e,t){const s=e.arguments[t].expression,r=[];let n=!1;if("ArrowFunctionExpression"===s.type){const e=this.extractKeyFromSelector(s);e&&(r.push(e),n=!0)}else if("ArrayExpression"===s.type)for(const e of s.elements)e?.expression&&r.push(...this.resolvePossibleKeyStringValues(e.expression));else r.push(...this.resolvePossibleKeyStringValues(s));return{keysToProcess:r.filter(e=>!!e),isSelectorAPI:n}}handlePluralKeys(e,s,r,n,i){try{const o=n?"ordinal":"cardinal",a=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:o});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:o});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}const l=Array.from(a).sort(),u=this.config.extract.pluralSeparator??"_",p=t.getObjectPropValue(r,"defaultValue"),f=t.getObjectPropValue(r,`defaultValue${u}other`),c=t.getObjectPropValue(r,`defaultValue${u}ordinal${u}other`),y=t.getObjectPropValue(r,"count");let g;if("number"==typeof y)try{const e=this.config.extract?.primaryLanguage||this.config.locales[0]||"en";g=new Intl.PluralRules(e,{type:o}).select(y)}catch(e){}const d=t.getObjectProperty(r,"context"),h=[];if(d?.value){const t=this.resolvePossibleContextStringValues(d.value);if(t.length>0){for(const s of t)s.length>0&&h.push({key:e,context:s});!1!==this.config.extract?.generateBasePluralForms&&h.push({key:e})}else h.push({key:e})}else h.push({key:e});for(const{key:e,context:o}of h)for(const a of l){const l=n?`defaultValue${u}ordinal${u}${a}`:`defaultValue${u}${a}`,y=t.getObjectPropValue(r,l);let d,h;if(d="string"==typeof y?y:"one"===a&&"string"==typeof p?p:n&&"string"==typeof c?c:n||"string"!=typeof f?"string"==typeof p?p:i&&g===a?i:e:f,o){const t=this.config.extract.contextSeparator??"_";h=n?`${e}${t}${o}${u}ordinal${u}${a}`:`${e}${t}${o}${u}${a}`}else h=n?`${e}${u}ordinal${u}${a}`:`${e}${u}${a}`;this.pluginContext.addKey({key:h,ns:s,defaultValue:d,hasCount:!0,isOrdinal:n})}}catch(n){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const o=i||t.getObjectPropValue(r,"defaultValue");this.pluginContext.addKey({key:e,ns:s,defaultValue:"string"==typeof o?o:e})}}handleJSXElement(t){const s=this.getElementName(t);if(s&&(this.config.extract.transComponents||["Trans"]).includes(s)){const s=e.extractFromTransComponent(t,this.config),r=[];if(s){if(s.keyExpression){const e=this.resolvePossibleKeyStringValues(s.keyExpression);r.push(...e)}else r.push(s.serializedChildren);let e;const{contextExpression:n,optionsNode:i,defaultValue:o,hasCount:a,isOrdinal:l,serializedChildren:u}=s;if(s.ns){const{ns:t}=s;e=r.map(e=>({key:e,ns:t,defaultValue:o||u,hasCount:a,isOrdinal:l}))}else{e=r.map(e=>{const t=this.config.extract.nsSeparator??":";let s;if(t&&e.includes(t)){let r;[s,...r]=e.split(t),e=r.join(t)}return{key:e,ns:s,defaultValue:o||u,hasCount:a,isOrdinal:l}});const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===s?.type&&"JSXExpressionContainer"===s.value?.type&&"Identifier"===s.value.expression.type){const t=s.value.expression.value,r=this.getVarFromScope(t);r?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=r.defaultNs)})}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),n&&a)if(this.config.extract.disablePlurals){const t=this.resolvePossibleContextStringValues(n),s=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===n.type)for(const r of t)for(const t of e){const e=`${t.key}${s}${r}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})});for(const r of t)for(const t of e){const e=`${t.key}${s}${r}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else{const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),r=!!s,o=this.resolvePossibleContextStringValues(n),a=this.config.extract.contextSeparator??"_";if(o.length>0){e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,r,i));for(const t of o)for(const s of e){const e=`${s.key}${a}${t}`;this.generatePluralKeysForTrans(e,s.defaultValue,s.ns,r,i)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,r,i))}else if(n){const t=this.resolvePossibleContextStringValues(n),s=this.config.extract.contextSeparator??"_";if(t.length>0){for(const r of t)for(const{key:t,ns:n,defaultValue:i}of e)this.pluginContext.addKey({key:`${t}${s}${r}`,ns:n,defaultValue:i});"StringLiteral"!==n.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else if(a)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})});else{const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),r=!!s;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,r,i))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}}}generatePluralKeysForTrans(e,s,r,n,i){try{const o=n?"ordinal":"cardinal",a=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:o}).resolvedOptions().pluralCategories,l=this.config.extract.pluralSeparator??"_";let u,p;i&&(u=t.getObjectPropValue(i,`defaultValue${l}other`),p=t.getObjectPropValue(i,`defaultValue${l}ordinal${l}other`));for(const o of a){const a=n?`defaultValue${l}ordinal${l}${o}`:`defaultValue${l}${o}`,f=i?t.getObjectPropValue(i,a):void 0;let c;c="string"==typeof f?f:"one"===o&&"string"==typeof s?s:n&&"string"==typeof p?p:n||"string"!=typeof u?"string"==typeof s?s:e:u;const y=n?`${e}${l}ordinal${l}${o}`:`${e}${l}${o}`;this.pluginContext.addKey({key:y,ns:r,defaultValue:c,hasCount:!0,isOrdinal:n})}}catch(t){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`),this.pluginContext.addKey({key:e,ns:r,defaultValue:s})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const s=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&s.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&s.unshift(t.value),s.join(".")}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let s=t;const r=[];for(;"MemberExpression"===s.type;){const e=s.property;if("Identifier"===e.type)r.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;r.unshift(e.expression.value)}s=s.object}if(r.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return r.join(t)}return null}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,t=!1){if("StringLiteral"===e.type)return e.value||t?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,t),...this.resolvePossibleStringValuesFromExpression(e.alternate,t)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const s=e.typeAnnotation;return this.resolvePossibleStringValuesFromType(s,t)}return[]}resolvePossibleStringValuesFromType(e,t=!1){if("TsUnionType"===e.type)return e.types.flatMap(e=>this.resolvePossibleStringValuesFromType(e,t));if("TsLiteralType"===e.type){if("StringLiteral"===e.literal.type)return e.literal.value||t?[e.literal.value]:[];if("TemplateLiteral"===e.literal.type)return this.resolvePossibleStringValuesFromTemplateLiteralType(e.literal);if("NumericLiteral"===e.literal.type||"BooleanLiteral"===e.literal.type)return[`${e.literal.value}`]}return[]}resolvePossibleStringValuesFromTemplateString(e){if(1===e.quasis.length&&0===e.expressions.length)return[e.quasis[0].cooked||""];const[t,...s]=e.quasis;return e.expressions.reduce((e,t,r)=>e.flatMap(e=>{const n=s[r]?.cooked??"";return this.resolvePossibleStringValuesFromExpression(t,!0).map(t=>`${e}${t}${n}`)}),[t.cooked??""])}resolvePossibleStringValuesFromTemplateLiteralType(e){if(1===e.quasis.length&&0===e.types.length)return[e.quasis[0].cooked||""];const[t,...s]=e.quasis;return e.types.reduce((e,t,r)=>e.flatMap(e=>{const n=s[r]?.cooked??"";return this.resolvePossibleStringValuesFromType(t,!0).map(t=>`${e}${t}${n}`)}),[t.cooked??""])}getUseTranslationConfig(e){const t=this.config.extract.useTranslationNames||["useTranslation"];for(const s of t){if("string"==typeof s&&s===e)return{name:e,nsArg:0,keyPrefixArg:1};if("object"==typeof s&&s.name===e)return{name:s.name,nsArg:s.nsArg??0,keyPrefixArg:s.keyPrefixArg??1}}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let s=e;for(;"MemberExpression"===s.type;){if("Identifier"!==s.property.type)return null;t.unshift(s.property.value),s=s.object}if("ThisExpression"===s.type)t.unshift("this");else{if("Identifier"!==s.type)return null;t.unshift(s.value)}return t.join(".")}return null}};
@@ -1 +0,0 @@
1
- import{extractFromTransComponent as e}from"./jsx-parser.js";import{getObjectPropValue as t,getObjectProperty as s}from"./ast-utils.js";class n{pluginContext;config;logger;scopeStack=[];hooks;objectKeys=new Set;scope=new Map;constructor(e,t,s,n){this.pluginContext=t,this.config=e,this.logger=s,this.hooks={onBeforeVisitNode:n?.onBeforeVisitNode,onAfterVisitNode:n?.onAfterVisitNode,resolvePossibleKeyStringValues:n?.resolvePossibleKeyStringValues,resolvePossibleContextStringValues:n?.resolvePossibleContextStringValues}}visit(e){this.enterScope(),this.walk(e),this.exitScope()}walk(e){if(!e)return;let t=!1;switch("Function"!==e.type&&"ArrowFunctionExpression"!==e.type&&"FunctionExpression"!==e.type||(this.enterScope(),t=!0),this.hooks.onBeforeVisitNode?.(e),e.type){case"VariableDeclarator":this.handleVariableDeclarator(e);break;case"CallExpression":this.handleCallExpression(e);break;case"JSXElement":this.handleJSXElement(e)}this.hooks.onAfterVisitNode?.(e);for(const t in e){if("span"===t)continue;const s=e[t];if(Array.isArray(s))for(const e of s)e&&"object"==typeof e&&this.walk(e);else s&&"object"==typeof s&&this.walk(s)}t&&this.exitScope()}enterScope(){this.scopeStack.push(new Map)}exitScope(){this.scopeStack.pop()}setVarInScope(e,t){this.scopeStack.length>0&&this.scopeStack[this.scopeStack.length-1].set(e,t)}getVarFromScope(e){for(let t=this.scopeStack.length-1;t>=0;t--)if(this.scopeStack[t].has(e)){return this.scopeStack[t].get(e)}const t=this.scope.get(e);if(t)return t}handleVariableDeclarator(e){const t=e.init;if(!t)return;const s="AwaitExpression"===t.type&&"CallExpression"===t.argument.type?t.argument:"CallExpression"===t.type?t:null;if(!s)return;const n=s.callee;if("Identifier"===n.type){const t=this.getUseTranslationConfig(n.value);if(t)return this.handleUseTranslationDeclarator(e,s,t),void this.handleUseTranslationForComments(e,s,t)}"MemberExpression"===n.type&&"Identifier"===n.property.type&&"getFixedT"===n.property.value&&this.handleGetFixedTDeclarator(e,s)}handleUseTranslationForComments(e,t,s){let n;if("Identifier"===e.id.type&&(n=e.id.value),"ArrayPattern"===e.id.type){const t=e.id.elements[0];"Identifier"===t?.type&&(n=t.value)}if("ObjectPattern"===e.id.type)for(const t of e.id.properties){if("AssignmentPatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value){n="t";break}if("KeyValuePatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value&&"Identifier"===t.value.type){n=t.value.value;break}}if(!n)return;const r=t.arguments?.[s.nsArg]?.expression,i=t.arguments?.[s.keyPrefixArg]?.expression;let o,a;if("StringLiteral"===r?.type?o=r.value:"ArrayExpression"===r?.type&&"StringLiteral"===r.elements[0]?.expression.type&&(o=r.elements[0].expression.value),"ObjectExpression"===i?.type){const e=i.properties.find(e=>"KeyValueProperty"===e.type&&"Identifier"===e.key.type&&"keyPrefix"===e.key.value);"KeyValueProperty"===e?.type&&"StringLiteral"===e.value.type&&(a=e.value.value)}(o||a)&&this.scope.set(n,{defaultNs:o,keyPrefix:a})}handleUseTranslationDeclarator(e,s,n){let r;if("Identifier"===e.id.type&&(r=e.id.value),"ArrayPattern"===e.id.type){const t=e.id.elements[0];"Identifier"===t?.type&&(r=t.value)}if("ObjectPattern"===e.id.type)for(const t of e.id.properties){if("AssignmentPatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value){r="t";break}if("KeyValuePatternProperty"===t.type&&"Identifier"===t.key.type&&"t"===t.key.value&&"Identifier"===t.value.type){r=t.value.value;break}}if(!r)return;const i=s.arguments?.[n.nsArg]?.expression;let o;"StringLiteral"===i?.type?o=i.value:"ArrayExpression"===i?.type&&"StringLiteral"===i.elements[0]?.expression.type&&(o=i.elements[0].expression.value);const a=s.arguments?.[n.keyPrefixArg]?.expression;let l;if("ObjectExpression"===a?.type){const e=t(a,"keyPrefix");l="string"==typeof e?e:void 0}this.setVarInScope(r,{defaultNs:o,keyPrefix:l})}handleGetFixedTDeclarator(e,t){if("Identifier"!==e.id.type||!e.init||"CallExpression"!==e.init.type)return;const s=e.id.value,n=t.arguments,r=n[1]?.expression,i=n[2]?.expression,o="StringLiteral"===r?.type?r.value:void 0,a="StringLiteral"===i?.type?i.value:void 0;(o||a)&&this.setVarInScope(s,{defaultNs:o,keyPrefix:a})}handleCallExpression(e){const n=this.getFunctionName(e.callee);if(!n)return;const r=this.getVarFromScope(n),i=this.config.extract.functions||["t","*.t"];let o=void 0!==r;if(!o)for(const e of i)if(e.startsWith("*.")){if(n.endsWith(e.substring(1))){o=!0;break}}else if(e===n){o=!0;break}if(!o||0===e.arguments.length)return;const{keysToProcess:a,isSelectorAPI:l}=this.handleCallExpressionArgument(e,0);if(0===a.length)return;let u=!1;const p=this.config.extract.pluralSeparator??"_";for(let e=0;e<a.length;e++)a[e].endsWith(`${p}ordinal`)&&(u=!0,a[e]=a[e].slice(0,-8));let f,c;if(e.arguments.length>1){const t=e.arguments[1].expression;"ObjectExpression"===t.type?c=t:"StringLiteral"===t.type&&(f=t.value)}if(e.arguments.length>2){const t=e.arguments[2].expression;"ObjectExpression"===t.type&&(c=t)}const y=c?t(c,"defaultValue"):void 0,d="string"==typeof y?y:f;for(let e=0;e<a.length;e++){let n,i=a[e];if(c){const e=t(c,"ns");"string"==typeof e&&(n=e)}const o=this.config.extract.nsSeparator??":";if(!n&&o&&i.includes(o)){const e=i.split(o);if(n=e.shift(),i=e.join(o),!i||""===i.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${n}${o}'`);continue}}!n&&r?.defaultNs&&(n=r.defaultNs),n||(n=this.config.extract.defaultNS);let p=i;if(r?.keyPrefix){const e=this.config.extract.keySeparator??".";if(p=!1!==e?r.keyPrefix.endsWith(e)?`${r.keyPrefix}${i}`:`${r.keyPrefix}${e}${i}`:`${r.keyPrefix}${i}`,!1!==e){if(p.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${p}' (keyPrefix: '${r.keyPrefix}', key: '${i}')`);continue}}}const f=e===a.length-1&&d||i;if(c){const e=s(c,"context"),r=[];if("StringLiteral"===e?.value?.type||"NumericLiteral"===e?.value.type||"BooleanLiteral"===e?.value.type){const t=`${e.value.value}`,s=this.config.extract.contextSeparator??"_";""!==t&&r.push({key:`${p}${s}${t}`,ns:n,defaultValue:f})}else if(e?.value){const t=this.resolvePossibleContextStringValues(e.value),s=this.config.extract.contextSeparator??"_";t.length>0&&(t.forEach(e=>{r.push({key:`${p}${s}${e}`,ns:n,defaultValue:f})}),r.push({key:p,ns:n,defaultValue:f}))}const i=void 0!==t(c,"count"),o=!0===t(c,"ordinal");if(i||u){this.config.extract.disablePlurals?r.length>0?r.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:p,ns:n,defaultValue:f}):this.handlePluralKeys(p,n,c,o||u,d);continue}if(r.length>0){r.forEach(this.pluginContext.addKey);continue}!0===t(c,"returnObjects")&&this.objectKeys.add(p)}l&&this.objectKeys.add(p),this.pluginContext.addKey({key:p,ns:n,defaultValue:f})}}handleCallExpressionArgument(e,t){const s=e.arguments[t].expression,n=[];let r=!1;if("ArrowFunctionExpression"===s.type){const e=this.extractKeyFromSelector(s);e&&(n.push(e),r=!0)}else if("ArrayExpression"===s.type)for(const e of s.elements)e?.expression&&n.push(...this.resolvePossibleKeyStringValues(e.expression));else n.push(...this.resolvePossibleKeyStringValues(s));return{keysToProcess:n.filter(e=>!!e),isSelectorAPI:r}}handlePluralKeys(e,n,r,i,o){try{const a=i?"ordinal":"cardinal",l=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:a});t.resolvedOptions().pluralCategories.forEach(e=>l.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:a});t.resolvedOptions().pluralCategories.forEach(e=>l.add(e))}const u=Array.from(l).sort(),p=this.config.extract.pluralSeparator??"_",f=t(r,"defaultValue"),c=t(r,`defaultValue${p}other`),y=t(r,`defaultValue${p}ordinal${p}other`),d=t(r,"count");let g;if("number"==typeof d)try{const e=this.config.extract?.primaryLanguage||this.config.locales[0]||"en";g=new Intl.PluralRules(e,{type:a}).select(d)}catch(e){}const h=s(r,"context"),x=[];if(h?.value){const t=this.resolvePossibleContextStringValues(h.value);if(t.length>0){for(const s of t)s.length>0&&x.push({key:e,context:s});!1!==this.config.extract?.generateBasePluralForms&&x.push({key:e})}else x.push({key:e})}else x.push({key:e});for(const{key:e,context:s}of x)for(const a of u){const l=t(r,i?`defaultValue${p}ordinal${p}${a}`:`defaultValue${p}${a}`);let u,d;if(u="string"==typeof l?l:"one"===a&&"string"==typeof f?f:i&&"string"==typeof y?y:i||"string"!=typeof c?"string"==typeof f?f:o&&g===a?o:e:c,s){const t=this.config.extract.contextSeparator??"_";d=i?`${e}${t}${s}${p}ordinal${p}${a}`:`${e}${t}${s}${p}${a}`}else d=i?`${e}${p}ordinal${p}${a}`:`${e}${p}${a}`;this.pluginContext.addKey({key:d,ns:n,defaultValue:u,hasCount:!0,isOrdinal:i})}}catch(s){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const i=o||t(r,"defaultValue");this.pluginContext.addKey({key:e,ns:n,defaultValue:"string"==typeof i?i:e})}}handleJSXElement(t){const s=this.getElementName(t);if(s&&(this.config.extract.transComponents||["Trans"]).includes(s)){const s=e(t,this.config),n=[];if(s){if(s.keyExpression){const e=this.resolvePossibleKeyStringValues(s.keyExpression);n.push(...e)}else n.push(s.serializedChildren);let e;const{contextExpression:r,optionsNode:i,defaultValue:o,hasCount:a,isOrdinal:l,serializedChildren:u}=s;if(s.ns){const{ns:t}=s;e=n.map(e=>({key:e,ns:t,defaultValue:o||u,hasCount:a,isOrdinal:l}))}else{e=n.map(e=>{const t=this.config.extract.nsSeparator??":";let s;if(t&&e.includes(t)){let n;[s,...n]=e.split(t),e=n.join(t)}return{key:e,ns:s,defaultValue:o||u,hasCount:a,isOrdinal:l}});const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===s?.type&&"JSXExpressionContainer"===s.value?.type&&"Identifier"===s.value.expression.type){const t=s.value.expression.value,n=this.getVarFromScope(t);n?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=n.defaultNs)})}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),r&&a)if(this.config.extract.disablePlurals){const t=this.resolvePossibleContextStringValues(r),s=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===r.type)for(const n of t)for(const t of e){const e=`${t.key}${s}${n}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})});for(const n of t)for(const t of e){const e=`${t.key}${s}${n}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else{const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),n=!!s,o=this.resolvePossibleContextStringValues(r),a=this.config.extract.contextSeparator??"_";if(o.length>0){e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,n,i));for(const t of o)for(const s of e){const e=`${s.key}${a}${t}`;this.generatePluralKeysForTrans(e,s.defaultValue,s.ns,n,i)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,n,i))}else if(r){const t=this.resolvePossibleContextStringValues(r),s=this.config.extract.contextSeparator??"_";if(t.length>0){for(const n of t)for(const{key:t,ns:r,defaultValue:i}of e)this.pluginContext.addKey({key:`${t}${s}${n}`,ns:r,defaultValue:i});"StringLiteral"!==r.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}else if(a)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})});else{const s=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),n=!!s;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,n,i))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue})})}}}generatePluralKeysForTrans(e,s,n,r,i){try{const o=r?"ordinal":"cardinal",a=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:o}).resolvedOptions().pluralCategories,l=this.config.extract.pluralSeparator??"_";let u,p;i&&(u=t(i,`defaultValue${l}other`),p=t(i,`defaultValue${l}ordinal${l}other`));for(const o of a){const a=i?t(i,r?`defaultValue${l}ordinal${l}${o}`:`defaultValue${l}${o}`):void 0;let f;f="string"==typeof a?a:"one"===o&&"string"==typeof s?s:r&&"string"==typeof p?p:r||"string"!=typeof u?"string"==typeof s?s:e:u;const c=r?`${e}${l}ordinal${l}${o}`:`${e}${l}${o}`;this.pluginContext.addKey({key:c,ns:n,defaultValue:f,hasCount:!0,isOrdinal:r})}}catch(t){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`),this.pluginContext.addKey({key:e,ns:n,defaultValue:s})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const s=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&s.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&s.unshift(t.value),s.join(".")}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let s=t;const n=[];for(;"MemberExpression"===s.type;){const e=s.property;if("Identifier"===e.type)n.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;n.unshift(e.expression.value)}s=s.object}if(n.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return n.join(t)}return null}resolvePossibleContextStringValues(e){return[...this.hooks.resolvePossibleContextStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleKeyStringValues(e){return[...this.hooks.resolvePossibleKeyStringValues?.(e)??[],...this.resolvePossibleStringValuesFromExpression(e)]}resolvePossibleStringValuesFromExpression(e,t=!1){if("StringLiteral"===e.type)return e.value||t?[e.value]:[];if("ConditionalExpression"===e.type){return[...this.resolvePossibleStringValuesFromExpression(e.consequent,t),...this.resolvePossibleStringValuesFromExpression(e.alternate,t)]}if("Identifier"===e.type&&"undefined"===e.value)return[];if("TemplateLiteral"===e.type)return this.resolvePossibleStringValuesFromTemplateString(e);if("NumericLiteral"===e.type||"BooleanLiteral"===e.type)return[`${e.value}`];if("TsSatisfiesExpression"===e.type||"TsAsExpression"===e.type){const s=e.typeAnnotation;return this.resolvePossibleStringValuesFromType(s,t)}return[]}resolvePossibleStringValuesFromType(e,t=!1){if("TsUnionType"===e.type)return e.types.flatMap(e=>this.resolvePossibleStringValuesFromType(e,t));if("TsLiteralType"===e.type){if("StringLiteral"===e.literal.type)return e.literal.value||t?[e.literal.value]:[];if("TemplateLiteral"===e.literal.type)return this.resolvePossibleStringValuesFromTemplateLiteralType(e.literal);if("NumericLiteral"===e.literal.type||"BooleanLiteral"===e.literal.type)return[`${e.literal.value}`]}return[]}resolvePossibleStringValuesFromTemplateString(e){if(1===e.quasis.length&&0===e.expressions.length)return[e.quasis[0].cooked||""];const[t,...s]=e.quasis;return e.expressions.reduce((e,t,n)=>e.flatMap(e=>{const r=s[n]?.cooked??"";return this.resolvePossibleStringValuesFromExpression(t,!0).map(t=>`${e}${t}${r}`)}),[t.cooked??""])}resolvePossibleStringValuesFromTemplateLiteralType(e){if(1===e.quasis.length&&0===e.types.length)return[e.quasis[0].cooked||""];const[t,...s]=e.quasis;return e.types.reduce((e,t,n)=>e.flatMap(e=>{const r=s[n]?.cooked??"";return this.resolvePossibleStringValuesFromType(t,!0).map(t=>`${e}${t}${r}`)}),[t.cooked??""])}getUseTranslationConfig(e){const t=this.config.extract.useTranslationNames||["useTranslation"];for(const s of t){if("string"==typeof s&&s===e)return{name:e,nsArg:0,keyPrefixArg:1};if("object"==typeof s&&s.name===e)return{name:s.name,nsArg:s.nsArg??0,keyPrefixArg:s.keyPrefixArg??1}}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let s=e;for(;"MemberExpression"===s.type;){if("Identifier"!==s.property.type)return null;t.unshift(s.property.value),s=s.object}if("ThisExpression"===s.type)t.unshift("this");else{if("Identifier"!==s.type)return null;t.unshift(s.value)}return t.join(".")}return null}}export{n as ASTVisitors};