gtx-cli 2.5.5 → 2.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#817](https://github.com/generaltranslation/gt/pull/817) [`80eef0e`](https://github.com/generaltranslation/gt/commit/80eef0e0f61d5a07ed850aa39b25e81bddd12b34) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: Static component resolution edge cases
8
+
3
9
  ## 2.5.5
4
10
 
5
11
  ### Patch Changes
@@ -25,7 +25,7 @@ export const warnDuplicateFunctionDefinitionSync = (file, functionName, location
25
25
  export const warnInvalidStaticInitSync = (file, functionName, location) => withLocation(file, withStaticError(`The definition for ${colorizeFunctionName(functionName)} could not be resolved. When using arrow syntax to define a static function, the right hand side or the assignment MUST only contain the arrow function itself and no other expressions.
26
26
  Example: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = () => { ... }`)}
27
27
  Invalid: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = [() => { ... }][0]`)}`), location);
28
- export const warnRecursiveFunctionCallSync = (file, functionName, location) => withLocation(file, withStaticError(`Recursive function call detected: ${colorizeFunctionName(functionName)}. A static function use recursive calls to construct its result.`), location);
28
+ export const warnRecursiveFunctionCallSync = (file, functionName, location) => withLocation(file, withStaticError(`Recursive function call detected: ${colorizeFunctionName(functionName)}. A static function cannot use recursive calls to construct its result.`), location);
29
29
  // Re-export error messages
30
30
  export const noLocalesError = `No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.`;
31
31
  export const noDefaultLocaleError = `No default locale found! Please provide a default locale, or specify it in your gt.config.json file.`;
@@ -1,6 +1,9 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  /**
3
- *
3
+ * Constructs tracking for gt related variables of interest
4
+ * inlineTranslationPaths: these are string-related translation functions
5
+ * translationComponentPaths: these are just <T> components
6
+ * importAliases: any other GT related imports
4
7
  */
5
8
  export declare function getPathsAndAliases(ast: any, pkg: 'gt-react' | 'gt-next'): {
6
9
  importAliases: Record<string, string>;
@@ -4,7 +4,10 @@ import { extractImportName } from './parseAst.js';
4
4
  // Handle CommonJS/ESM interop
5
5
  const traverse = traverseModule.default || traverseModule;
6
6
  /**
7
- *
7
+ * Constructs tracking for gt related variables of interest
8
+ * inlineTranslationPaths: these are string-related translation functions
9
+ * translationComponentPaths: these are just <T> components
10
+ * importAliases: any other GT related imports
8
11
  */
9
12
  export function getPathsAndAliases(ast, pkg) {
10
13
  // First pass: collect imports and process translation functions
@@ -35,7 +35,7 @@ export declare function buildJSXTree({ importAliases, node, unwrappedExpressions
35
35
  node: any;
36
36
  callStack: string[];
37
37
  unwrappedExpressions: string[];
38
- visited: Set<string>;
38
+ visited: Set<string> | null;
39
39
  updates: Updates;
40
40
  errors: string[];
41
41
  warnings: Set<string>;
@@ -202,6 +202,9 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, visite
202
202
  });
203
203
  if (elementIsVariable) {
204
204
  if (componentType === STATIC_COMPONENT) {
205
+ if (visited === null) {
206
+ visited = new Set();
207
+ }
205
208
  return resolveStaticComponentChildren({
206
209
  importAliases,
207
210
  scopeNode,
@@ -376,7 +379,7 @@ export function parseJSXElement({ importAliases, node, originalName, pkg, update
376
379
  importAliases,
377
380
  node,
378
381
  scopeNode,
379
- visited: new Set(),
382
+ visited: null,
380
383
  callStack: [],
381
384
  pkg,
382
385
  unwrappedExpressions,
@@ -486,7 +489,7 @@ function resolveStaticComponentChildren({ importAliases, scopeNode, children, un
486
489
  : child.expression.callee);
487
490
  const calleeBinding = scopeNode.scope.getBinding(callee.name);
488
491
  if (!calleeBinding) {
489
- warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`);
492
+ warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
490
493
  continue;
491
494
  }
492
495
  // Function is found locally, return wrapped in an expression
@@ -577,17 +580,29 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
577
580
  });
578
581
  }
579
582
  else if (importedFunctionsMap.has(callee.name)) {
583
+ // Get the original function name
584
+ let originalName;
585
+ if (calleeBinding.path.isImportSpecifier()) {
586
+ originalName = t.isIdentifier(calleeBinding.path.node.imported)
587
+ ? calleeBinding.path.node.imported.name
588
+ : calleeBinding.path.node.imported.value;
589
+ }
590
+ else if (calleeBinding.path.isImportDefaultSpecifier()) {
591
+ originalName = calleeBinding.path.node.local.name;
592
+ }
593
+ else if (calleeBinding.path.isImportNamespaceSpecifier()) {
594
+ originalName = calleeBinding.path.node.local.name;
595
+ }
580
596
  // Function is being imported
581
597
  const importPath = importedFunctionsMap.get(callee.name);
582
598
  const filePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
583
- if (filePath) {
584
- const functionName = callee.name;
585
- return withRecusionGuard({
586
- filename: file,
587
- functionName,
599
+ if (filePath && originalName) {
600
+ const result = withRecusionGuard({
601
+ filename: filePath,
602
+ functionName: originalName,
588
603
  cb: () => processFunctionInFile({
589
604
  filePath,
590
- functionName,
605
+ functionName: originalName,
591
606
  visited,
592
607
  callStack,
593
608
  unwrappedExpressions,
@@ -599,6 +614,9 @@ function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBindi
599
614
  pkg,
600
615
  }),
601
616
  });
617
+ if (result !== null) {
618
+ return result;
619
+ }
602
620
  }
603
621
  }
604
622
  warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
@@ -644,7 +662,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
644
662
  });
645
663
  const reExports = [];
646
664
  const warnDuplicateFuncDef = (path) => {
647
- warnings.add(warnDuplicateFunctionDefinitionSync(file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
665
+ warnings.add(warnDuplicateFunctionDefinitionSync(filePath, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
648
666
  };
649
667
  traverse(ast, {
650
668
  // Handle function declarations: function getInfo() { ... }
@@ -663,7 +681,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
663
681
  updates,
664
682
  errors,
665
683
  warnings,
666
- file,
684
+ file: filePath,
667
685
  parsingOptions,
668
686
  importedFunctionsMap,
669
687
  });
@@ -689,7 +707,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
689
707
  warnings,
690
708
  visited,
691
709
  unwrappedExpressions,
692
- file,
710
+ file: filePath,
693
711
  parsingOptions,
694
712
  importedFunctionsMap,
695
713
  });
@@ -735,7 +753,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
735
753
  updates,
736
754
  errors,
737
755
  warnings,
738
- file,
756
+ file: filePath,
739
757
  pkg,
740
758
  });
741
759
  if (foundResult != null) {
@@ -35,7 +35,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
35
35
  // Parse <T> components
36
36
  for (const { localName, path } of translationComponentPaths) {
37
37
  parseTranslationComponent({
38
- importAliases: importAliases,
38
+ importAliases,
39
39
  originalName: localName,
40
40
  localName,
41
41
  ast,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [