-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Parsing and generating while preserving whitespace #16621
Comments
Hey @KernelDeimos! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
Check out https://github.com/benjamn/recast |
Oh, this can be de-coupled! After reading the README of recast that makes a lot of sense. I'm closing my issue because IMO this is the right solution. |
Fyi, I plan to start working on this soon: babel/rfcs#15 |
I eagerly await this and I'm re-opening the issue I posted. I don't know which will come first, but "august of last year" doesn't inspire confidence in the recast issue I linked. |
Does this mean... it's impossible to make refactoring tools like I described right now? (without writing a generator or fixing one I mean) Is there actually no source code in existence that can do this on modern javascript code? I just want to make sure I'm not misunderstanding something; Javascript is one of the most popular languages on the planet right now and this came as a surprise to me. |
You can also use |
💻
What problem are you trying to solve?
I'd like to build refactoring tools using babel, but I don't want these tools to be "disruptive" and cause unnecessary whitespace changes. For example this feature request was dropped, so my refactoring tool wouldn't be compatible with a project using 4 spaces for indentation; that said, this wouldn't have been a good solution for me anyway because a project might have inconsistent indentation or other whitespace oddities.
Seeing as
@babel/parser
outputs a CST rather than an AST without position information, it seems entirely plausible for@babel/generator
to output in accordance with the CST.Describe the solution you'd like
Option to preserve whitespace in the generator
Describe alternatives you've considered
Using another package like
escodegen
, but@babel/generator
is the only package I've found with good support for modern syntax.Documentation, Adoption, Migration Strategy
To the user of the package I imagine this would be a flag. This flag would be mutually exclusive to some other flags though such as
retainLines
, so perhaps this nuance should be documented as well. When the flag is not set,@babel/generator
should behave exactly as it currently does to avoid regressions.The text was updated successfully, but these errors were encountered: