luamin uses the excellent gluaparse library to parse Lua code into an Abstract Syntax Tree. Based on that AST, luamin then generates a (hopefully) more compact yet semantically equivalent Lua program. Here’s an online demo.
luamin was inspired by the LuaMinify and Esmangle projects.
Feel free to fork if you see possible improvements!
var luaCode = 'a = ((1 + 2) - 3) * (4 / (5 ^ 6)) -- foo';
luamin.minify(luaCode); // 'a=(1+2-3)*4/5^6'
// `minify` also accepts luaparse-compatible ASTs as its argument:
var ast = gluaparse.parse(luaCode, { 'scope': true });
luamin.minify(ast); // 'a=(1+2-3)*4/5^6'
Mathias Bynens |
luamin is available under the MIT license.