Skip to content

How to insert nodes with proper position data? #84

Answered by wooorm
AshtarCodes asked this question in Q&A
Discussion options

You must be logged in to vote

Your problem most likely does not have to do with positions. 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:

  • first reformat (parse and serialize) and save that result as X, then perform your codemod on X and save the result as Y, and finally compare X and Y.
  • Diff in whitespace-insensitive mode
  • Probably much more, but I’d probably need to learn more about your setup first

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AshtarCodes
Comment options

Answer selected by AshtarCodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants