npm package: @reaf-toolkit/parser
Description: reaf component parser
Author: sunshine
Latest version: 0.0.15

# @reaf-toolkit/parser

> reaf组件 typescript文件解析

# Installation

## Using npm:

```zsh
$ npm i -g npm
$ npm i --save @reaf-toolkit/parser
```

## Using yarn:

```zsh
$ yarn add @reaf-toolkit/parser
```

## Usage

index.tsx
```tsx
import React from 'react'
import { ITest5 } from './type'

interface IX {
  /** test */
  name1: (number | string)[]
}

interface IProps extends IX, ITest5 {
  /**
   * 年龄
   * @test 28
   */
  age?: EAge
}

export const enum EAge {
  /**
   * 第一个
   * @test1 2
   */
  'one' = 28,
  /** 第二个 */
  'two' = 29
}

const Demo: React.FC<IProps> = () => {
  const a = <div>this is a demo</div>
  return a
}

Demo.defaultProps = {
  age: 28
}

export default Demo
```
type.ts

```ts
import { ITest3, ITest4 as ITest5 } from './type2'
export interface ITest1 {
  /** 名称 */
  name: string
}

export interface ITest2 {
  /** 名称 */
  name: string
}

export { ITest3, ITest5 }
```

type2.ts

```ts
export interface ITest3 {
  /** 名称 */
  name: string
}

export interface ITest4 {
  /** 名称fhjasjklfadskjl */
  name: string
}
```

```js
import parserFile from '@reaf-toolkit/parser'
// xxx为本地文件目录
parserFile('xxx/index.tsx')
// we will get
{
  "__src": "xxx/index.tsx",
  "dependencies": {
    "React": {
      "alias": "default",
      "ignore": true,
      "path": "xxx/node_modules/react/index.js"
    },
    "ITest5": {
      "alias": "ITest5",
      "ignore": false,
      "path": "xxx/type.ts"
    }
  },
  "enums": {
    "EAge": {
      "one": {
        "jsDoc": {
          "comment": "第一个",
          "tags": {
            "test1": "2"
          }
        },
        "name": "one",
        "value": "28"
      },
      "two": {
        "jsDoc": {
          "comment": "第二个"
        },
        "name": "two",
        "value": "29"
      }
    }
  },
  "exports": {
    "EAge": {
      "one": {
        "jsDoc": {
          "comment": "第一个",
          "tags": {
            "test1": "2"
          }
        },
        "name": "one",
        "value": "28"
      },
      "two": {
        "jsDoc": {
          "comment": "第二个"
        },
        "name": "two",
        "value": "29"
      }
    },
    "default": {
      "type": "Identifier",
      "alias": "Demo"
    }
  },
  "defaultProps": {
    "Demo": {
      "defaultValue": {
        "age": "28"
      },
      "propsName": "IProps"
    }
  },
  "interfaces": {
    "IX": {
      "name1": {
        "required": true,
        "flowType": {
          "type": "array",
          "elements": {
            "type": "union",
            "elements": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ]
          }
        },
        "description": {
          "comment": "test"
        }
      }
    },
    "IProps": {
      "age": {
        "required": false,
        "flowType": {
          "type": "typeReference~enum",
          "name": "EAge",
          "element": {
            "one": {
              "jsDoc": {
                "comment": "第一个",
                "tags": {
                  "test1": "2"
                }
              },
              "name": "one",
              "value": "28"
            },
            "two": {
              "jsDoc": {
                "comment": "第二个"
              },
              "name": "two",
              "value": "29"
            }
          }
        },
        "description": {
          "comment": "年龄",
          "tags": {
            "test": "28"
          }
        }
      },
      "extends": [
        {
          "extendsName": "IX",
          "elements": {
            "name1": {
              "required": true,
              "flowType": {
                "type": "array",
                "elements": {
                  "type": "union",
                  "elements": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "string"
                    }
                  ]
                }
              },
              "description": {
                "comment": "test"
              }
            }
          }
        },
        {
          "extendsName": "ITest5",
          "elements": {
            "name": {
              "required": true,
              "flowType": {
                "type": "string"
              },
              "description": {
                "comment": "名称fhjasjklfadskjl"
              }
            }
          }
        }
      ]
    }
  }
}
```