-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format-preserving code printer #15
base: main
Are you sure you want to change the base?
Format-preserving code printer #15
Conversation
Thank you very much for the detailed description! Would it be faster/more accurate/easier to implement if we required the corresponding options to be enabled in the parser or used Also, I'm curious, how do users expect the formatting of the edited code? |
Yes the plan is to use
This is something that we need to explore :) I think for now it would be good enough to have the "standard formatting" when using injected code, and only respect the format for the lines/nodes that are not modified. |
You can also go about the same goal by using a CST, which is to say by storing a node's syntactic tokens together with that node instead of having them in a single flat |
A note: this would make Babel a first-class codemod engine, but it would remain unable to do one of the basic tasks of codemodding: inserting a blank line. Also as far as I can tell when using the expression templating engine, formatting from the template expression would not be preserved. E.g. expr`[ ${expr` [ ] `} ] ;` // [[]] instead of [ [] ] |
I am worried that this would need significant changes to transform plugins to preserve the CST info, while the goal of this proposal is to require changes (almost) only in the code generator. |
Yeah, I think implementing this proposal is probably the best step Babel can take right now. I'm more trying to introduce a distinction between what is an small incremental improvement, vs what would it look like to solve this problem for the long run. |
I think it's also worth noting that this puts Babel on a collision course with ESLint and Prettier. When things started out it was clear what was what. I'd describe it like this:
Each of these tools has started to encounter similar problems like precedence, comment attachment, and multilingualism, though, so that it is no longer easy to explain the distinctions in which tool to use and when, and is especially not easy to explain how all the tools are meant to be used together -- programmatically I mean, not in the sense of "install all their VSCode extensions." |
View as rendered text
We have been talking for a while about an option to preserve the output format after running Babel, so I wrote down how I think it should be done. Feedback welcome!