You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As described by @eventualbuddha in Rich-Harris#67 and @mariusGundersen in mozilla/source-map#216, merging 2+ source maps should never result in lost mappings. The current behavior of sorcery and Mozilla's source-map is to trace the line mappings of the root source map and toss out the rest of the tree, which results in a poor debugging experience. Below is my attempt to solve this issue.
Check out the tests here, and add a test (or file an issue) if you come across an edge case.
Most of the fix is contained in the blend function. It's well-documented, but questions are welcome. This function has one argument; a Node object that represents the "root" source map in a tree of source maps. The sources array of the given node is used to trace the root mappings array to its original source(s). Additionally, segments from any other nodes in the tree are interweaved into the root mappings array if they fit.
Since blend only mutates the given node, we need to start from the leaf nodes and work our way up to the root node so all source maps in the tree are blended together. This is done with the trace function.
I hope this solution works well for anyone who needs it. Please comment if you have any questions or find any bugs. Maybe this solution will even be adopted by Mozilla and @Rich-Harris. :)
Test plan
These are the tests I have so far. Passing tests have a checkmark. ✔︎
{indent,dedent} lines
shift columns {left,right} from middle of line
break line in two {while,without} removing characters
insert line break at {start,end} of file
remove first line
remove {middle,last} line
remove all line breaks
move first line to {middle,bottom}
move last line to middle
swap two lines
Test ideas are welcome. :)
The text was updated successfully, but these errors were encountered:
@whaaaley I'm taking the "fix it if I need it" approach due to time constraints. If you find any bugs, a repro would be handy. In its current state, it probably works in most situations. I'll be testing it on real applications in the near future.
As described by @eventualbuddha in Rich-Harris#67 and @mariusGundersen in mozilla/source-map#216, merging 2+ source maps should never result in lost mappings. The current behavior of
sorcery
and Mozilla'ssource-map
is to trace the line mappings of the root source map and toss out the rest of the tree, which results in a poor debugging experience. Below is my attempt to solve this issue.Check out the tests here, and add a test (or file an issue) if you come across an edge case.
Most of the fix is contained in the
blend
function. It's well-documented, but questions are welcome. This function has one argument; aNode
object that represents the "root" source map in a tree of source maps. Thesources
array of the given node is used to trace the rootmappings
array to its original source(s). Additionally, segments from any other nodes in the tree are interweaved into the rootmappings
array if they fit.Since
blend
only mutates the given node, we need to start from the leaf nodes and work our way up to the root node so all source maps in the tree are blended together. This is done with thetrace
function.I hope this solution works well for anyone who needs it. Please comment if you have any questions or find any bugs. Maybe this solution will even be adopted by Mozilla and @Rich-Harris. :)
Test plan
These are the tests I have so far. Passing tests have a checkmark. ✔︎
Test ideas are welcome. :)
The text was updated successfully, but these errors were encountered: