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
|
@@ -5,7 +5,7 @@ import * as t from '@babel/types';
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { parse } from '@babel/parser';
|
|
7
7
|
import addGTIdentifierToSyntaxTree from './addGTIdentifierToSyntaxTree.js';
|
|
8
|
-
import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidStaticInitSync, warnRecursiveFunctionCallSync, } from '../../../../console/index.js';
|
|
8
|
+
import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnInvalidStaticChildSync, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidStaticInitSync, warnRecursiveFunctionCallSync, } from '../../../../console/index.js';
|
|
9
9
|
import { isAcceptedPluralForm } from 'generaltranslation/internal';
|
|
10
10
|
import { isStaticExpression } from '../../evaluateJsx.js';
|
|
11
11
|
import { STATIC_COMPONENT, TRANSLATION_COMPONENT, VARIABLE_COMPONENTS, } from '../constants.js';
|
|
@@ -16,7 +16,7 @@ import { buildImportMap } from '../buildImportMap.js';
|
|
|
16
16
|
import { getPathsAndAliases } from '../getPathsAndAliases.js';
|
|
17
17
|
import { parseTProps } from './parseTProps.js';
|
|
18
18
|
import { handleChildrenWhitespace } from './handleChildrenWhitespace.js';
|
|
19
|
-
import { isElementNode } from './types.js';
|
|
19
|
+
import { isElementNode, } from './types.js';
|
|
20
20
|
import { multiplyJsxTree } from './multiplication/multiplyJsxTree.js';
|
|
21
21
|
import { removeNullChildrenFields } from './removeNullChildrenFields.js';
|
|
22
22
|
import path from 'node:path';
|
|
@@ -77,31 +77,14 @@ export function parseTranslationComponent({ originalName, importAliases, localNa
|
|
|
77
77
|
* @param insideT - Whether the current node is inside a <T> component
|
|
78
78
|
* @returns The built JSX tree
|
|
79
79
|
*/
|
|
80
|
-
export function buildJSXTree({ importAliases, node, unwrappedExpressions,
|
|
80
|
+
export function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, callStack, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkgs, }) {
|
|
81
81
|
if (t.isJSXExpressionContainer(node)) {
|
|
82
82
|
// Skip JSX comments
|
|
83
83
|
if (t.isJSXEmptyExpression(node.expression)) {
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
|
-
if (inStatic) {
|
|
87
|
-
return processStaticExpression({
|
|
88
|
-
unwrappedExpressions,
|
|
89
|
-
scopeNode,
|
|
90
|
-
expressionNodePath: helperPath.get('expression'),
|
|
91
|
-
importAliases,
|
|
92
|
-
visited: visited,
|
|
93
|
-
callStack,
|
|
94
|
-
updates,
|
|
95
|
-
errors,
|
|
96
|
-
warnings,
|
|
97
|
-
file,
|
|
98
|
-
parsingOptions,
|
|
99
|
-
importedFunctionsMap,
|
|
100
|
-
pkgs,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
86
|
const expr = node.expression;
|
|
104
|
-
if (t.isJSXElement(expr)
|
|
87
|
+
if (t.isJSXElement(expr)) {
|
|
105
88
|
return buildJSXTree({
|
|
106
89
|
importAliases,
|
|
107
90
|
node: expr,
|
|
@@ -109,16 +92,14 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
109
92
|
visited,
|
|
110
93
|
callStack,
|
|
111
94
|
updates,
|
|
112
|
-
errors,
|
|
113
|
-
warnings,
|
|
95
|
+
errors: errors,
|
|
96
|
+
warnings: warnings,
|
|
114
97
|
file,
|
|
115
98
|
insideT,
|
|
116
99
|
parsingOptions,
|
|
117
100
|
scopeNode,
|
|
118
101
|
importedFunctionsMap,
|
|
119
102
|
pkgs,
|
|
120
|
-
inStatic,
|
|
121
|
-
helperPath: helperPath.get('expression'),
|
|
122
103
|
});
|
|
123
104
|
}
|
|
124
105
|
const staticAnalysis = isStaticExpression(expr, true);
|
|
@@ -164,10 +145,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
164
145
|
const props = {};
|
|
165
146
|
const elementIsPlural = componentType === 'Plural';
|
|
166
147
|
const elementIsBranch = componentType === 'Branch';
|
|
167
|
-
element.openingElement.attributes.forEach((attr
|
|
168
|
-
const helperAttribute = helperPath
|
|
169
|
-
.get('openingElement')
|
|
170
|
-
.get('attributes')[index];
|
|
148
|
+
element.openingElement.attributes.forEach((attr) => {
|
|
171
149
|
if (t.isJSXAttribute(attr)) {
|
|
172
150
|
const attrName = attr.name.name;
|
|
173
151
|
let attrValue = null;
|
|
@@ -176,24 +154,34 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
176
154
|
attrValue = attr.value.value;
|
|
177
155
|
}
|
|
178
156
|
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
179
|
-
const helperValue = helperAttribute.get('value');
|
|
180
157
|
// Check if this is an HTML content prop (title, placeholder, alt, etc.)
|
|
181
158
|
const isHtmlContentProp = Object.values(HTML_CONTENT_PROPS).includes(attrName);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
unwrappedExpressions.push(generate(attr.value).code);
|
|
159
|
+
if (isHtmlContentProp) {
|
|
160
|
+
// For HTML content props, only accept static string expressions
|
|
161
|
+
const staticAnalysis = isStaticExpression(attr.value.expression, true);
|
|
162
|
+
if (staticAnalysis.isStatic &&
|
|
163
|
+
staticAnalysis.value !== undefined) {
|
|
164
|
+
attrValue = staticAnalysis.value;
|
|
189
165
|
}
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
166
|
+
// Otherwise attrValue stays null and won't be included
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// For non-HTML-content props, validate plural/branch then build tree
|
|
170
|
+
if ((elementIsPlural && isAcceptedPluralForm(attrName)) ||
|
|
171
|
+
(elementIsBranch && attrName !== 'branch')) {
|
|
172
|
+
// Make sure that variable strings like {`I have ${count} book`} are invalid!
|
|
173
|
+
if (t.isTemplateLiteral(attr.value.expression) &&
|
|
174
|
+
!isStaticExpression(attr.value.expression, true).isStatic) {
|
|
175
|
+
unwrappedExpressions.push(generate(attr.value).code);
|
|
176
|
+
}
|
|
177
|
+
// If it's an array, flag as an unwrapped expression
|
|
178
|
+
if (t.isArrayExpression(attr.value.expression)) {
|
|
179
|
+
unwrappedExpressions.push(generate(attr.value.expression).code);
|
|
180
|
+
}
|
|
193
181
|
}
|
|
194
182
|
attrValue = buildJSXTree({
|
|
195
183
|
importAliases,
|
|
196
|
-
node: attr.value,
|
|
184
|
+
node: attr.value.expression,
|
|
197
185
|
unwrappedExpressions,
|
|
198
186
|
visited,
|
|
199
187
|
callStack,
|
|
@@ -206,19 +194,8 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
206
194
|
scopeNode,
|
|
207
195
|
importedFunctionsMap,
|
|
208
196
|
pkgs,
|
|
209
|
-
inStatic,
|
|
210
|
-
helperPath: helperValue,
|
|
211
197
|
});
|
|
212
198
|
}
|
|
213
|
-
// For HTML content props, only accept static string expressions
|
|
214
|
-
else if (isHtmlContentProp) {
|
|
215
|
-
const staticAnalysis = isStaticExpression(attr.value.expression, true);
|
|
216
|
-
if (staticAnalysis.isStatic &&
|
|
217
|
-
staticAnalysis.value !== undefined) {
|
|
218
|
-
attrValue = staticAnalysis.value;
|
|
219
|
-
}
|
|
220
|
-
// Otherwise attrValue stays null and won't be included
|
|
221
|
-
}
|
|
222
199
|
}
|
|
223
200
|
}
|
|
224
201
|
props[attrName] = attrValue;
|
|
@@ -226,43 +203,36 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
226
203
|
});
|
|
227
204
|
if (elementIsVariable) {
|
|
228
205
|
if (componentType === STATIC_COMPONENT) {
|
|
229
|
-
const helperElement = helperPath.get('children');
|
|
230
|
-
const results = {
|
|
231
|
-
nodeType: 'element',
|
|
232
|
-
type: STATIC_COMPONENT,
|
|
233
|
-
props,
|
|
234
|
-
};
|
|
235
|
-
// Create children array if necessary
|
|
236
|
-
if (element.children.length) {
|
|
237
|
-
results.props.children = [];
|
|
238
|
-
}
|
|
239
206
|
if (visited === null) {
|
|
240
207
|
visited = new Set();
|
|
241
208
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
pkgs,
|
|
259
|
-
inStatic: true,
|
|
260
|
-
helperPath: helperChild,
|
|
261
|
-
});
|
|
262
|
-
results.props.children.push(result);
|
|
263
|
-
}
|
|
264
|
-
return results;
|
|
209
|
+
return resolveStaticComponentChildren({
|
|
210
|
+
importAliases,
|
|
211
|
+
scopeNode,
|
|
212
|
+
children: element.children,
|
|
213
|
+
unwrappedExpressions,
|
|
214
|
+
visited,
|
|
215
|
+
updates,
|
|
216
|
+
errors,
|
|
217
|
+
warnings,
|
|
218
|
+
file,
|
|
219
|
+
callStack,
|
|
220
|
+
parsingOptions,
|
|
221
|
+
importedFunctionsMap,
|
|
222
|
+
pkgs,
|
|
223
|
+
props,
|
|
224
|
+
});
|
|
265
225
|
}
|
|
226
|
+
// I do not see why this is being called, i am disabling this for now:
|
|
227
|
+
// parseJSXElement({
|
|
228
|
+
// importAliases,
|
|
229
|
+
// node: element,
|
|
230
|
+
// updates,
|
|
231
|
+
// errors,
|
|
232
|
+
// warnings,
|
|
233
|
+
// file,
|
|
234
|
+
// parsingOptions,
|
|
235
|
+
// });
|
|
266
236
|
return {
|
|
267
237
|
nodeType: 'element',
|
|
268
238
|
// if componentType is undefined, use typeName
|
|
@@ -272,7 +242,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
272
242
|
};
|
|
273
243
|
}
|
|
274
244
|
const children = element.children
|
|
275
|
-
.map((child
|
|
245
|
+
.map((child) => buildJSXTree({
|
|
276
246
|
importAliases,
|
|
277
247
|
node: child,
|
|
278
248
|
unwrappedExpressions,
|
|
@@ -287,8 +257,6 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
287
257
|
scopeNode,
|
|
288
258
|
importedFunctionsMap,
|
|
289
259
|
pkgs,
|
|
290
|
-
inStatic,
|
|
291
|
-
helperPath: helperPath.get('children')[index],
|
|
292
260
|
}))
|
|
293
261
|
.filter((child) => child !== null && child !== '');
|
|
294
262
|
if (children.length === 1) {
|
|
@@ -308,7 +276,7 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
308
276
|
// If it's a JSX fragment
|
|
309
277
|
else if (t.isJSXFragment(node)) {
|
|
310
278
|
const children = node.children
|
|
311
|
-
.map((child
|
|
279
|
+
.map((child) => buildJSXTree({
|
|
312
280
|
importAliases,
|
|
313
281
|
node: child,
|
|
314
282
|
unwrappedExpressions,
|
|
@@ -323,8 +291,6 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
323
291
|
scopeNode,
|
|
324
292
|
importedFunctionsMap,
|
|
325
293
|
pkgs,
|
|
326
|
-
inStatic,
|
|
327
|
-
helperPath: helperPath.get('children')[index],
|
|
328
294
|
}))
|
|
329
295
|
.filter((child) => child !== null && child !== '');
|
|
330
296
|
const props = {};
|
|
@@ -374,59 +340,6 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
374
340
|
}
|
|
375
341
|
return generate(node).code;
|
|
376
342
|
}
|
|
377
|
-
else if ((t.isCallExpression(node) && t.isIdentifier(node.callee)) ||
|
|
378
|
-
(t.isAwaitExpression(node) &&
|
|
379
|
-
t.isCallExpression(node.argument) &&
|
|
380
|
-
t.isIdentifier(node.argument.callee))) {
|
|
381
|
-
if (inStatic) {
|
|
382
|
-
const callExpression = (node.type === 'AwaitExpression' ? node.argument : node);
|
|
383
|
-
const callee = callExpression.callee;
|
|
384
|
-
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
385
|
-
if (!calleeBinding) {
|
|
386
|
-
warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
return resolveStaticFunctionInvocationFromBinding({
|
|
390
|
-
importAliases,
|
|
391
|
-
calleeBinding,
|
|
392
|
-
callee,
|
|
393
|
-
visited: visited, // we know this is true bc of inStatic
|
|
394
|
-
callStack,
|
|
395
|
-
file,
|
|
396
|
-
updates,
|
|
397
|
-
errors,
|
|
398
|
-
warnings,
|
|
399
|
-
unwrappedExpressions,
|
|
400
|
-
pkgs,
|
|
401
|
-
parsingOptions,
|
|
402
|
-
importedFunctionsMap,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
unwrappedExpressions.push(generate(node).code);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
else if (t.isParenthesizedExpression(node)) {
|
|
410
|
-
const child = node.expression;
|
|
411
|
-
return buildJSXTree({
|
|
412
|
-
importAliases,
|
|
413
|
-
node: child,
|
|
414
|
-
unwrappedExpressions,
|
|
415
|
-
visited,
|
|
416
|
-
callStack,
|
|
417
|
-
updates,
|
|
418
|
-
errors,
|
|
419
|
-
warnings,
|
|
420
|
-
file,
|
|
421
|
-
insideT,
|
|
422
|
-
parsingOptions,
|
|
423
|
-
scopeNode,
|
|
424
|
-
importedFunctionsMap,
|
|
425
|
-
pkgs,
|
|
426
|
-
inStatic,
|
|
427
|
-
helperPath: helperPath.get('expression'),
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
343
|
// If it's some other JS expression
|
|
431
344
|
else if (t.isIdentifier(node) ||
|
|
432
345
|
t.isMemberExpression(node) ||
|
|
@@ -434,17 +347,11 @@ export function buildJSXTree({ importAliases, node, unwrappedExpressions, inStat
|
|
|
434
347
|
t.isBinaryExpression(node) ||
|
|
435
348
|
t.isLogicalExpression(node) ||
|
|
436
349
|
t.isConditionalExpression(node)) {
|
|
437
|
-
|
|
350
|
+
return generate(node).code;
|
|
438
351
|
}
|
|
439
352
|
else {
|
|
440
|
-
|
|
441
|
-
unwrappedExpressions.push(node);
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
unwrappedExpressions.push(generate(node).code);
|
|
445
|
-
}
|
|
353
|
+
return generate(node).code;
|
|
446
354
|
}
|
|
447
|
-
return null;
|
|
448
355
|
}
|
|
449
356
|
// end buildJSXTree
|
|
450
357
|
// Parses a JSX element and adds it to the updates array
|
|
@@ -486,8 +393,6 @@ export function parseJSXElement({ importAliases, node, originalName, pkgs, updat
|
|
|
486
393
|
insideT: false,
|
|
487
394
|
parsingOptions,
|
|
488
395
|
importedFunctionsMap,
|
|
489
|
-
inStatic: false,
|
|
490
|
-
helperPath: scopeNode,
|
|
491
396
|
});
|
|
492
397
|
// Strip the outer <T> component if necessary
|
|
493
398
|
const jsxTree = isElementNode(treeResult) && treeResult.props?.children
|
|
@@ -533,6 +438,86 @@ export function parseJSXElement({ importAliases, node, originalName, pkgs, updat
|
|
|
533
438
|
});
|
|
534
439
|
}
|
|
535
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Resolves an invocation inside of a <Static> component. It will resolve the function, and build
|
|
443
|
+
* a jsx tree for each return inside of the function definition.
|
|
444
|
+
*
|
|
445
|
+
* function getOtherSubject() {
|
|
446
|
+
* return <div>Jane</div>;
|
|
447
|
+
* }
|
|
448
|
+
*
|
|
449
|
+
* function getSubject() {
|
|
450
|
+
* if (condition) return getOtherSubject();
|
|
451
|
+
* return <div>John</div>;
|
|
452
|
+
* }
|
|
453
|
+
* ...
|
|
454
|
+
* <Static>
|
|
455
|
+
* {getSubject()}
|
|
456
|
+
* </Static>
|
|
457
|
+
*/
|
|
458
|
+
function resolveStaticComponentChildren({ importAliases, scopeNode, children, unwrappedExpressions, visited, updates, errors, warnings, file, callStack, parsingOptions, importedFunctionsMap, pkgs, props, }) {
|
|
459
|
+
const result = {
|
|
460
|
+
nodeType: 'element',
|
|
461
|
+
type: STATIC_COMPONENT,
|
|
462
|
+
props,
|
|
463
|
+
};
|
|
464
|
+
let found = false;
|
|
465
|
+
// Create children array if necessary
|
|
466
|
+
if (children.length) {
|
|
467
|
+
result.props.children = [];
|
|
468
|
+
}
|
|
469
|
+
for (const child of children) {
|
|
470
|
+
// Ignore whitespace outside of jsx container
|
|
471
|
+
if (t.isJSXText(child) && child.value.trim() === '') {
|
|
472
|
+
result.props.children.push(child.value);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
// Must be an expression container with a function invocation
|
|
476
|
+
if (!t.isJSXExpressionContainer(child) ||
|
|
477
|
+
!((t.isCallExpression(child.expression) &&
|
|
478
|
+
t.isIdentifier(child.expression.callee)) ||
|
|
479
|
+
(t.isAwaitExpression(child.expression) &&
|
|
480
|
+
t.isCallExpression(child.expression.argument) &&
|
|
481
|
+
t.isIdentifier(child.expression.argument.callee))) ||
|
|
482
|
+
found // There can only be one invocation inside of a <Static> component
|
|
483
|
+
) {
|
|
484
|
+
errors.push(warnInvalidStaticChildSync(file, `${child.loc?.start?.line}:${child.loc?.start?.column}`));
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
// Set found to true
|
|
488
|
+
found = true;
|
|
489
|
+
// Get callee and binding from scope
|
|
490
|
+
const callee = (t.isAwaitExpression(child.expression)
|
|
491
|
+
? child.expression.argument.callee
|
|
492
|
+
: child.expression.callee);
|
|
493
|
+
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
494
|
+
if (!calleeBinding) {
|
|
495
|
+
warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
// Function is found locally, return wrapped in an expression
|
|
499
|
+
const staticFunctionInvocation = resolveStaticFunctionInvocationFromBinding({
|
|
500
|
+
importAliases,
|
|
501
|
+
calleeBinding,
|
|
502
|
+
callee,
|
|
503
|
+
visited,
|
|
504
|
+
callStack,
|
|
505
|
+
file,
|
|
506
|
+
updates,
|
|
507
|
+
errors,
|
|
508
|
+
warnings,
|
|
509
|
+
unwrappedExpressions,
|
|
510
|
+
pkgs,
|
|
511
|
+
parsingOptions,
|
|
512
|
+
importedFunctionsMap,
|
|
513
|
+
});
|
|
514
|
+
result.props.children.push({
|
|
515
|
+
nodeType: 'expression',
|
|
516
|
+
result: staticFunctionInvocation,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
536
521
|
function resolveStaticFunctionInvocationFromBinding({ importAliases, calleeBinding, callee, unwrappedExpressions, visited, callStack, file, updates, errors, warnings, parsingOptions, importedFunctionsMap, pkgs, }) {
|
|
537
522
|
function withRecusionGuard({ cb, filename, functionName, }) {
|
|
538
523
|
const cacheKey = `${filename}::${functionName}`;
|
|
@@ -672,7 +657,7 @@ function processFunctionInFile({ filePath, functionName, visited, callStack, par
|
|
|
672
657
|
});
|
|
673
658
|
const { importAliases } = getPathsAndAliases(ast, pkgs);
|
|
674
659
|
// Collect all imports in this file to track cross-file function calls
|
|
675
|
-
let importedFunctionsMap
|
|
660
|
+
let importedFunctionsMap;
|
|
676
661
|
traverse(ast, {
|
|
677
662
|
Program(path) {
|
|
678
663
|
importedFunctionsMap = buildImportMap(path);
|
|
@@ -809,8 +794,9 @@ function processFunctionDeclarationNodePath({ functionName, path, importAliases,
|
|
|
809
794
|
if (!returnNodePath.isExpression()) {
|
|
810
795
|
return;
|
|
811
796
|
}
|
|
812
|
-
result.branches.push(
|
|
797
|
+
result.branches.push(processReturnExpression({
|
|
813
798
|
unwrappedExpressions,
|
|
799
|
+
functionName,
|
|
814
800
|
pkgs,
|
|
815
801
|
callStack,
|
|
816
802
|
scopeNode: returnNodePath,
|
|
@@ -851,8 +837,9 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
851
837
|
const bodyNodePath = arrowFunctionPath.get('body');
|
|
852
838
|
if (bodyNodePath.isExpression()) {
|
|
853
839
|
// process expression return
|
|
854
|
-
result.branches.push(
|
|
840
|
+
result.branches.push(processReturnExpression({
|
|
855
841
|
unwrappedExpressions,
|
|
842
|
+
functionName,
|
|
856
843
|
pkgs,
|
|
857
844
|
scopeNode: arrowFunctionPath,
|
|
858
845
|
expressionNodePath: bodyNodePath,
|
|
@@ -878,8 +865,9 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
878
865
|
if (!returnNodePath.isExpression()) {
|
|
879
866
|
return;
|
|
880
867
|
}
|
|
881
|
-
result.branches.push(
|
|
868
|
+
result.branches.push(processReturnExpression({
|
|
882
869
|
unwrappedExpressions,
|
|
870
|
+
functionName,
|
|
883
871
|
pkgs,
|
|
884
872
|
scopeNode: returnPath,
|
|
885
873
|
expressionNodePath: returnNodePath,
|
|
@@ -903,15 +891,15 @@ function processVariableDeclarationNodePath({ functionName, path, importAliases,
|
|
|
903
891
|
return result;
|
|
904
892
|
}
|
|
905
893
|
/**
|
|
906
|
-
* Process a
|
|
894
|
+
* Process a expression being returned from a function
|
|
907
895
|
*/
|
|
908
|
-
function
|
|
896
|
+
function processReturnExpression({ unwrappedExpressions, scopeNode, expressionNodePath, importAliases, visited, callStack, updates, errors, warnings, file, parsingOptions, importedFunctionsMap, functionName, pkgs, }) {
|
|
909
897
|
// // If the node is null, return
|
|
910
898
|
// if (expressionNodePath == null) return null;
|
|
911
899
|
// Remove parentheses if they exist
|
|
912
900
|
if (t.isParenthesizedExpression(expressionNodePath.node)) {
|
|
913
901
|
// ex: return (value)
|
|
914
|
-
return
|
|
902
|
+
return processReturnExpression({
|
|
915
903
|
unwrappedExpressions,
|
|
916
904
|
importAliases,
|
|
917
905
|
scopeNode,
|
|
@@ -923,6 +911,7 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
923
911
|
warnings,
|
|
924
912
|
file,
|
|
925
913
|
parsingOptions,
|
|
914
|
+
functionName,
|
|
926
915
|
importedFunctionsMap,
|
|
927
916
|
pkgs,
|
|
928
917
|
});
|
|
@@ -936,7 +925,7 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
936
925
|
warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
937
926
|
return null;
|
|
938
927
|
}
|
|
939
|
-
// Function is found
|
|
928
|
+
// Function is found locally
|
|
940
929
|
return resolveStaticFunctionInvocationFromBinding({
|
|
941
930
|
importAliases,
|
|
942
931
|
calleeBinding,
|
|
@@ -963,7 +952,7 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
963
952
|
warnings.add(warnFunctionNotFoundSync(file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
964
953
|
return null;
|
|
965
954
|
}
|
|
966
|
-
// Function is found
|
|
955
|
+
// Function is found locally
|
|
967
956
|
return resolveStaticFunctionInvocationFromBinding({
|
|
968
957
|
importAliases,
|
|
969
958
|
calleeBinding,
|
|
@@ -998,8 +987,6 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
998
987
|
scopeNode,
|
|
999
988
|
importedFunctionsMap,
|
|
1000
989
|
pkgs,
|
|
1001
|
-
inStatic: true,
|
|
1002
|
-
helperPath: expressionNodePath,
|
|
1003
990
|
});
|
|
1004
991
|
}
|
|
1005
992
|
else if (t.isConditionalExpression(expressionNodePath.node)) {
|
|
@@ -1009,7 +996,7 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
1009
996
|
const alternateNodePath = expressionNodePath.get('alternate');
|
|
1010
997
|
const result = {
|
|
1011
998
|
nodeType: 'multiplication',
|
|
1012
|
-
branches: [consequentNodePath, alternateNodePath].map((expressionNodePath) =>
|
|
999
|
+
branches: [consequentNodePath, alternateNodePath].map((expressionNodePath) => processReturnExpression({
|
|
1013
1000
|
unwrappedExpressions,
|
|
1014
1001
|
importAliases,
|
|
1015
1002
|
scopeNode,
|
|
@@ -1021,6 +1008,7 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
1021
1008
|
warnings,
|
|
1022
1009
|
file,
|
|
1023
1010
|
parsingOptions,
|
|
1011
|
+
functionName,
|
|
1024
1012
|
importedFunctionsMap,
|
|
1025
1013
|
pkgs,
|
|
1026
1014
|
})),
|
|
@@ -1043,8 +1031,6 @@ function processStaticExpression({ unwrappedExpressions, scopeNode, expressionNo
|
|
|
1043
1031
|
scopeNode,
|
|
1044
1032
|
importedFunctionsMap,
|
|
1045
1033
|
pkgs,
|
|
1046
|
-
inStatic: true,
|
|
1047
|
-
helperPath: expressionNodePath,
|
|
1048
1034
|
});
|
|
1049
1035
|
}
|
|
1050
1036
|
}
|
|
@@ -5,16 +5,6 @@ import type { ParsingConfigOptions } from '../../../types/parsing.js';
|
|
|
5
5
|
* Clears all caches. Useful for testing or when file system changes.
|
|
6
6
|
*/
|
|
7
7
|
export declare function clearParsingCaches(): void;
|
|
8
|
-
/**
|
|
9
|
-
* Recursively resolves variable assignments to find all aliases of a translation callback parameter.
|
|
10
|
-
* Handles cases like: const t = translate; const a = translate; const b = a; const c = b;
|
|
11
|
-
*
|
|
12
|
-
* @param scope The scope to search within
|
|
13
|
-
* @param variableName The variable name to resolve
|
|
14
|
-
* @param visited Set to track already visited variables to prevent infinite loops
|
|
15
|
-
* @returns Array of all variable names that reference the original translation callback
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolveVariableAliases(scope: any, variableName: string, visited?: Set<string>): string[];
|
|
18
8
|
/**
|
|
19
9
|
* Main entry point for parsing translation strings from useGT() and getGT() calls.
|
|
20
10
|
*
|