Skip to content
debug-coffee-ahk logo

coffee-ahk 架构与调试指南

debug-coffee-ahk

查询 coffee-ahk 编译架构、bug 定位方法、调试技巧,use when debugging/fixing bugs or need to understand compilation flow

SKILL.md

Full skill instructions

coffee-ahk 架构与调试指南

何时使用

  • 修复 coffee-ahk 编译器 bug
  • 理解编译流程、定位渲染错误、token 缺失
  • 需要查询关键文件职责或 Processor 执行顺序

何时更新本 skill:

  • 添加/删除 Formatter/​Processor/​Renderer 文件或修改执行顺序
  • 关键文件职责变更(如 Content.reload/​pick-item.ts 逻辑修改)
  • 发现新的常见陷阱或 bug 定位模式
  • 调试命令或工具链变更

效率优先:Read/​Grep/​Glob > Task · 优先使用本 skill 提供的路径信息,避免重复探索

编译流程(3 阶段)

entry/​index.ts:18-67:

  1. Formatters (formatters/​index.ts) - CoffeeScript tokens → Item[]
  2. Processors (processors/​index.ts) - AST 结构重写(顺序敏感)
  3. Renderer (renderer/​index.ts) - Item[] → AHK 代码

Processor 执行顺序

processors/​index.ts:19-37: newLine → validate → for/​array/​object/​logicalOr/​ifExpression/​chainedCompare → typeof/​instanceof/​variable → builtInLoader/​class/​function

function 内部顺序 (function/​index.ts:13-34): mark → class → implicit-return → anonymous → count → parameter → do → ctx-transform

关键文件职责

路径职责关键逻辑
models/​Content.ts:52reload() 过滤 voidfilter(it => !it.is('void'))
processors/​function/​anonymous/​pick-item.ts:27提取嵌套函数标记原位置为 void
processors/​function/​class/​prepend-this.ts:20类方法添加 ℓthisconstructor 特殊处理
processors/​function/​ctx-transform/​params.ts:11-15收集参数+类方法标记classMethods: Set<string>
processors/​function/​ctx-transform/​bind.ts:12-15Bind() 添加 this 参数检测 classMethods 传递 this
formatters/​property.ts:42this.prop 处理检查 lastType 插入 .
renderer/​index.ts:102mapMethod 映射type → 渲染函数

Bug 定位方法论

渲染错误(AHK 输出不符预期)

定位:

  1. 查看 AST:{verbose:true, ast:true} 确认 Processor 后 Item[]
  2. 检查 renderer/​index.ts mapMethod 是否有对应 type
  3. 检查 renderer/​basic.ts, edge.ts, control-flow.ts

Token 缺失(AST 中缺 token)

定位:

  1. 查看 CoffeeScript tokens:{coffeeAst:true}
  2. 检查 formatters/​index.ts 是否有对应 formatter
  3. 常见:THIS/SUPER/新语法未处理

作用域/闭包错误

定位:检查 processors/​function/​ctx-transform/ 的 collectParams/​transformVars/​addBind,验证 λ 对象传递链

Class method arrow functions 特殊处理:

  • collectParams() 检测 ℓthis 参数,记录到 classMethods Set
  • addBind() 为 class method 内部的 .Bind(λ) 添加 this 参数 → .Bind(λ, this)
  • 确保嵌套箭头函数能访问正确的 this(通过 ℓthis 传递)

调试技巧

# 查看完整编译流程
node -e "import('./​dist/​index.js').then(m=>m.default('file.coffee', {verbose:true, ast:true}))"

# 仅查看 CoffeeScript tokens
node -e "import('./​dist/​index.js').then(m=>m.default('file.coffee', {coffeeAst:true}))"

# 编译单文件(仅非测试文件)
node dist/​index.js file.coffee

测试文件规则:

  • ⚠️ 禁止手动编译或修改 script/​test/​*.ahk
  • 必须使用 pnpm test overwrite 自动生成
  • 新增测试:创建 .coffee → 运行 pnpm test overwrite -- <name>

常见陷阱

问题原因解决
Formatter 未消费 token忘记 return true添加 return
this 被过滤formatters 缺少处理添加 formatter
void 未过滤Content.reload() 依赖调用 reload()
嵌套函数 scope 错误pick-item.ts scope 调整验证 scope.shift()
Class method arrow 缺少 thisaddBind() 未检测 classMethods更新 params.ts + bind.ts

工作流程

  1. 确认问题类型:渲染错误/​token缺失/作用域错误(参考上方方法论)
  2. 使用调试命令:根据问题类型选择对应的 verbose/​ast/​coffeeAst 输出
  3. 定位具体文件:根据关键文件职责表直接定位,避免全目录探索
  4. 验证修复:运行 pnpm test 或 pnpm test overwrite -- <name>
  5. 返回信息:✓ Bug 已定位于 {文件}:{行号} 或 ✓ 修复完成并通过测试

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View