Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
target
Cargo.lock
.idea
11 changes: 7 additions & 4 deletions src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ impl SourceMapHermes {

// Find the closest mapping, just like here:
// https://github.com/facebook/metro/blob/63b523eb20e7bdf62018aeaf195bb5a3a1a67f36/packages/metro-symbolicate/src/SourceMetadataMapConsumer.js#L204-L231
let (_mapping_idx, mapping) =
greatest_lower_bound(&function_map.mappings, &token.get_src(), |o| {
(o.line, o.column)
})?;
// Mappings use 1-based index for lines, and 0-based index for cols, as seen here:
// https://github.com/facebook/metro/blob/f2d80cebe66d3c64742f67259f41da26e83a0d8d/packages/metro/src/Server/symbolicate.js#L58-L60
let (_mapping_idx, mapping) = greatest_lower_bound(
&function_map.mappings,
&(token.get_src_line() + 1, token.get_src_col()),
|o| (o.line, o.column),
)?;
function_map
.names
.get(mapping.name_index as usize)
Expand Down
4 changes: 2 additions & 2 deletions src/ram_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl<'a> SplitRamBundleModuleIter<'a> {
}
}

impl<'a> Iterator for SplitRamBundleModuleIter<'a> {
impl Iterator for SplitRamBundleModuleIter<'_> {
type Item = Result<(String, SourceView, SourceMap)>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -458,7 +458,7 @@ pub fn is_ram_bundle_slice(slice: &[u8]) -> bool {
slice
.pread_with::<RamBundleHeader>(0, scroll::LE)
.ok()
.map_or(false, |x| x.is_valid_magic())
.is_some_and(|x| x.is_valid_magic())
}

/// Returns "true" if the given path points to the startup file of a file RAM bundle
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ fn test_react_native_hermes() {
("input.js", 2, 0, None)
);
assert_eq!(sm.get_original_function_name(11857), Some("<global>"));

assert_eq!(
sm.lookup_token(0, 11947).unwrap().to_tuple(),
("module.js", 1, 4, None)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically points to the throw token here (which is at line 2:5)

throw new Error("lets throw!");

);
assert_eq!(sm.get_original_function_name(11947), Some("foo"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this was returning <global> instead of foo as it thought it was outside the function scope.

}

#[test]
Expand Down
Loading