recast-function

1.0.6 • Public • Published

recast-function

不同函数间的转换,目前支持,将普通函数转换成继承React.Component的class构造函数。

how to use

step 1

  • npm install -g cnpm --registry=https://registry.npm.taobao.org
  • cnpm install recast-function --save
  • 或者使用 yarn add recast-function

step 2

import recastFunction from 'recast-function';

  • use

接收参数

recastFunction.normalToReactClass(code, isDownLoad); code, 源函数 isDownLoad 是否下载 函数解释: normalToReactClass(将普通函数转换成继承React.Component的class构造函数) ...

示例

recastFunction.normalToReactClass( ` function Page(props) { const { a, b } = props; function z(){ console.log('a', a); return 0; } return ( <div onClick={z}>{z()}<div></div></div> ); } ` )

将会返回string格式的结果

class Page extends React.Component { constructor(props) { super(props); this.state = {}; } render() { const { a, b } = this.props; const z = () => { console.log('a', a); return 0; }; return ( <div onClick={z}>{z()}<div></div></div> ); } } 注意:源函数类型如果不匹配,则可能得不到想要的结果。 另外加上isDownLoad为true的传参可以直接下载文件。 解决重复劳动力是一件很有意义的事情, 有什么好的想法,欢迎一起成长交流 WeChat:mrliaojun

github

Jared

Package Sidebar

Install

npm i recast-function

Weekly Downloads

2

Version

1.0.6

License

ISC

Unpacked Size

10.6 kB

Total Files

5

Last publish

Collaborators

  • aisriver