escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Allow 'compact' code with newlines between global statements

Open gfwilliams opened this issue 7 years ago • 2 comments

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?

gfwilliams avatar Mar 15 '17 13:03 gfwilliams

Why is this useful?

michaelficarra avatar Mar 15 '17 14:03 michaelficarra

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.

gfwilliams avatar Mar 15 '17 15:03 gfwilliams