跳转至

G2-2 export 统计报告 —— 函数 / class / 类型

目的:完整统计 src/ 下所有 export 实体 方法grep -rE "^export (async )?function|^export const|^export class|^export type|^export interface|^export default" --include="*.ts" --include="*.tsx" 执行日期:2026-06-06


1. 总览

实体 数量 占比 备注
export function 5,229 65% 含 async function
export const 1,274 16% 含对象、数组
export class 95 1.2% 真正的类
export type 1,331 17% TypeScript type alias
export interface 39 0.5% 极少用 interface
export default 131 1.6% 默认导出(React 组件)
合计 8,099 100% 平均每文件 4.3 个 export

2. function vs class vs type 比例

function : class : type : interface : const : default
   5229   :  95   : 1331 :   39       : 1274 :  131
   65%   :  1%   : 17%  :  0.5%      : 16%  :  2%

关键洞察: - function 65% —— 主导(这是 Node 后端) - class 仅 1% —— 几乎不用面向对象 - interface 仅 0.5% —— 几乎全用 type 而不是 interface(现代化 TS 风格) - default 仅 2% —— 用 named export 为主(可重构友好)


3. Top 10 文件(按 export function 数)

排名 文件 export function 文件行数 密度
1 src/bootstrap/state.ts 210 1758 ⅛ 行
2 src/utils/messages.ts 95 5512 1/58 行
3 src/utils/sessionStorage.ts 88 5105 1/58 行
4 src/utils/auth.ts 50 2002 1/40 行
5 src/utils/teammateMailbox.ts 34 ~600 1/18 行
6 src/utils/permissions/permissionSetup.ts 31 ~800 1/26 行
7 src/utils/attachments.ts 29 3997 1/138 行
8 src/utils/hooks.ts 28 5022 1/179 行
9 src/utils/model/model.ts 27 ~1500 1/56 行
10 src/utils/commitAttribution.ts 25 ~600 1/24 行

关键洞察: - bootstrap/state.ts 1758 行 210 个 export —— 8 行/函数 异常高密度 - 推测是很多 getXxx() / setXxx() getter/setter 对(每个字段都有一对) - 与其他文件比(58 行/函数)说明大量小工具函数


4. 99 个文件 export 数量分布

export 数 文件数 占比
0 ~50 3% 占位 / 类型 only
1-5 ~1100 58% 典型文件
6-10 ~400 21% 工具文件
11-20 ~250 13% 大型工具
21-50 ~90 5% 子模块入口
51-100 ~10 0.5% 核心文件
100+ 1 0.05% bootstrap/state.ts

5. async vs sync function

类别 数量
export async function ~1,800(35%)
export function ~3,400(65%)
总 function 5,229

35% 是 async —— 网络 IO / 文件 IO / DB / 消息队列占大头。


6. class 分析

仅 95 个 class,按"用途"分类:

类别 估算数
Error class ~30 BridgeFatalError, ToolError, MCPError
状态/Store ~10 AppState, SessionState
工具类 ~15 LRUCache, RingBuffer
客户端/SDK ~10 MCPClient, OAuthClient
React 组件 ~10 Modal, Dialog
其他 ~20 各种领域类

class 极少用——这是 functional 风格 的代码库。


7. type vs interface

类别 数量 占比
type X = ... 1,331 97%
interface X { ... } 39 3%
总类型定义 1,370 100%

97% 用 type——这是现代 TypeScript 风格

为什么 type 占绝对优势: - 联合类型(type X = A | B)必须用 type - 交叉类型(type X = A & B)必须用 type - 元组类型(type X = [A, B])必须用 type - 工具类型(Pick<>Omit<>Partial<>)用 type 更自然 - 映射类型(type X = { [K in keyof Y]: ... })必须用 type

39 个 interface 几乎都是: - 公共 SDK 接口(MCPError extends Error) - React props 接口(少数) - 历史遗留


8. default export 分布

131 个 default export 主要是 React 组件: - ~100 个 React 组件(export default function MyComponent()) - ~30 个命令的入口 - 1 个工具入口(MCPClient


9. 命名规范

模式 数量
camelCase 函数 getUser, queryModel ~5,000
PascalCase AppState, MCPClient 95
PascalCase 类型 User, Message, Tool ~1,300
SCREAMING_SNAKE 常量 MAX_RETRIES ~200
camelCase 变量 pendingBuffer ~1,000+

TypeScript 标准:camelCase 函数/变量,PascalCase 类/类型。


10. 关键洞察

  1. function 主导(65%)——functional 风格 + Node 后端
  2. class 极少(1%)——避免 OOP 复杂度
  3. type 主导 type 定义(97%)——现代 TS 风格
  4. async 35%——IO 密集型
  5. default 1.6%——named export 为主
  6. bootstrap/state.ts 异常——210 export / 1758 行(getter/setter 工厂)
  7. 总 export 8099 个——仓库接口丰富

11. 对比

指标 Claude Code 同类
总 export 8,099 1,000-3,000
function/文件 2.7 1-3
class 占比 1% 5-15%
type vs interface 97/3 70/30
async 占比 35% 20-30%

Claude Code 是 function 主导 + modern TS 风格。


最后更新:2026-06-06 执行人:devxiaofan