Escodegen (escodegen) is an
ECMAScript
(also popularly known as JavaScript)
code generator from Mozilla's Parser API
AST. See the online generator
for a demo. This repository contains the Python translation of Escodegen.
Install
pip install escodegen
Usage
Example:
import escodegen
escodegen.generate({
'type': 'BinaryExpression',
'operator': '+',
'left': { 'type': 'Literal', 'value': 20 },
'right': { 'type': 'Literal', 'value': 2 }
})
produces the string: '20 + 2'
Example:
import escodegen
import esprima
escodegen.generate(esprima.parse('let a=10;let b=20'))
produces the string: 'let a = 10;\nlet b = 20;'
See the API page for
options.