gtx-cli 2.5.35 → 2.5.36

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,14 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.36
4
+
5
+ ### Patch Changes
6
+
7
+ - [#806](https://github.com/generaltranslation/gt/pull/806) [`d59dd40`](https://github.com/generaltranslation/gt/commit/d59dd40e7b042e2bb4e718f17f3b2e764165151f) Thanks [@archie-mckenzie](https://github.com/archie-mckenzie)! - feat: declareStatic()
8
+
9
+ - Updated dependencies [[`d59dd40`](https://github.com/generaltranslation/gt/commit/d59dd40e7b042e2bb4e718f17f3b2e764165151f)]:
10
+ - generaltranslation@8.1.4
11
+
3
12
  ## 2.5.35
4
13
 
5
14
  ### Patch Changes
@@ -0,0 +1 @@
1
+ export declare function formatCodeClamp(code: string): string;
@@ -0,0 +1,7 @@
1
+ const MAX_CODE_GEN_LENGTH = 100;
2
+ export function formatCodeClamp(code) {
3
+ if (code.length <= MAX_CODE_GEN_LENGTH) {
4
+ return code;
5
+ }
6
+ return `${code.slice(0, MAX_CODE_GEN_LENGTH)}...`;
7
+ }
@@ -14,11 +14,13 @@ export declare const warnAsyncUseGT: (file: string, location?: string) => string
14
14
  export declare const warnSyncGetGT: (file: string, location?: string) => string;
15
15
  export declare const warnTernarySync: (file: string, location?: string) => string;
16
16
  export declare const withLocation: (file: string, message: string, location?: string) => string;
17
- export declare const warnInvalidStaticChildSync: (file: string, location?: string) => string;
18
17
  export declare const warnFunctionNotFoundSync: (file: string, functionName: string, location?: string) => string;
18
+ export declare const warnInvalidDeclareVarNameSync: (file: string, value: string, location?: string) => string;
19
19
  export declare const warnDuplicateFunctionDefinitionSync: (file: string, functionName: string, location?: string) => string;
20
20
  export declare const warnInvalidStaticInitSync: (file: string, functionName: string, location?: string) => string;
21
21
  export declare const warnRecursiveFunctionCallSync: (file: string, functionName: string, location?: string) => string;
22
+ export declare const warnDeclareStaticNotWrappedSync: (file: string, functionName: string, location?: string) => string;
23
+ export declare const warnDeclareStaticNoResultsSync: (file: string, functionName: string, location?: string) => string;
22
24
  export declare const noLocalesError = "No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.";
23
25
  export declare const noDefaultLocaleError = "No default locale found! Please provide a default locale, or specify it in your gt.config.json file.";
24
26
  export declare const noFilesError = "Incorrect or missing files configuration! Please make sure your files are configured correctly in your gt.config.json file.";
@@ -1,7 +1,9 @@
1
1
  import { colorizeFilepath, colorizeComponent, colorizeIdString, colorizeContent, colorizeLine, colorizeFunctionName, } from './colors.js';
2
+ import { formatCodeClamp } from './formatting.js';
2
3
  const withWillErrorInNextVersion = (message) => `${message} (This will become an error in the next major version of the CLI.)`;
3
4
  // Static function related errors
4
5
  const withStaticError = (message) => `<Static> rules violation: ${message}`;
6
+ const withDeclareStaticError = (message) => `declareStatic() rules violation: ${message}`;
5
7
  // Synchronous wrappers for backward compatibility
6
8
  export const warnApiKeyInConfigSync = (optionsFilepath) => `${colorizeFilepath(optionsFilepath)}: Your API key is exposed! Please remove it from the file and include it as an environment variable.`;
7
9
  export const warnVariablePropSync = (file, attrName, value, location) => withLocation(file, `${colorizeComponent('<T>')} component has dynamic attribute ${colorizeIdString(attrName)} with value: ${colorizeContent(value)}. Change ${colorizeIdString(attrName)} to ensure this content is translated.`, location);
@@ -20,13 +22,15 @@ export const warnAsyncUseGT = (file, location) => withLocation(file, `Found useG
20
22
  export const warnSyncGetGT = (file, location) => withLocation(file, `Found getGT() in a synchronous function. Use useGT() instead, or make the function async.`, location);
21
23
  export const warnTernarySync = (file, location) => withLocation(file, 'Found ternary expression. A Branch component may be more appropriate here.', location);
22
24
  export const withLocation = (file, message, location) => `${colorizeFilepath(file)}${location ? ` (${colorizeLine(location)})` : ''}: ${message}`;
23
- export const warnInvalidStaticChildSync = (file, location) => withLocation(file, 'Found invalid <Static> invocation. Children must be an expression container with a function invocation. Callee must be a single identifier. (Example: <T> <Static> {getSubject()} </Static> </T>)', location);
24
25
  export const warnFunctionNotFoundSync = (file, functionName, location) => withLocation(file, `Function ${colorizeFunctionName(functionName)} definition could not be resolved. This might affect translation resolution for this ${colorizeComponent('<T>')} component.`, location);
26
+ export const warnInvalidDeclareVarNameSync = (file, value, location) => withLocation(file, `Found invalid declareVar() $name tag. Must be a static expression. Received: ${colorizeContent(value)}.`, location);
25
27
  export const warnDuplicateFunctionDefinitionSync = (file, functionName, location) => withLocation(file, `Function ${colorizeFunctionName(functionName)} is defined multiple times. Only the first definition will be used.`, location);
26
28
  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.
27
29
  Example: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = () => { ... }`)}
28
30
  Invalid: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = [() => { ... }][0]`)}`), location);
29
31
  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);
32
+ export const warnDeclareStaticNotWrappedSync = (file, functionName, location) => withLocation(file, withDeclareStaticError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. This call is not wrapped in declareStatic(). Ensure the function is properly wrapped with declareStatic() and does not have circular import dependencies.`), location);
33
+ export const warnDeclareStaticNoResultsSync = (file, functionName, location) => withLocation(file, withDeclareStaticError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. DeclareStatic can only receive function invocations and cannot use undefined values or looped calls to construct its result.`), location);
30
34
  // Re-export error messages
31
35
  export const noLocalesError = `No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.`;
32
36
  export const noDefaultLocaleError = `No default locale found! Please provide a default locale, or specify it in your gt.config.json file.`;
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.5.35";
1
+ export declare const PACKAGE_VERSION = "2.5.36";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.5.35';
2
+ export const PACKAGE_VERSION = '2.5.36';
@@ -1,4 +1,6 @@
1
- export declare const MSG_TRANSLATION_HOOK = "msg";
1
+ export declare const DECLARE_VAR_FUNCTION = "declareVar";
2
+ export declare const DECLARE_STATIC_FUNCTION = "declareStatic";
3
+ export declare const MSG_TRANSLATION_FUNCTION = "msg";
2
4
  export declare const INLINE_TRANSLATION_HOOK = "useGT";
3
5
  export declare const INLINE_TRANSLATION_HOOK_ASYNC = "getGT";
4
6
  export declare const INLINE_MESSAGE_HOOK = "useMessages";
@@ -1,4 +1,6 @@
1
- export const MSG_TRANSLATION_HOOK = 'msg';
1
+ export const DECLARE_VAR_FUNCTION = 'declareVar';
2
+ export const DECLARE_STATIC_FUNCTION = 'declareStatic';
3
+ export const MSG_TRANSLATION_FUNCTION = 'msg';
2
4
  export const INLINE_TRANSLATION_HOOK = 'useGT';
3
5
  export const INLINE_TRANSLATION_HOOK_ASYNC = 'getGT';
4
6
  export const INLINE_MESSAGE_HOOK = 'useMessages';
@@ -11,7 +13,9 @@ export const GT_TRANSLATION_FUNCS = [
11
13
  INLINE_TRANSLATION_HOOK_ASYNC,
12
14
  INLINE_MESSAGE_HOOK,
13
15
  INLINE_MESSAGE_HOOK_ASYNC,
14
- MSG_TRANSLATION_HOOK,
16
+ MSG_TRANSLATION_FUNCTION,
17
+ DECLARE_VAR_FUNCTION,
18
+ DECLARE_STATIC_FUNCTION,
15
19
  TRANSLATION_COMPONENT,
16
20
  STATIC_COMPONENT,
17
21
  'Var',
@@ -63,11 +67,17 @@ export const GT_LIBRARIES_UPSTREAM = {
63
67
  'gt-react',
64
68
  'gt-next',
65
69
  ],
66
- 'gt-react': ['gt-i18n', '@generaltranslation/react-core', 'gt-react'],
70
+ 'gt-react': [
71
+ 'gt-i18n',
72
+ '@generaltranslation/react-core',
73
+ 'gt-react',
74
+ 'gt-react-native', // allow for cross-library compatibility (gt-react/gt-react-native only)
75
+ ],
67
76
  'gt-react-native': [
68
77
  'gt-i18n',
69
78
  '@generaltranslation/react-core',
70
79
  'gt-react-native',
80
+ 'gt-react', // allow for cross-library compatibility (gt-react/gt-react-native only)
71
81
  ],
72
82
  '@generaltranslation/react-core': [
73
83
  'gt-i18n',
@@ -0,0 +1,9 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * Get the callee name from an expression: ... = useGT();
4
+ * Rule of thumb, only call on expressions with parentheses
5
+ */
6
+ export declare function getCalleeNameFromExpression(expr: t.Expression): {
7
+ namespaceName: string | null;
8
+ functionName: string | null;
9
+ };
@@ -0,0 +1,32 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * Get the callee name from an expression: ... = useGT();
4
+ * Rule of thumb, only call on expressions with parentheses
5
+ */
6
+ export function getCalleeNameFromExpression(expr) {
7
+ // If its an await expression, unwrap it
8
+ if (t.isAwaitExpression(expr)) {
9
+ return getCalleeNameFromExpression(expr.argument);
10
+ }
11
+ // Check that this is a call expression eg: func()
12
+ if (!t.isCallExpression(expr)) {
13
+ return { namespaceName: null, functionName: null };
14
+ }
15
+ // Get the callee name
16
+ const calleeName = expr.callee;
17
+ // Simple case: ... = useGT();
18
+ if (t.isIdentifier(calleeName)) {
19
+ return { namespaceName: null, functionName: calleeName.name };
20
+ }
21
+ // Member expression: ... = GT.useGT();
22
+ if (t.isMemberExpression(calleeName)) {
23
+ if (t.isIdentifier(calleeName.object) &&
24
+ t.isIdentifier(calleeName.property)) {
25
+ return {
26
+ namespaceName: calleeName.object.name,
27
+ functionName: calleeName.property.name,
28
+ };
29
+ }
30
+ }
31
+ return { namespaceName: null, functionName: null };
32
+ }
@@ -1,5 +1,5 @@
1
1
  import traverseModule from '@babel/traverse';
2
- import { GT_TRANSLATION_FUNCS, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, MSG_TRANSLATION_HOOK, TRANSLATION_COMPONENT, } from '../../jsx/utils/constants.js';
2
+ import { GT_TRANSLATION_FUNCS, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, MSG_TRANSLATION_FUNCTION, TRANSLATION_COMPONENT, } from '../../jsx/utils/constants.js';
3
3
  import { extractImportName } from './parseAst.js';
4
4
  // Handle CommonJS/ESM interop
5
5
  const traverse = traverseModule.default || traverseModule;
@@ -23,7 +23,7 @@ export function getPathsAndAliases(ast, pkgs) {
23
23
  name.original === INLINE_TRANSLATION_HOOK_ASYNC ||
24
24
  name.original === INLINE_MESSAGE_HOOK ||
25
25
  name.original === INLINE_MESSAGE_HOOK_ASYNC ||
26
- name.original === MSG_TRANSLATION_HOOK) {
26
+ name.original === MSG_TRANSLATION_FUNCTION) {
27
27
  inlineTranslationPaths.push({
28
28
  localName: name.local,
29
29
  path,
@@ -61,7 +61,7 @@ export function getPathsAndAliases(ast, pkgs) {
61
61
  name.original === INLINE_TRANSLATION_HOOK_ASYNC ||
62
62
  name.original === INLINE_MESSAGE_HOOK ||
63
63
  name.original === INLINE_MESSAGE_HOOK_ASYNC ||
64
- name.original === MSG_TRANSLATION_HOOK) {
64
+ name.original === MSG_TRANSLATION_FUNCTION) {
65
65
  inlineTranslationPaths.push({
66
66
  localName: name.local,
67
67
  path: parentPath,
@@ -120,8 +120,6 @@ export function handleChildrenWhitespace(currentTree, parentNodeType = undefined
120
120
  newChildren.push(newElement);
121
121
  break;
122
122
  case 'multiplication':
123
- // I dont think this case is possible, at least in the array case
124
- // Can only be child of element or multiplication nodes
125
123
  newChildren.push({
126
124
  nodeType: 'multiplication',
127
125
  branches: handleChildrenWhitespace(child.branches, 'multiplication'),
@@ -3,7 +3,7 @@ import * as t from '@babel/types';
3
3
  import { NodePath } from '@babel/traverse';
4
4
  import { ParsingConfigOptions } from '../../../../types/parsing.js';
5
5
  import traverseModule from '@babel/traverse';
6
- import { JsxTree } from './types.js';
6
+ import { MultiplicationNode, JsxTree } from './types.js';
7
7
  import { GTLibrary } from '../constants.js';
8
8
  /**
9
9
  * Entry point for JSX parsing
@@ -31,12 +31,11 @@ export declare function parseTranslationComponent({ originalName, importAliases,
31
31
  * @param insideT - Whether the current node is inside a <T> component
32
32
  * @returns The built JSX tree
33
33
  */
34
- export declare function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkgs, }: {
34
+ export declare function buildJSXTree({ importAliases, node, unwrappedExpressions, inStatic, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkgs, helperPath, }: {
35
35
  importAliases: Record<string, string>;
36
36
  node: any;
37
37
  callStack: string[];
38
38
  unwrappedExpressions: string[];
39
- visited: Set<string> | null;
40
39
  updates: Updates;
41
40
  errors: string[];
42
41
  warnings: Set<string>;
@@ -46,7 +45,10 @@ export declare function buildJSXTree({ importAliases, node, unwrappedExpressions
46
45
  scopeNode: NodePath;
47
46
  importedFunctionsMap: Map<string, string>;
48
47
  pkgs: GTLibrary[];
49
- }): JsxTree;
48
+ inStatic: boolean;
49
+ visited: Set<string> | null;
50
+ helperPath: NodePath;
51
+ }): JsxTree | MultiplicationNode;
50
52
  export declare function parseJSXElement({ importAliases, node, originalName, pkgs, updates, errors, warnings, file, parsingOptions, scopeNode, importedFunctionsMap, }: {
51
53
  importAliases: Record<string, string>;
52
54
  node: t.JSXElement;