mathiasbynens / luamin

A Lua minifier written in JavaScript
https://mths.be/luamin
MIT License
217 stars 54 forks source link

Add `minifyAST(ast)` #6

Closed mathiasbynens closed 11 years ago

mathiasbynens commented 11 years ago

In some situations it would be useful to have a minifyAST method that takes a luaparse-generated AST and returns the minified Lua code as a string (as opposed to minify() which takes a Lua string and returns a minified Lua string).

We could make minify(ast) work as well (by simply adding a typeof check to minify()), but I’m not sure what would be the best solution. Overloading minify would have a minor impact on its performance, but API-wise it’s probably the most ideal solution.

Any opinions on this? /cc @oxyc @jdalton @kitcambridge

oxyc commented 11 years ago

I actually wanted this while trying out luamin. As minify is generally only called once the overloading shouldn't even happen in most cases.

Personally I prefer the solution of reusing minify :+1:

mathiasbynens commented 11 years ago

Implemented in b5ff809b6d8bfb9350d4212bed6b48f397f45934.

For some reason I absolutely love that this is possible now:

$ luaparse --scope 'a = 42' | luamin -a
a=42
mathiasbynens commented 11 years ago

@kitcambridge @jdalton If you still have any opinions on overloading functions vs. creating separate functions in general, please share :)

jdalton commented 11 years ago

@mathiasbynens It's a case by case basis (overloading vs. separate functions).