Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ impl SourceMapHermes {

// Find the closest mapping, just like here:
// https://github.com/facebook/metro/blob/63b523eb20e7bdf62018aeaf195bb5a3a1a67f36/packages/metro-symbolicate/src/SourceMetadataMapConsumer.js#L204-L231
// 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(), |o| {
greatest_lower_bound(&function_map.mappings, &(token.get_src_line() + 1, token.get_src_col()), |o| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could either do this, or change the mapping function to do (o.line - 1, o.column), let me know what do you prefer

Copy link
Contributor

Choose a reason for hiding this comment

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

I think doing it this way is fine.

(o.line, o.column)
})?;
function_map
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