Fork me on GitHub

part of the Shift suite

Shift Code Generator

generates an ECMAScript program from a valid Shift AST


Demo

In this demo, a Shift AST is given on the left, and the code generator output is shown on the right. Notice how the code generator outputs only the whitespace/punctuation that is strictly necessary for the program to round trip through the parser.

{ type: "Script", directives: [], statements: [ { type: "VariableDeclarationStatement", declaration: { type: "VariableDeclaration", kind: "let", declarators: [ { type: "VariableDeclarator", binding: { type: "BindingIdentifier", name: "a" }, init: { type: "LiteralNumericExpression", value: 0 } }, { type: "VariableDeclarator", binding: { type: "BindingIdentifier", name: "b" }, init: { type: "LiteralStringExpression", value: "string" } } ] } } ] }

Installation

npm install shift-codegen

Usage

import codegen from "shift-codegen";
let programSource = codegen(/* Shift AST */);