Open aleclarson opened 6 years ago
How's the progress on this? Is this still something you're working on?
@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.
Alrighty. I'll test it out for my css-in-js idea soon.
@whaaaley You can use @cush/sorcery to avoid cloning it yourself. 👍
As described by @eventualbuddha in https://github.com/Rich-Harris/sorcery/issues/67 and @mariusGundersen in https://github.com/mozilla/source-map/issues/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. :)