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 +9 -0
- package/dist/console/formatting.d.ts +1 -0
- package/dist/console/formatting.js +7 -0
- package/dist/console/index.d.ts +3 -1
- package/dist/console/index.js +5 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/react/jsx/utils/constants.d.ts +3 -1
- package/dist/react/jsx/utils/constants.js +13 -3
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +9 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +32 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +3 -3
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -2
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +6 -4
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +168 -154
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +15 -0
- package/dist/react/jsx/utils/parseDeclareStatic.js +540 -0
- package/dist/react/jsx/utils/parseString.d.ts +25 -0
- package/dist/react/jsx/utils/parseString.js +539 -0
- package/dist/react/jsx/utils/parseStringFunction.d.ts +10 -0
- package/dist/react/jsx/utils/parseStringFunction.js +63 -10
- package/dist/react/jsx/utils/types.d.ts +14 -0
- package/dist/react/jsx/utils/types.js +1 -0
- package/package.json +2 -2
|
@@ -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_FUNCTION, 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,7 +12,10 @@ 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';
|
|
15
17
|
import { isNumberLiteral } from './isNumberLiteral.js';
|
|
18
|
+
import { indexVars } from 'generaltranslation/internal';
|
|
16
19
|
/**
|
|
17
20
|
* Cache for resolved import paths to avoid redundant I/O operations.
|
|
18
21
|
* Key: `${currentFile}::${importPath}`
|
|
@@ -42,11 +45,62 @@ export function clearParsingCaches() {
|
|
|
42
45
|
* - Metadata extraction from options object
|
|
43
46
|
* - Error reporting for non-static expressions and template literals with expressions
|
|
44
47
|
*/
|
|
45
|
-
function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu) {
|
|
48
|
+
function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu, parsingOptions) {
|
|
46
49
|
if (tPath.parent.type === 'CallExpression' &&
|
|
47
50
|
tPath.parent.arguments.length > 0) {
|
|
48
51
|
const arg = tPath.parent.arguments[0];
|
|
49
|
-
if (arg
|
|
52
|
+
// if (t.isExpression(arg)) {
|
|
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' ||
|
|
50
104
|
(t.isTemplateLiteral(arg) && arg.expressions.length === 0)) {
|
|
51
105
|
const source = arg.type === 'StringLiteral' ? arg.value : arg.quasis[0].value.raw;
|
|
52
106
|
// Validate is ICU
|
|
@@ -71,9 +125,7 @@ function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAd
|
|
|
71
125
|
if (!result.isStatic) {
|
|
72
126
|
errors.push(warnNonStaticExpressionSync(file, attribute, generate(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
73
127
|
}
|
|
74
|
-
if (result.isStatic &&
|
|
75
|
-
result.value != null &&
|
|
76
|
-
!ignoreAdditionalData) {
|
|
128
|
+
if (result.isStatic && result.value && !ignoreAdditionalData) {
|
|
77
129
|
const mappedKey = mapAttributeName(attribute);
|
|
78
130
|
if (attribute === '$maxChars') {
|
|
79
131
|
if ((typeof result.value === 'string' &&
|
|
@@ -124,6 +176,7 @@ function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAd
|
|
|
124
176
|
errors.push(warnNonStringSync(file, generate(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
125
177
|
}
|
|
126
178
|
}
|
|
179
|
+
// }
|
|
127
180
|
}
|
|
128
181
|
}
|
|
129
182
|
/**
|
|
@@ -148,7 +201,7 @@ function extractParameterName(param) {
|
|
|
148
201
|
* @param visited Set to track already visited variables to prevent infinite loops
|
|
149
202
|
* @returns Array of all variable names that reference the original translation callback
|
|
150
203
|
*/
|
|
151
|
-
function resolveVariableAliases(scope, variableName, visited = new Set()) {
|
|
204
|
+
export function resolveVariableAliases(scope, variableName, visited = new Set()) {
|
|
152
205
|
if (visited.has(variableName)) {
|
|
153
206
|
return []; // Prevent infinite loops
|
|
154
207
|
}
|
|
@@ -184,7 +237,7 @@ function handleFunctionCall(tPath, updates, errors, warnings, file, importMap, i
|
|
|
184
237
|
if (tPath.parent.type === 'CallExpression' &&
|
|
185
238
|
tPath.parent.callee === tPath.node) {
|
|
186
239
|
// Direct translation call: t('hello')
|
|
187
|
-
processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu);
|
|
240
|
+
processTranslationCall(tPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu, parsingOptions);
|
|
188
241
|
}
|
|
189
242
|
else if (tPath.parent.type === 'CallExpression' &&
|
|
190
243
|
t.isExpression(tPath.node) &&
|
|
@@ -373,14 +426,14 @@ export function parseStrings(importName, originalName, path, updates, errors, wa
|
|
|
373
426
|
const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
|
|
374
427
|
for (const refPath of referencePaths) {
|
|
375
428
|
// Handle msg() calls directly without variable assignment
|
|
376
|
-
if (originalName ===
|
|
429
|
+
if (originalName === MSG_TRANSLATION_FUNCTION) {
|
|
377
430
|
const ignoreAdditionalData = false;
|
|
378
431
|
const ignoreDynamicContent = false;
|
|
379
432
|
const ignoreInvalidIcu = false;
|
|
380
433
|
// Check if this is a direct call to msg('string')
|
|
381
434
|
if (refPath.parent.type === 'CallExpression' &&
|
|
382
435
|
refPath.parent.callee === refPath.node) {
|
|
383
|
-
processTranslationCall(refPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu);
|
|
436
|
+
processTranslationCall(refPath, updates, errors, warnings, file, ignoreAdditionalData, ignoreDynamicContent, ignoreInvalidIcu, parsingOptions);
|
|
384
437
|
}
|
|
385
438
|
continue;
|
|
386
439
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type StringNode = StringTextNode | StringSequenceNode | StringChoiceNode;
|
|
2
|
+
type StringTextNode = {
|
|
3
|
+
type: 'text';
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
type StringSequenceNode = {
|
|
7
|
+
type: 'sequence';
|
|
8
|
+
nodes: StringNode[];
|
|
9
|
+
};
|
|
10
|
+
type StringChoiceNode = {
|
|
11
|
+
type: 'choice';
|
|
12
|
+
nodes: StringNode[];
|
|
13
|
+
};
|
|
14
|
+
export type { StringNode, StringTextNode, StringSequenceNode, StringChoiceNode, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.36",
|
|
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.4"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@babel/types": "^7.28.4",
|