Is there is a way to easily jump a line ?
fraxken opened this issue · comments
Thomas.G commented
Hi,
I'm using this lib to generate JavaScript code from a generated AST but i wanted to add some blank line between some of my stmt. Is there is a way to achieve this without having to go in a complicated code that deal with start/end ?
Sorry for the newbie question and thanks for your time !
Best Regards,
Thomas
David Bonnet commented
This can be easily achieved by defining a custom generator.
For example, the following adds blank lines before/after each function declaration:
import { generate, baseGenerator } from 'astring'
generate(ast, {
generator: {
...baseGenerator,
FunctionDeclaration(node, state) {
state.write('\n')
baseGenerator.FunctionDeclaration(node, state)
state.write('\n')
},
},
})