MCPcopy
hub / github.com/lingodotdev/lingo.dev / traverse

Function traverse

packages/cli/src/cli/loaders/mjml.ts:154–190  ·  view source on GitHub ↗
(
  node: any,
  visitor: (node: any, path: string, componentName: string) => string | undefined,
  path: string = "",
)

Source from the content-addressed store, hash-verified

152}
153
154function traverse(
155 node: any,
156 visitor: (node: any, path: string, componentName: string) => string | undefined,
157 path: string = "",
158) {
159 if (!node || typeof node !== "object") {
160 return;
161 }
162
163 const children = node.$$;
164 if (!Array.isArray(children)) {
165 return;
166 }
167
168 const elementCounts = new Map<string, number>();
169
170 children.forEach((child: any) => {
171 const elementName = child["#name"];
172
173 if (!elementName || elementName.startsWith("__")) {
174 return;
175 }
176
177 const currentIndex = elementCounts.get(elementName) || 0;
178 elementCounts.set(elementName, currentIndex + 1);
179
180 const currentPath = path
181 ? `${path}/${elementName}/${currentIndex}`
182 : `${elementName}/${currentIndex}`;
183
184 const result = visitor(child, currentPath, elementName);
185
186 if (result !== "SKIP_CHILDREN") {
187 traverse(child, visitor, currentPath);
188 }
189 });
190}
191
192function getInnerHTML(node: any): string | null {
193 if (!node.$$ || !Array.isArray(node.$$)) {

Callers 15

pullFunction · 0.70
pushFunction · 0.70
jsx-provider.tsFile · 0.50
jsx-html-lang.tsFile · 0.50
jsxFragmentMutationFunction · 0.50
_getProgramNodePathFunction · 0.50
getJSXElementPathFunction · 0.50
getJsxRootsFunction · 0.50
findExistingImportFunction · 0.50
generateUniqueImportNameFunction · 0.50

Calls 2

getMethod · 0.65
setMethod · 0.65

Tested by 9

getJSXElementPathFunction · 0.40
createMockDataFunction · 0.40
getJSXElementPathFunction · 0.40
getFirstJsxFunction · 0.40
getJSXElementPathFunction · 0.40
getJSXElementPathFunction · 0.40
getJSXElementPathsFunction · 0.40
getJSXElementPathFunction · 0.40
testIsReactComponentFunction · 0.40