What’s New in SlimIt 0.6.1

by Ruslan Spivak on March 15, 2012

While the new version of SlimIt is mostly a bugfix release:
- Problem with “+”, “++” and whitespace
- Problem with for loop with ? operator in initializer position

there is also one new feature: -t / –mangle-toplevel command-line option.
It allows you to turn on global scope name mangling which is now off by default.
Let’s see it in action.

$ cat test.js
function foo(first, second){
  alert(first, second);
}

foo();

Global scope mangling is off by default:

$ slimit -m test.js
function foo(a,b){alert(a,b);}foo();

With global scope name mangling on:

$ slimit -m --mangle-toplevel test.js
function a(a,b){alert(a,b);}a();

In Python code pass mangle_toplevel=True argument to minify function:

>>> from slimit import minify
>>> text = """\
... function foo(first, second){
...   alert(first, second);
... }
...
... foo();
... """
>>> minify(text, mangle=True, mangle_toplevel=True)
'function a(a,b){alert(a,b);}a();'
If you enjoyed this post why not subscribe via email or my RSS feed and get the latest updates immediately. You can also follow me on GitHub or Twitter.

Speak your mind

Previous post:

Next post: