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
We already know the start and end position of each node in the code. So we could collect the ranges [start, end][] of nodes to remove, sort by start position in reverse order (merging overlapping ranges), then delete each range from the code.
The text was updated successfully, but these errors were encountered:
Previously, a regex string replacement was used, and regex is an inadequate
tool for transforming entire JavaScript code files. Instead, this commit
changes that to a proper algorithm that removes the code at the source position
ranges of the nodes to be removed. This will not work properly if the Babel
parser ever did not return the correct source positions, but that is not a
regression since the former algortihm already relied on the positions
being correct.
The plugin reeds to remove import statements before adding them again in the sorted order. Currently, this removal is done via a regexp https://github.com/IanVS/prettier-plugin-sort-imports/blob/main/src/utils/remove-nodes-from-original-code.ts#L37-L39
While that may be working for most cases, it is fundamentally broken and leads to cases such as
getting formatted as
We already know the start and end position of each node in the code. So we could collect the ranges
[start, end][]
of nodes to remove, sort bystart
position in reverse order (merging overlapping ranges), then delete each range from the code.The text was updated successfully, but these errors were encountered: