How to insert nodes with proper position data? #84
-
I have developed a sort of codemod / syntax conversion tool using rehype, and I am inserting nodes at various points of the AST, some are elements, most are comments and new lines. I would like for users of the tool to clearly see what changes the tool has done. Unfortunately, my file loses its previous formatting / spacing when I insert nodes, which then makes file diffs unreadable. I understand that this happens because I am not providing accurate I've looked at the tree traversal guides and I don't see any mention of dealing with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your problem most likely does not have to do with You can either:
|
Beta Was this translation helpful? Give feedback.
Your problem most likely does not have to do with
position
s. Your problem has to do with ASTs: ASTs are abstract. They don’t have information about which quote was used ("
or'
) and other “insignificant” information.When you generate output from an AST, it will often look different from the input with white-space and the like.
You can either: