0.0.15 • Published 2 years ago

@reaf-toolkit/parser v0.0.15

Weekly downloads
1
License
MIT
Repository
-
Last release
2 years ago

@reaf-toolkit/parser

reaf组件 typescript文件解析

Installation

Using npm:

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

Using yarn:

$ yarn add @reaf-toolkit/parser

Usage

index.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

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

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

export { ITest3, ITest5 }

type2.ts

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

export interface ITest4 {
  /** 名称fhjasjklfadskjl */
  name: string
}
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"
              }
            }
          }
        }
      ]
    }
  }
}
0.0.15

2 years ago

0.0.14

3 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago