shift-printer
v1.0.1
Published
Utility methods (pretty printer, summarizer) for printing Shift ASTs
Downloads
14,267
Readme
Shift Printer
shift-printer is a module that exposes common ways you would probably want to print out JavaScript ASTs. It's a lightweight wrapper around shift-codegen that reduces the boilerplate around printing and logging.
Status
Installation
$ npm install shift-printer
Usage
const codegen = require('shift-printer');
const { parseScript } = require('shift-parser');
const ast = parseScript(`function test(a,b,c) { return a+b+c; } test(1,2,3)`);
const src = codegen.prettyPrint(ast);
console.log(src);
// the above two lines can be written as:
codegen.log(ast);
API
.prettyPrint(ast)
Prints with linebreaks, indentation, and spaces.
.print(ast)
alias of .prettyPrint()
.printTerse(ast)
Prints minimal source representation.
.prettyTruncated(ast, length = 50, overflow = '...')
Prints truncated source e.g. function test(a,b,c) { ...
.printSummary(ast)
Node-specific print rules e.g. function test(a, b, c) { ... }
log(ast)
console.log(print(ast))
logTruncated(ast, length = 50, overflow = '...')
console.log(printTruncated(ast, length, overflow))
logTerse(ast)
console.log(printTerse(ast));