feat(sourcemap): support safe scopes round-trip metadata#11581
Conversation
🦋 Changeset detectedLatest commit: 46afe32 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Binary Sizes
Commit: 34650d2 |
PR Review: feat(sourcemap): support safe scopes round-trip metadataSummaryThis PR adds support for the ECMA-426 Code QualityThe implementation is clean and consistent with the existing patterns in the codebase:
Correctness — scopes invalidation coverageThe PR correctly invalidates
One observation: let mut new_map = new_map.into_sourcemap();
// Note: scopes are implicitly None from the builder — this is intentional
// since mapping adjustment invalidates scope metadata.Test CoverageTest coverage is good:
Minor suggestion: a test for PerformanceNo concerns. The scopes field is stored as a single SecurityNo concerns. The scopes string is opaque pass-through data — it is not interpreted, executed, or used in any path-construction logic. NitIn VerdictThis is a well-structured, minimal change that correctly handles the ECMA-426 scopes field with proper invalidation semantics. The approach of treating scopes as opaque metadata is the right one for now. LGTM with the minor suggestions above. |
There was a problem hiding this comment.
Pull request overview
Adds support for the ECMA-426 top-level scopes sourcemap metadata so it can be decoded/encoded (eager + lazy) and preserved on read/write round-trips, while being invalidated on mutating operations where it may become stale.
Changes:
- Add
scopesstorage + getter/setter to the eagerSourceMaptype, and invalidate it in mutating APIs (remove_names,rewrite_with_mapping,adjust_mappings). - Extend eager and lazy JSON (de)serialization paths to include the optional
scopesfield. - Add tests covering eager/lazy
scopesround-trip preservation and invalidation behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/swc_sourcemap/src/types.rs | Stores scopes on eager SourceMap, exposes get/set, and clears it on mutating operations; adds unit tests for invalidation. |
| crates/swc_sourcemap/src/jsontypes.rs | Extends eager JSON RawSourceMap schema with optional scopes. |
| crates/swc_sourcemap/src/decoder.rs | Populates eager SourceMap.scopes during decode. |
| crates/swc_sourcemap/src/encoder.rs | Serializes eager SourceMap.scopes when present. |
| crates/swc_sourcemap/src/lazy/mod.rs | Adds scopes to lazy RawSourceMap/SourceMap and preserves it through lazy decode/encode; clears it on lazy adjust_mappings; adds tests. |
| crates/swc_sourcemap/tests/test_decoder.rs | Integration test verifying eager decode reads scopes. |
| crates/swc_sourcemap/tests/test_encoder.rs | Integration test verifying eager encode/decode round-trips scopes. |
| .changeset/eleven-papayas-attend.md | Publishes a minor changeset for swc_sourcemap / swc_core. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
scopesfield support to eager/lazy sourcemap decode/encodescopesfor plain read/write round-tripscopesin mutating paths where metadata can become stale (remove_names,rewrite_with_mapping,adjust_mappings, lazyadjust_mappings)Verification