https://github.com/midwayjs/ts-analysis
TypeScript Code Analysis
https://github.com/midwayjs/ts-analysis
Last synced: over 1 year ago
JSON representation
TypeScript Code Analysis
- Host: GitHub
- URL: https://github.com/midwayjs/ts-analysis
- Owner: midwayjs
- License: mit
- Created: 2020-07-02T02:25:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-28T16:18:25.000Z (over 4 years ago)
- Last Synced: 2025-04-06T07:16:31.543Z (over 1 year ago)
- Language: TypeScript
- Size: 28.3 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-analysis
Analysis TypeScript Code to Json
## Usage
```ts
// Use Class
import { TsAnalysis } from '@midwayjs/ts-analysis';
async (codePath) => {
const analysisInstance = new TsAnalysis(codePath); // 初始化实例
await analysisInstance.start(); // 分析器启动
const result = await analysisInstance.getResult(); // 获取分析结果
return result;
}
// Use Instance
import { tsAnalysis } from '@midwayjs/ts-analysis';
async (codePath) => {
const result = await tsAnalysis(codePath) // 获取分析结果
return result;
}
```
## Result Demo
### Decorator
```ts
// decorator.ts
@Provider()
class Test {
constructor(name: string, age: number) {}
@Inject('context')
ctx;
@Func('index.handler', { method: 'GET', path: '/api/test' })
async handler() { }
}
// result
{
decorators: {
Provider: [
{
sourceFile: '/Users/xxx/decorator.ts', // 代码所在位置
position: { // 装饰器所在位置
start: { // 装饰器开始位置
ln: 0,
col: 0
},
end: { // 装饰器结束位置
ln: 0,
col: 12
}
},
params: [
// 参数
],
target: { // 装饰的目标
type: 'class', // 目标类型
name: 'Test', // 目标名称
position: { // 目标代码位置
... // 格式参照上述位置结构
},
params: [ // 目标参数列表,class即为constructor参数列表
{
name: 'name',
type: 'string'
},
{
name: 'age',
type: 'number'
}
]
},
childDecorators: {
Inject: [
... // 结构类似
],
Func: [
... // 结构类似
]
}
}
],
Inject: [
... // 结构类似
],
Func: [
... // 结构类似
]
}
}
```