gtx-cli 2.5.34-alpha.0 → 2.5.35
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 +12 -0
- package/dist/api/collectUserEditDiffs.js +25 -3
- package/dist/console/index.d.ts +1 -3
- package/dist/console/index.js +1 -5
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/react/jsx/utils/constants.d.ts +1 -3
- package/dist/react/jsx/utils/constants.js +3 -13
- package/dist/react/jsx/utils/getPathsAndAliases.js +3 -3
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +2 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +4 -6
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +154 -168
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -10
- package/dist/react/jsx/utils/parseStringFunction.js +10 -63
- package/dist/workflow/download.js +0 -1
- package/package.json +2 -2
- package/dist/console/formatting.d.ts +0 -1
- package/dist/console/formatting.js +0 -7
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
- package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
- package/dist/react/jsx/utils/parseString.d.ts +0 -25
- package/dist/react/jsx/utils/parseString.js +0 -539
- package/dist/react/jsx/utils/types.d.ts +0 -14
- package/dist/react/jsx/utils/types.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { isStaticExpression, isValidIcu } from '../evaluateJsx.js';
|
|
3
|
-
import { GT_ATTRIBUTES_WITH_SUGAR,
|
|
3
|
+
import { GT_ATTRIBUTES_WITH_SUGAR, MSG_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, mapAttributeName, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, } from './constants.js';
|
|
4
4
|
import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, warnAsyncUseGT, warnSyncGetGT, warnInvalidIcuSync, warnInvalidMaxCharsSync, } from '../../../console/index.js';
|
|
5
5
|
import generateModule from '@babel/generator';
|
|
6
6
|
import traverseModule from '@babel/traverse';
|
|
@@ -12,10 +12,7 @@ import pathModule from 'node:path';
|
|
|
12
12
|
import { parse } from '@babel/parser';
|
|
13
13
|
import { resolveImportPath } from './resolveImportPath.js';
|
|
14
14
|
import { buildImportMap } from './buildImportMap.js';
|
|
15
|
-
import { handleStaticExpression } from './parseDeclareStatic.js';
|
|
16
|
-
import { nodeToStrings } from './parseString.js';
|
|
17
15
|
import { isNumberLiteral } from './isNumberLiteral.js';
|
|
18
|
-
import { indexVars } from 'generaltranslation/internal';
|
|
19
16
|
/**
|
|
20
17
|
* Cache for resolved import paths to avoid redundant I/O operations.
|
|
21
18
|
* Key: `${currentFile}::${importPath}`
|
|
@@ -45,62 +42,11 @@ export function clearParsingCaches() {
|
|
|
45
42
|
* - Metadata extraction from options object
|
|
46
43
|
* - Error reporting for non-static expressions and template literals with expressions
|
|
47
44
|
*/
|
|
48
|
-
function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu
|
|
45
|
+
function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu) {
|
|
49
46
|
if (tPath.parent.type === 'CallExpression' &&
|
|
50
47
|
tPath.parent.arguments.length > 0) {
|
|
51
48
|
const arg = tPath.parent.arguments[0];
|
|
52
|
-
|
|
53
|
-
if (!ignoreDynamicContent &&
|
|
54
|
-
t.isExpression(arg) &&
|
|
55
|
-
!isStaticExpression(arg).isStatic) {
|
|
56
|
-
const result = handleStaticExpression(arg, tPath, file, parsingOptions, errors);
|
|
57
|
-
if (result) {
|
|
58
|
-
const strings = nodeToStrings(result).map(indexVars);
|
|
59
|
-
if (!ignoreInvalidIcu) {
|
|
60
|
-
for (const string of strings) {
|
|
61
|
-
const { isValid, error } = isValidIcu(string);
|
|
62
|
-
if (!isValid) {
|
|
63
|
-
warnings.add(warnInvalidIcuSync(file, string, error ?? 'Unknown error', `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// get metadata and id from options
|
|
69
|
-
const options = tPath.parent.arguments[1];
|
|
70
|
-
const metadata = {};
|
|
71
|
-
if (options && options.type === 'ObjectExpression') {
|
|
72
|
-
options.properties.forEach((prop) => {
|
|
73
|
-
if (prop.type === 'ObjectProperty' &&
|
|
74
|
-
prop.key.type === 'Identifier') {
|
|
75
|
-
const attribute = prop.key.name;
|
|
76
|
-
if (GT_ATTRIBUTES_WITH_SUGAR.includes(attribute) &&
|
|
77
|
-
t.isExpression(prop.value)) {
|
|
78
|
-
const result = isStaticExpression(prop.value);
|
|
79
|
-
if (!result.isStatic) {
|
|
80
|
-
errors.push(warnNonStaticExpressionSync(file, attribute, generate(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
81
|
-
}
|
|
82
|
-
if (result.isStatic && result.value && !ignoreAdditionalData) {
|
|
83
|
-
// Map $id and $context to id and context
|
|
84
|
-
metadata[mapAttributeName(attribute)] = result.value;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
for (const string of strings) {
|
|
91
|
-
updates.push({
|
|
92
|
-
dataFormat: 'ICU',
|
|
93
|
-
source: string,
|
|
94
|
-
metadata: { ...metadata },
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
// Nothing returned, push error
|
|
100
|
-
errors.push(warnNonStringSync(file, generate(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
101
|
-
// ignore dynamic content flag is triggered, check strings are valid ICU
|
|
102
|
-
}
|
|
103
|
-
else if (arg.type === 'StringLiteral' ||
|
|
49
|
+
if (arg.type === 'StringLiteral' ||
|
|
104
50
|
(t.isTemplateLiteral(arg) && arg.expressions.length === 0)) {
|
|
105
51
|
const source = arg.type === 'StringLiteral' ? arg.value : arg.quasis[0].value.raw;
|
|
106
52
|
// Validate is ICU
|
|
@@ -125,7 +71,9 @@ function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAd
|
|
|
125
71
|
if (!result.isStatic) {
|
|
126
72
|
errors.push(warnNonStaticExpressionSync(file, attribute, generate(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
127
73
|
}
|
|
128
|
-
if (result.isStatic &&
|
|
74
|
+
if (result.isStatic &&
|
|
75
|
+
result.value != null &&
|
|
76
|
+
!ignoreAdditionalData) {
|
|
129
77
|
const mappedKey = mapAttributeName(attribute);
|
|
130
78
|
if (attribute === '$maxChars') {
|
|
131
79
|
if ((typeof result.value === 'string' &&
|
|
@@ -176,7 +124,6 @@ function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAd
|
|
|
176
124
|
errors.push(warnNonStringSync(file, generate(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
177
125
|
}
|
|
178
126
|
}
|
|
179
|
-
// }
|
|
180
127
|
}
|
|
181
128
|
}
|
|
182
129
|
/**
|
|
@@ -201,7 +148,7 @@ function extractParameterName(param) {
|
|
|
201
148
|
* @param visited Set to track already visited variables to prevent infinite loops
|
|
202
149
|
* @returns Array of all variable names that reference the original translation callback
|
|
203
150
|
*/
|
|
204
|
-
|
|
151
|
+
function resolveVariableAliases(scope, variableName, visited = new Set()) {
|
|
205
152
|
if (visited.has(variableName)) {
|
|
206
153
|
return []; // Prevent infinite loops
|
|
207
154
|
}
|
|
@@ -237,7 +184,7 @@ function handleFunctionCall(tPath, updates, errors, warnings, file, importMap, i
|
|
|
237
184
|
if (tPath.parent.type === 'CallExpression' &&
|
|
238
185
|
tPath.parent.callee === tPath.node) {
|
|
239
186
|
// Direct translation call: t('hello')
|
|
240
|
-
processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu
|
|
187
|
+
processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu);
|
|
241
188
|
}
|
|
242
189
|
else if (tPath.parent.type === 'CallExpression' &&
|
|
243
190
|
t.isExpression(tPath.node) &&
|
|
@@ -426,14 +373,14 @@ export function parseStrings(importName, originalName, path, updates, errors, wa
|
|
|
426
373
|
const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
|
|
427
374
|
for (const refPath of referencePaths) {
|
|
428
375
|
// Handle msg() calls directly without variable assignment
|
|
429
|
-
if (originalName ===
|
|
376
|
+
if (originalName === MSG_TRANSLATION_HOOK) {
|
|
430
377
|
const ignoreAdditionalData = false;
|
|
431
378
|
const ignoreDynamicContent = false;
|
|
432
379
|
const ignoreInvalidIcu = false;
|
|
433
380
|
// Check if this is a direct call to msg('string')
|
|
434
381
|
if (refPath.parent.type === 'CallExpression' &&
|
|
435
382
|
refPath.parent.callee === refPath.node) {
|
|
436
|
-
processTranslationCall(refPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu
|
|
383
|
+
processTranslationCall(refPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu);
|
|
437
384
|
}
|
|
438
385
|
continue;
|
|
439
386
|
}
|
|
@@ -70,7 +70,6 @@ export async function downloadTranslations(fileVersionData, jobData, branchData,
|
|
|
70
70
|
logger.error(`${chalk.red(`${pollResult.fileTracker.failed.size} file(s) failed to translate:`)}\n${Array.from(pollResult.fileTracker.failed.entries())
|
|
71
71
|
.map(([key, value]) => `- ${value.fileName}`)
|
|
72
72
|
.join('\n')}`);
|
|
73
|
-
return false;
|
|
74
73
|
}
|
|
75
74
|
if (!pollResult.success) {
|
|
76
75
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.35",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"unified": "^11.0.5",
|
|
107
107
|
"unist-util-visit": "^5.0.0",
|
|
108
108
|
"yaml": "^2.8.0",
|
|
109
|
-
"generaltranslation": "8.1.
|
|
109
|
+
"generaltranslation": "8.1.3"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@babel/types": "^7.28.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatCodeClamp(code: string): string;
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
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,15 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { NodePath } from '@babel/traverse';
|
|
3
|
-
import { ParsingConfigOptions } from '../../../types/parsing.js';
|
|
4
|
-
import { StringNode } from './types.js';
|
|
5
|
-
export type StringTree = (string | StringTree)[];
|
|
6
|
-
/**
|
|
7
|
-
* Checks if an expression is static or uses declareStatic
|
|
8
|
-
* Returns a Node representing the parsed expression
|
|
9
|
-
* @param expr - The expression to check
|
|
10
|
-
* @param tPath - NodePath for scope resolution
|
|
11
|
-
* @param file - Current file path
|
|
12
|
-
* @param parsingOptions - Parsing configuration
|
|
13
|
-
* @returns Node | null - The parsed node, or null if invalid
|
|
14
|
-
*/
|
|
15
|
-
export declare function handleStaticExpression(expr: t.Expression, tPath: NodePath, file: string, parsingOptions: ParsingConfigOptions, errors: string[]): StringNode | null;
|