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

Function getJsxElementName

packages/compiler/src/utils/jsx-element.ts:4–32  ·  view source on GitHub ↗
(nodePath: NodePath<t.JSXElement>)

Source from the content-addressed store, hash-verified

2import { NodePath } from "../babel-interop";
3
4export function getJsxElementName(nodePath: NodePath<t.JSXElement>) {
5 const openingElement = nodePath.node.openingElement;
6
7 // elements with simple (string) name
8 if (t.isJSXIdentifier(openingElement.name)) {
9 return openingElement.name.name;
10 }
11
12 // elements with dots in name
13 if (t.isJSXMemberExpression(openingElement.name)) {
14 const memberExpr = openingElement.name;
15 const parts: string[] = [];
16
17 // Traverse the member expression to collect all parts
18 let current: t.JSXMemberExpression | t.JSXIdentifier = memberExpr;
19 while (t.isJSXMemberExpression(current)) {
20 parts.unshift(current.property.name);
21 current = current.object;
22 }
23
24 // Add the base identifier
25 if (t.isJSXIdentifier(current)) {
26 parts.unshift(current.name);
27 }
28
29 return parts.join(".");
30 }
31 return null;
32}
33
34export function getNestedJsxElements(nodePath: NodePath<t.JSXElement>) {
35 const nestedElements: t.JSXElement[] = [];

Callers 7

jsx-provider.tsFile · 0.90
jsx-html-lang.tsFile · 0.90
JSXElementFunction · 0.90
JSXElementFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected