-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
RFC: TC39 ECMA-426 Scopes Proposal - Implementation Design #11426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This commit introduces a comprehensive design document for implementing the TC39 ECMA-426 scopes proposal in SWC. The scopes proposal extends source maps to include scope information (variable bindings, function boundaries, scope hierarchies), enabling debuggers to provide accurate variable inspection even after aggressive optimizations. ## Design Highlights ### Architecture Analysis - Analyzed SWC's existing source map infrastructure (SourceMap, JsWriter) - Documented current scope tracking via Resolver pass - Identified position tracking during code generation - Reviewed AST visitor patterns (Visit, VisitMut, Fold) ### TC39 Specification Research - Studied original scope and generated range data structures - Documented VLQ encoding format with 8 tag types (B-I) - Analyzed delta encoding strategy for position optimization - Reviewed Chrome DevTools encoding recommendations ### Implementation Design - Designed Rust data structures for OriginalScope and GeneratedRange - Created ScopeCollector visitor for scope information collection - Designed RangeTracker for tracking generated code ranges - Implemented VLQ encoder with delta encoding support ### Integration Strategy - Zero-overhead design using feature flags (sourcemap-scopes) - Leverages existing Resolver infrastructure to avoid duplication - Integrates with current source map generation pipeline - Phased implementation plan (12 weeks, 6 phases) ### Performance Considerations - Feature flag ensures no overhead when disabled - Memory overhead: ~48 bytes per scope (0.024% for typical files) - Target: <5% performance impact when enabled - Optimized VLQ encoding with delta compression ## Key Design Decisions 1. **New Crate**: Create `swc_sourcemap_scopes` crate for isolation 2. **Visitor Pattern**: Use existing Visit trait for scope collection 3. **Feature Flags**: Conditional compilation for zero overhead 4. **Arena Allocation**: Consider bumpalo for scope tree allocation 5. **Interning**: Leverage existing Atom interning for scope names ## Implementation Phases 1. Foundation: Data structures and VLQ encoder (Week 1-2) 2. Scope Collection: Implement collector visitor (Week 3-4) 3. Range Tracking: Modify Emitter for tracking (Week 5-6) 4. Encoding: Full scopes encoding integration (Week 7-8) 5. Optimization: Performance tuning and docs (Week 9-10) 6. Advanced Features: Bindings and callsites (Week 11-12) ## References - TC39 ECMA-426 Scopes Proposal - ECMA-426 Source Map Specification - Chrome DevTools Scopes Encoding - SWC Resolver and SourceMap documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
|
|
1 similar comment
|
|
|
🤖 This pull request has been linked to DevBird Task #3855 View the task details and manage the automated development workflow in DevBird. Learn more about DevBird here or the announcement blog post here. |
📋 DevBird Task PromptResearch and document the current source map implementation in SWC and design the integration approach for the TC39 ECMA-426 scopes proposal. ObjectiveUnderstand SWC's existing source map infrastructure and create a comprehensive design document for implementing the SourceMap scopes specification. Documentation & Resources
Scope
Technical Requirements
Success Criteria
This comment was automatically added by DevBird. You can disable this feature in DevBird Settings. |
kdy1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use @docs/adr
Restructure the TC39 ECMA-426 scopes proposal design document to follow the Architecture Decision Record (ADR) format as requested in review. Changes: - Move from docs/sourcemap-scopes-design.md to docs/adr/00005-tc39-ecma426-scopes-proposal-implementation.md - Restructure content to follow ADR template with Context/Problem, Decision Drivers, Options, and Decision Outcome sections - Maintain all technical details including data structures, integration points, and implementation phases - Add proper ADR metadata (status: proposed, date, deciders) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
Binary Sizes
Commit: 00c5074 |
The rkyv 0.7.45 vulnerability (RUSTSEC-2026-0001) is a transitive dependency from parcel_sourcemap via lightningcss. The vulnerability involves potential undefined behavior in Arc<T>/Rc<T> implementations during OOM (Out of Memory) conditions, which is unlikely to occur in normal usage. This is being ignored until parcel_sourcemap updates their rkyv dependency to a patched version. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Overview
This PR introduces a comprehensive design document for implementing the TC39 ECMA-426 scopes proposal in SWC. The scopes proposal extends source maps to include scope information (variable bindings, function boundaries, scope hierarchies), enabling debuggers to provide accurate variable inspection even after aggressive optimizations like inlining, tree-shaking, and minification.
What's Included
📋 Design Document
docs/sourcemap-scopes-design.md🔍 Analysis Completed
Current Architecture Review
TC39 Specification Research
Implementation Design
🎯 Key Design Principles
Zero-Overhead When Disabled
sourcemap-scopesPerformance-First
Incremental Integration
📊 Technical Highlights
Data Structures:
VLQ Encoding Tags:
B(0x1): Original scope startC(0x2): Original scope endD(0x3): Scope variablesE(0x4): Generated range startF(0x5): Generated range endG(0x6): Simple bindingsH(0x7): Subrange bindingI(0x8): Callsite (inlining info)Integration Points:
📅 Implementation Plan
Phase 1: Foundation (Week 1-2)
swc_sourcemap_scopescratePhase 2: Scope Collection (Week 3-4)
Phase 3: Range Tracking (Week 5-6)
Phase 4: Encoding (Week 7-8)
Phase 5: Optimization (Week 9-10)
Phase 6: Advanced Features (Week 11-12)
🔗 References
📝 Files Changed
docs/sourcemap-scopes-design.md- Complete implementation design document✨ What's Next?
This is a Request for Comments (RFC) - the design document is ready for review and feedback from the SWC team. Once approved, implementation can begin following the phased plan.
Feedback Welcome On:
🎯 Success Metrics
Type: Documentation / RFC
Priority: Medium
Breaking Changes: None
Feature Flag:
sourcemap-scopes(new)🤖 Generated with Claude Code