resolveLocation has been left alone for quite some time because its already so delicate.
though it turns out @stramel discovered many of our errors are reported with the wrong position information and tests didn't catch this as they either had no end column, or we just didn't check that the asserted column actually was the right one! 🤦♂️
nobody understood this function and i struggled to remember too, so i deleted it.
i've rewritten it from scratch based on offsets, with getLocFromIndex being our saviour here 🥳 this means we don't need to calculate line changes, account for multi-line expressions, quasis, etc. that was where most of the complexity lived before.
here's how we calculate it now:
Loop through the quasis
Every time we see an expression, increment a correction number by how long the placeholder is for that expression
Increment the HTML start offset by the correction number
Increment the HTML end offset by the correction number
Convert the indices to source locations
If we ever get into some funky situation where a range or something is null, we resolve to the whole quasi's location as a fallback
cc @stramel
FYI i have commented the function a fair amount to help explain it
resolveLocation
has been left alone for quite some time because its already so delicate.though it turns out @stramel discovered many of our errors are reported with the wrong position information and tests didn't catch this as they either had no end column, or we just didn't check that the asserted column actually was the right one! 🤦♂️
nobody understood this function and i struggled to remember too, so i deleted it.
i've rewritten it from scratch based on offsets, with
getLocFromIndex
being our saviour here 🥳 this means we don't need to calculate line changes, account for multi-line expressions, quasis, etc. that was where most of the complexity lived before.here's how we calculate it now:
cc @stramel
FYI i have commented the function a fair amount to help explain it