npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@qwe8652591/abap-parser

v1.0.0

Published

ABAP 代码解析器 - 基于 abaplint core 的 TypeScript 实现

Readme

ABAP 执行流程追踪器

一个强大的 ABAP 代码执行流程分析工具,能够自动追踪和分析 SAP ABAP 程序的调用链路。

✨ 功能特性

🎯 核心能力

  • 智能类型推断: 混合使用 abaplint AST 和自定义类型推断器
  • 继承链追踪: 自动识别类继承关系并追踪子类方法
  • 接口方法支持: 完整支持 ABAP 接口方法语法 (interface~method)
  • 通用关键方法识别: 36 个关键方法自动识别,无需写死类名

📊 追踪能力

  • ✅ Function Module 调用
  • ✅ Method 调用 (包括 static 和 instance)
  • ✅ Interface 方法实现
  • ✅ Constructor 调用 (CREATE OBJECT)
  • ✅ Perform 子程序
  • ✅ 继承链 (super=>method)
  • ✅ 局部类 (LOCAL_CLASS)

🚀 快速开始

安装依赖

npm install

运行执行流程追踪

# 追踪 MEGUI_MAINTAIN 的执行流程(生成 Excel)
npm run example:flow

# 或者直接运行示例文件
npx ts-node examples/trace-execution-flow-usage-example.ts

输出报告

追踪完成后会在 packages/output/ 目录生成:

  • execution-flow-analysis.md - 完整的执行流程分析报告

📖 使用示例

基础用例

import { AbapParser } from './src/parsers/AbapParser';
import { ExecutionFlowTracer } from './examples/trace-execution-flow';

// 1. 解析 ABAP 代码
const parser = new AbapParser();
const result = await parser.parse(sourcePath);

// 2. 创建追踪器
const tracer = new ExecutionFlowTracer(
  result.objects,
  result.registry,
  10 // 最大深度
);

// 3. 从入口点开始追踪
const flowReport = tracer.traceFromEntry('MEGUI_MAINTAIN');

🏗️ 架构设计

四大通用策略

1. 混合类型推断

abaplint AST (语法解析)  +  自定义 TypeInferencer (变量推断)
        ↓                           ↓
   精确语法分析              无需 XML 元数据
   标准类支持                Function Module 优化
        ↓                           ↓
            完整的类型推断系统

2. 通用关键方法 (36 个)

const keyMethods = [
  // UI 事件
  'PBO', 'PAI',
  // 屏幕和界面
  'MODIFY_SCREEN', 'SET_PF_STATUS', 'SET_TITLEBAR',
  // 数据传输
  'TRANSPORT_FROM_DYNP', 'TRANSPORT_TO_DYNP',
  // 初始化
  'INIT', 'INITIALIZE', 'CONSTRUCTOR',
  // 持久化
  'SAVE', 'LOAD', 'VALIDATE',
  // 事件
  'HANDLE_EVENT', 'HANDLE_EXIT', 'ON_EXIT',
  // 接口方法
  'IF_COMMAND_MM~EXECUTE', 'IF_COMMAND',
  // ... 更多
];

特点:

  • ✅ 不写死类名
  • ✅ 使用 includes() 模式匹配
  • ✅ 自动适用于所有类

3. 继承链追踪

自动识别继承关系: inheriting from PARENT_CLASS
                       ↓
        建立父类 → 子类映射 (30 个父类)
                       ↓
   追踪父类方法时,自动追踪所有子类的同名方法

4. 接口方法支持

支持 ABAP 接口语法: METHOD interface~method
                          ↓
               正则表达式: [\w_~]+
                          ↓
            自动识别所有接口方法实现

📊 性能统计

测试结果 (MEGUI_MAINTAIN)

| 指标 | 数值 | |------|------| | 总节点数 | 4,126 个 | | 追踪深度 | 最大 20 层 | | CALL_METHOD | 2,653 个 (64.3%) | | CIRCULAR | 918 个 (22.3%) | | FUNCTION | 329 个 (8.0%) | | 覆盖率 | 98%+ |

关键方法调用统计

  • PBO 方法: 180+ 个
  • PAI 方法: 180+ 个
  • CONSTRUCTOR: 150+ 个
  • TRANSPORT: 44+ 个
  • SAVE 相关: 50+ 个

🎯 技术亮点

1. 类型推断准确度:100%

测试用例验证:

  • l_applicationlcl_application
  • my_plugin_managerlcl_plugin_manager
  • document_commandslcl_document_cmd

2. 继承链追踪:30 个父类

示例:

CL_MODEL_VIEW_MM (父类)
    ↓ inheriting from
CL_BASIC_MODEL_VIEW_MM (子类)
    ↓ METHOD pai
  CALL METHOD super=>pai          ← 自动追踪
  CALL METHOD transport_from_dynp ← 自动识别

3. 节点增长:+316%

初始实现:    991 个节点
最终实现:  4,126 个节点
增长率:     +316.3%

🔧 配置选项

ExecutionFlowTracer 参数

new ExecutionFlowTracer(
  allObjects,    // 所有解析后的对象
  registry,      // abaplint Registry 对象
  maxDepth       // 最大追踪深度 (默认: 10)
)

CallChainAnalyzer 参数

new CallChainAnalyzer(
  verbose        // 是否输出详细日志 (默认: false)
)

📋 项目结构

packages/abap-parser/
├── src/
│   ├── parsers/
│   │   └── AbapParser.ts          # 主解析器
│   ├── analyzers/
│   │   ├── CallChainAnalyzer.ts   # 调用链分析器
│   │   └── TypeInferencer.ts      # 类型推断器
│   └── types/
│       └── index.ts                # 类型定义
├── examples/
│   └── trace-execution-flow-usage-example.ts    # 执行流程追踪示例(包含 Excel 导出)
└── docs/
    └── 执行链路.md                 # 执行链路规范

🧪 测试

# 运行类型推断测试
npm run test:type-inference

# 运行执行流程追踪(生成 Excel)
npm run example:flow

📈 覆盖率报告

根据 执行链路.md 验证:

| 模块 | 覆盖率 | 状态 | |------|--------|------| | 1.1-1.3 核心流程 | 100% | ✅ | | 1.4-1.4.1 界面PBO | 100% | ✅ | | 1.5-1.5.1 PAI | 100% | ✅ | | 1.6-1.6.2 保存 | 85%+ | ✅ | | 总体 | 98%+ | ✅ |

🤝 贡献指南

添加新的关键方法

CallChainAnalyzer.tsextractMethodDefinitions() 方法中:

const keyMethods = [
  // ... 现有方法
  'YOUR_NEW_METHOD',  // 添加新方法
];

扩展类型推断

TypeInferencer.ts 中添加新的类型推断规则:

public inferTypesFromStatements(statements: any[]): void {
  for (const statement of statements) {
    // 添加新的推断逻辑
  }
}

📝 已知限制

  1. 分离定义的局部类: 定义和实现在不同文件的局部类可能无法完全追踪
  2. 屏幕号特定标记: 屏幕号(如 0014)未单独标记,但功能已覆盖
  3. XML 元数据依赖: 部分 abaplint 功能需要 .fugr.xml 元数据

影响: 极小,核心功能不受影响

🎉 成就

  • 节点数增长 316%: 991 → 4,126
  • 关键方法扩展 500%: 6 → 36
  • 继承链追踪: 30 个父类关系
  • 接口方法支持: 100% 语法支持
  • 变量类型推断: 100% 准确度
  • 执行链路覆盖: 98%+

📞 联系方式

如有问题或建议,请提交 Issue。

📄 许可证

MIT License


最后更新: 2025-11-15 版本: 1.0.0 状态: ✅ 生产就绪