escodegen
escodegen copied to clipboard
Allow 'compact' code with newlines between global statements
Quite often I see minified code that puts individual statements at the global level on different lines.
For example:
function a() { ... }
function b() { ... function c() { ... } }
var x;
Unfortunately right now it looks like escodegen only does:
function a() { ... }function b() { ... function c() { ... } }var x;
or adds newlines everywhere.
A semi-compact option would be great, and I've had some success doing this by adding a special newline
variable that only gets added from Syntax.Program
.
Is this something of interest? I can produce a PR?
Why is this useful?
In my case, I'm using escodegen to create minified code to send to a microcontroller running JS (Espruino). It interprets each function as it gets it after a newline is received - effectively as if it were entered by a user in a REPL.
If everything is in one line, you end up with several thousand characters to execute in one go, which fills up all the available memory and breaks things.