Closed satazor closed 10 years ago
The AST generated by rocambole
already contains a toString()
method.
the issue with formatting the AST is that right now I do some RegExp replacements to remove all the indent, trailing white spaces and empty lines before calling rocambole.parse(sourceString)
.. so I would need to refactor this logic before doing that. so right now you actually need to do:
esformatter.format( ast.toString() );
will leave it open since I agree that it should be able to process an AST (just not sure if it will degrade performance and how hard it will be to implement it).
as a side note, I also think the format
method should allow returning an AST so you could potentially pipe it with other tools (I would like to see a tool that forced hardwrap of long lines).
I will probably add a new method esformatter.transform( ast )
which returns the transformed AST (not a string). I would also want a way to pass a regular Esprima AST and enhance it as needed.
closing this issue in favor of #86
Format an AST
At the moment the
format
function only accepts a string. It would be nice to support a rocambole AST. In my use case, I use rocambole to fetch the AST with all those extra tokens, modify it, and want be able to format it.Don't reformat code
Assuming that the feature request above is done, I would like esformatter to be able to take an AST and output the correspondent source code WITHOUT formatting. I don't know if this gets out of the scope of this tool.