gtx-cli 2.4.14 → 2.5.0-alpha.0
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 +0 -7
- package/dist/console/colors.d.ts +1 -0
- package/dist/console/colors.js +3 -0
- package/dist/console/index.d.ts +6 -0
- package/dist/console/index.js +13 -2
- package/dist/react/jsx/evaluateJsx.d.ts +5 -6
- package/dist/react/jsx/evaluateJsx.js +32 -4
- package/dist/react/jsx/utils/buildImportMap.d.ts +9 -0
- package/dist/react/jsx/utils/buildImportMap.js +30 -0
- package/dist/react/jsx/utils/constants.d.ts +2 -0
- package/dist/react/jsx/utils/constants.js +11 -2
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +17 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +89 -0
- package/dist/react/{data-_gt → jsx/utils/jsxParsing}/addGTIdentifierToSyntaxTree.d.ts +2 -1
- package/dist/react/{data-_gt → jsx/utils/jsxParsing}/addGTIdentifierToSyntaxTree.js +30 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +6 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +199 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +13 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +42 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +5 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +69 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +60 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +949 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +8 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +47 -0
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +48 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +34 -0
- package/dist/react/jsx/utils/parseStringFunction.js +4 -141
- package/dist/react/jsx/utils/resolveImportPath.d.ts +11 -0
- package/dist/react/jsx/utils/resolveImportPath.js +111 -0
- package/dist/react/parse/createInlineUpdates.js +19 -70
- package/package.json +2 -2
- package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
- package/dist/react/jsx/trimJsxStringChildren.js +0 -122
- package/dist/react/jsx/utils/parseJsx.d.ts +0 -21
- package/dist/react/jsx/utils/parseJsx.js +0 -259
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WhitespaceJsxTreeResult, WhitespaceMultiplicationNode } from '../types.js';
|
|
2
|
+
export type MultiplicationNodeResult = {
|
|
3
|
+
parent: any | undefined;
|
|
4
|
+
key: string | undefined;
|
|
5
|
+
node: WhitespaceMultiplicationNode;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Finds the immediate multiplication node from the given root (eg no nested multiplication nodes)
|
|
9
|
+
* TODO: I am sure there is some optimization to be done here
|
|
10
|
+
*
|
|
11
|
+
* Maybe there is an optimization here with caching used paths btwn calls
|
|
12
|
+
*/
|
|
13
|
+
export declare function findMultiplicationNode(root: WhitespaceJsxTreeResult | WhitespaceMultiplicationNode | (WhitespaceJsxTreeResult | WhitespaceMultiplicationNode)[]): MultiplicationNodeResult | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isWhitespaceMultiplicationNode, isWhitespaceJsxTree, } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Finds the immediate multiplication node from the given root (eg no nested multiplication nodes)
|
|
4
|
+
* TODO: I am sure there is some optimization to be done here
|
|
5
|
+
*
|
|
6
|
+
* Maybe there is an optimization here with caching used paths btwn calls
|
|
7
|
+
*/
|
|
8
|
+
export function findMultiplicationNode(root) {
|
|
9
|
+
// Entry point
|
|
10
|
+
return handleChildren(root, undefined, undefined);
|
|
11
|
+
// Helper function to handle children
|
|
12
|
+
function handleChildren(curr, parent, key) {
|
|
13
|
+
if (Array.isArray(curr)) {
|
|
14
|
+
for (const [index, child] of Object.entries(curr)) {
|
|
15
|
+
const result = handleChild(child, parent, index);
|
|
16
|
+
if (result)
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return handleChild(curr, parent, key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Helper function to handle a single child
|
|
26
|
+
function handleChild(curr, parent, key) {
|
|
27
|
+
if (isWhitespaceMultiplicationNode(curr)) {
|
|
28
|
+
return { parent, key, node: curr };
|
|
29
|
+
}
|
|
30
|
+
else if (isWhitespaceJsxTree(curr)) {
|
|
31
|
+
if (curr.props?.children) {
|
|
32
|
+
return handleChildren(curr.props.children, curr.props, 'children');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { findMultiplicationNode } from './findMultiplicationNode.js';
|
|
2
|
+
/**
|
|
3
|
+
* Given a JSX tree, multiply the static function nodes
|
|
4
|
+
*/
|
|
5
|
+
export function multiplyJsxTree(tree) {
|
|
6
|
+
if (!Array.isArray(tree)) {
|
|
7
|
+
return multiplyBranches([tree]);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
// when tree is an array, this is just sibbling elements within the <T>, so we need to treat them as a single branch
|
|
11
|
+
const wrapperElement = {
|
|
12
|
+
nodeType: 'element',
|
|
13
|
+
type: 'T',
|
|
14
|
+
props: {
|
|
15
|
+
children: tree,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
// Multiply the wrapper element
|
|
19
|
+
const multipliedBranches = multiplyBranches([
|
|
20
|
+
wrapperElement,
|
|
21
|
+
]);
|
|
22
|
+
// Unwrap the branches
|
|
23
|
+
return multipliedBranches.map((branch) => branch.props.children);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Given a list of branches, multiply recursively (DFS)
|
|
28
|
+
* @param branches
|
|
29
|
+
*/
|
|
30
|
+
function multiplyBranches(branches) {
|
|
31
|
+
// Queue of branches to process
|
|
32
|
+
const branchQueue = branches;
|
|
33
|
+
// Finalized branches
|
|
34
|
+
const newBranches = [];
|
|
35
|
+
// Process branches until exhausted
|
|
36
|
+
while (branchQueue.length) {
|
|
37
|
+
// Pop the next branch
|
|
38
|
+
const branch = branchQueue.shift();
|
|
39
|
+
// Get closest multiplication node
|
|
40
|
+
const currentNode = findMultiplicationNode(branch);
|
|
41
|
+
// No multiplication nodes, just add the branch to the final list
|
|
42
|
+
if (!currentNode) {
|
|
43
|
+
newBranches.push(branch);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const { node, parent, key } = currentNode;
|
|
47
|
+
// Recursive call
|
|
48
|
+
const subBranches = multiplyBranches(node.branches);
|
|
49
|
+
// For every sub branch, create a new cloned branch
|
|
50
|
+
for (const subBranch of subBranches) {
|
|
51
|
+
// Placeholder for the new branch
|
|
52
|
+
let newBranch = undefined;
|
|
53
|
+
// Create a clone of the original with the sub branch swapped in
|
|
54
|
+
if (parent === undefined || key === undefined) {
|
|
55
|
+
// This means the subBranch directly replaces the branch itself
|
|
56
|
+
newBranches.push(subBranch);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Replace the multiplication node with the sub branch
|
|
60
|
+
parent[key] = subBranch;
|
|
61
|
+
// eslint-disable-next-line no-undef
|
|
62
|
+
newBranch = structuredClone(branch);
|
|
63
|
+
// Add the new branch to the list
|
|
64
|
+
branchQueue.push(newBranch);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return newBranches;
|
|
69
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Updates } from '../../../../types/index.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import { NodePath } from '@babel/traverse';
|
|
4
|
+
import { ParsingConfigOptions } from '../../../../types/parsing.js';
|
|
5
|
+
import traverseModule from '@babel/traverse';
|
|
6
|
+
import { JsxTree } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Entry point for JSX parsing
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseTranslationComponent({ originalName, importAliases, localName, path, updates, errors, warnings, file, parsingOptions, pkg, }: {
|
|
11
|
+
ast: any;
|
|
12
|
+
pkg: 'gt-react' | 'gt-next';
|
|
13
|
+
originalName: string;
|
|
14
|
+
importAliases: Record<string, string>;
|
|
15
|
+
path: traverseModule.NodePath<traverseModule.Node>;
|
|
16
|
+
localName: string;
|
|
17
|
+
updates: Updates;
|
|
18
|
+
errors: string[];
|
|
19
|
+
warnings: Set<string>;
|
|
20
|
+
file: string;
|
|
21
|
+
parsingOptions: ParsingConfigOptions;
|
|
22
|
+
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a JSX tree from a given node, recursively handling children.
|
|
25
|
+
* @param node - The node to build the tree from
|
|
26
|
+
* @param unwrappedExpressions - An array to store unwrapped expressions
|
|
27
|
+
* @param updates - The updates array
|
|
28
|
+
* @param errors - The errors array
|
|
29
|
+
* @param file - The file name
|
|
30
|
+
* @param insideT - Whether the current node is inside a <T> component
|
|
31
|
+
* @returns The built JSX tree
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildJSXTree({ importAliases, node, unwrappedExpressions, visited, updates, errors, warnings, file, insideT, parsingOptions, scopeNode, importedFunctionsMap, pkg, }: {
|
|
34
|
+
importAliases: Record<string, string>;
|
|
35
|
+
node: any;
|
|
36
|
+
unwrappedExpressions: string[];
|
|
37
|
+
visited: Set<string>;
|
|
38
|
+
updates: Updates;
|
|
39
|
+
errors: string[];
|
|
40
|
+
warnings: Set<string>;
|
|
41
|
+
file: string;
|
|
42
|
+
insideT: boolean;
|
|
43
|
+
parsingOptions: ParsingConfigOptions;
|
|
44
|
+
scopeNode: NodePath;
|
|
45
|
+
importedFunctionsMap: Map<string, string>;
|
|
46
|
+
pkg: 'gt-react' | 'gt-next';
|
|
47
|
+
}): JsxTree;
|
|
48
|
+
export declare function parseJSXElement({ importAliases, node, originalName, pkg, updates, errors, warnings, file, parsingOptions, scopeNode, importedFunctionsMap, }: {
|
|
49
|
+
importAliases: Record<string, string>;
|
|
50
|
+
node: t.JSXElement;
|
|
51
|
+
originalName: string;
|
|
52
|
+
pkg: 'gt-react' | 'gt-next';
|
|
53
|
+
updates: Updates;
|
|
54
|
+
errors: string[];
|
|
55
|
+
warnings: Set<string>;
|
|
56
|
+
file: string;
|
|
57
|
+
parsingOptions: ParsingConfigOptions;
|
|
58
|
+
scopeNode: NodePath<t.JSXElement>;
|
|
59
|
+
importedFunctionsMap: Map<string, string>;
|
|
60
|
+
}): void;
|