MCPcopy Index your code
hub / github.com/reactjs/react-codemod / findReactComponentNameByParent

Function findReactComponentNameByParent

transforms/utils/ReactUtils.js:103–126  ·  view source on GitHub ↗
(path, parentClassName)

Source from the content-addressed store, hash-verified

101 // ---------------------------------------------------------------------------
102 // Finds alias for React.Component if used as named import.
103 const findReactComponentNameByParent = (path, parentClassName) => {
104 const reactImportDeclaration = path
105 .find(j.ImportDeclaration, {
106 type: 'ImportDeclaration',
107 source: {
108 type: 'Literal',
109 },
110 })
111 .filter(importDeclaration => hasReact(path));
112
113 const componentImportSpecifier = reactImportDeclaration
114 .find(j.ImportSpecifier, {
115 type: 'ImportSpecifier',
116 imported: {
117 type: 'Identifier',
118 name: parentClassName,
119 },
120 }).at(0);
121
122 const paths = componentImportSpecifier.paths();
123 return paths.length
124 ? paths[0].value.local.name
125 : undefined;
126 };
127
128
129 const findReactES6ClassDeclarationByParent = (path, parentClassName) => {

Callers 1

Calls 1

hasReactFunction · 0.85

Tested by

no test coverage detected