gengyang 64c9daa1f4 refactor: 💡 refactor with react-docgen
BREAKING CHANGE: 🧨 use react-docgen to replace parser
2020-03-16 16:32:41 +08:00

43 lines
1.1 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { builders, namedTypes as t, NodePath, visit } from 'ast-types';
/**
* If the path is a call expression, it recursively resolves to the
* rightmost argument, stopping if it finds a React.createClass call expression
*
* Else the path itself is returned.
*/
export default function resolveTranspiledClass(path: any) {
let classPath = path;
visit(path, {
visitFunctionDeclaration(arg) {
classPath = new NodePath(
builders.functionDeclaration(
arg.node.id,
[],
builders.blockStatement([
builders.returnStatement(
builders.jsxElement(
builders.jsxOpeningElement(
builders.jsxIdentifier('div'),
[],
true,
),
),
),
]),
),
path.parent,
);
return false;
},
});
return classPath;
}