Package Exports
- @putout/printer
Readme
Printer 
Prints Babel AST to readable JavaScript.
- ☝️ Similar to Recast, but simpler and easier in maintenance, since it supports only Babel.
- ☝️ As opinionated as Prettier, but has more user-friendly output and works directly with AST.
- ☝️ Like ESLint but without any configuration and plugins 🤷, also works directly with Babel AST only.
Install
npm i @putout/printerAPI
const {print} = require('@putout/printer');
const {parse} = require('@babel/parser');
const ast = parse('const a = (b, c) => {const d = 5; return a;}');
print(ast);
// returns
`
const a = (b, c) => {
const d = 5;
return a;
};
`;Overrides
When you need to extend syntax of @putout/printer just pass a function which receives:
path, Babel Pathprint, a function to output result of printing into token array;
When path contains to dashes __ and name, it is the same as: print(path.get('right')), and this is
actually traverse(path.get('right')) shortened to simplify read and process.
Here is how you can override AssignmentPattern:
const ast = parse('const {a = 5} = b');
print(ast, {
format: {
indent: ' ',
},
visitors: {
AssignmentPattern(path, {print}) {
print(' /* [hello world] */= ');
print('__right');
},
},
});
// returns
'const {a /* [hello world] */= 5} = b;\n\n';License
MIT