How nettybun/acorn-macros works
Main Components
a) Input Processing Layer
• Source JS/TS Files
• ESBuild Bundle
• Macro Import Detection
b) Core Processing Engine
• Acorn Parser
• AST Walker
• Macro Registry
• Macro Evaluation Pipeline
c) Macro Implementation Layer
• Individual Macro Packages
• Macro Configuration
• Output Handlers
Component Relationships
┌─ Build Process ──────────────────────────────────────────┐
• ┌─ Input ─────┐ ┌─ Processing ───┐ ┌─ Output ──┐ │
• Source Files│ │ Acorn Parser │ │ Processed │ │
• ESBuild │ -> │ AST Walker │ -> │ JS │ │
• Bundle │ │ Macro Engine │ │ CSS/etc. │ │
• ┘ └───────────────┘ └──────────┘ │
• ↑ │
• ┌─ Macro Registry ───────────────────────────────┐ │
• ┌─────────┐ ┌────────┐ ┌─────────┐ ┌───────┐ │ │
• style. │ │ms. │ │preval. │ │Other │ │ │
• acorn │ │acorn │ │acorn │ │Macros │ │ │
• ┘ └────────┘ └─────────┘ └───────┘ │ │
• ┘ │
• ┘
Key Elements to Highlight
• Input/Source files (Blue)
• Processing Engine (Green)
• Macro Implementations (Orange)
• Output Files (Purple)
b) Flow Indicators:
Important Details
• Single-pass nature of the AST walk
• Macro evaluation order for nested macros
• Source code replacement mechanism
• Hooks (Pre/Post) integration points
Implementation Details
A separate section showing:
• Macro interface definition
• Hook points (Pre/Post)
• Range calculation mechanism
• Code replacement strategy