feat: add native source maps support#1241
Conversation
ce3be99 to
c67c483
Compare
44b9e8e to
fbb6b35
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1241 +/- ##
==========================================
- Coverage 81.43% 80.39% -1.05%
==========================================
Files 97 105 +8
Lines 23877 27277 +3400
==========================================
+ Hits 19445 21929 +2484
- Misses 4432 5348 +916 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
74347e4 to
e161b54
Compare
e161b54 to
22bebf7
Compare
| r#"export function greet(name) {{ | ||
| console.log("Hello, " + name); | ||
| }} | ||
|
|
||
| greet("World"); |
There was a problem hiding this comment.
I think this code needs to throw an error to test it fully - otherwise we're not checking if the source map is actually getting applied, right?
There was a problem hiding this comment.
good catch! I update the test to throw an error.
| // External source maps with relative paths (./) are loaded lazily when needed | ||
| // We've verified that the module loads successfully |
There was a problem hiding this comment.
If an error is not thrown in a test, is the source map actually loaded? Maybe we need some more assertions here, like checking if the load_external_source_map was called?
There was a problem hiding this comment.
I added more assets here
| // Verify the error shows the synthetic path from the bundle | ||
| // Should show as absolute: /a.ts (not with excessive ../) | ||
| assert!( | ||
| err_str.contains("/a.ts") || err_str.contains("file:///a.ts"), | ||
| "Error should contain synthetic bundle path: {}", | ||
| err_str | ||
| ); |
There was a problem hiding this comment.
Why is it either /a.ts or file:///a.ts?
There was a problem hiding this comment.
good catch! Should be only file:///a.ts. Fixed!
| // TODO(bartlomieju): I feel like these two should be cleared when Isolate | ||
| // reaches "near heap limit" to free up some space. This needs to be confirmed though. | ||
| maps: HashMap<String, Option<SourceMap>>, | ||
| maps: HashMap<String, Option<Arc<SourceMap>>>, |
There was a problem hiding this comment.
Ouch, now I'm a bit confused - what's the difference between maps and native_source_maps? Since they look almost identical is there a reason to keep them separate?
There was a problem hiding this comment.
Oh! Actually, we don't need native_source_maps. I remove it to use maps directly.
bartlomieju
left a comment
There was a problem hiding this comment.
Looks, great, a few questions left before we merge it
5ebed11 to
67a4c04
Compare
67a4c04 to
d5e9176
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
WalkthroughThe pull request enhances source map support by introducing external source map loading capabilities. Changes include adding a new trait method for loading external source maps, extracting and processing source map URLs from V8 modules, refining path abbreviation logic for error messages, and managing Arc-wrapped source maps with URL tracking. Changes
Sequence Diagram(s)sequenceDiagram
participant Module as V8 Module Script
participant MapLoader as map.rs
participant ModuleLoader as ModuleLoader
participant SourceMapper as SourceMapper
participant DataDecoder as sourcemap
Module->>MapLoader: Load module with sourceMappingURL
alt Data URL
MapLoader->>DataDecoder: Decode data: URL
DataDecoder->>SourceMapper: Register decoded SourceMap (Arc)
else External URL
MapLoader->>MapLoader: Resolve URL relative to module
MapLoader->>ModuleLoader: load_external_source_map(url)
ModuleLoader->>SourceMapper: Register external URL
end
SourceMapper->>SourceMapper: Store with Arc<SourceMap>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Areas requiring extra attention:
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
core/error.rs(3 hunks)core/modules/loaders.rs(2 hunks)core/modules/map.rs(3 hunks)core/modules/tests.rs(1 hunks)core/source_map.rs(7 hunks)
| if source_mapping_url.starts_with(DATA_PREFIX) { | ||
| if let Ok(DecodedMap::Regular(sm)) = | ||
| sourcemap::decode_data_url(&source_mapping_url) | ||
| { | ||
| self | ||
| .source_mapper | ||
| .borrow_mut() | ||
| .add_source_map(module_name, sm); | ||
| } | ||
| } else { | ||
| // Resolve external source map URL relative to the module URL | ||
| let resolved_url = | ||
| if let Ok(module_url) = ModuleSpecifier::parse(name.as_str()) { | ||
| module_url | ||
| .join(&source_mapping_url) | ||
| .unwrap_or(module_url) | ||
| .to_string() | ||
| } else { | ||
| source_mapping_url | ||
| }; | ||
|
|
||
| self | ||
| .source_mapper | ||
| .borrow_mut() | ||
| .add_source_map_url(module_name, resolved_url); |
There was a problem hiding this comment.
Support all decoded data URL map variants
decode_data_url() can return DecodedMap::Index / DecodedMap::IndexOwned (multi-section maps) in addition to Regular*. By matching only DecodedMap::Regular we silently drop any inline source map that happens to be an index, which means no native mapping for many real-world bundler outputs (Rollup/esbuild frequently emit sectioned maps). Please accept every variant (e.g. call decoded.into_sourcemap() or handle the index cases explicitly) before stashing the map; otherwise we regress the new feature for a large class of inputs.
bartlomieju
left a comment
There was a problem hiding this comment.
LGTM, let's try it out in the CLI
Related:
denoland/deno#4499
denoland/deno#21988
Summary by CodeRabbit
New Features
Improvements