0

I want to compile part of my JS code which is based on Mootools library.

I want all the variables be renamed but none of the function, the called and defined ones. Because most of the called one are from mootools and those defined are called from outside:

code to be compiled:

// textnum is safe to be renamed, all variables are
textnum = 0;
// loadText can't be ranmed because is called from outside
function loadText()
{
    textnum++;
    document.body.setStyle("font", "12px");
    // here setSyle can't be renamed
}

Is there a way to tell it to rename only vars?

I found out this is an open source project, Is there a way to manipulate it somehow that it doesn't touch function at all!?

Ali
  • 21,572
  • 15
  • 83
  • 95
  • I guess declaring all functions, one by one, as externs isn't an option? – rmobis Dec 15 '12 at 14:01
  • From docs: to decalre an extern => function textDiv(text){}; but what about this: body.textDiv(text){} it doesn't work like that. and if it does I must define it for every element I have, not just once?!?! @Raphael_ – Ali Dec 15 '12 at 14:06
  • Declaring both `body` and `textDiv()` would prolly work for `body.textDiv()`. Yes, you'd have to declare it for every element you want to be preserved. As a matter of personal experience, I tried Google Closure a while back and it ended up being more a hassle than providing any real benefit, compared to simply minifying the code. – rmobis Dec 15 '12 at 14:09
  • @Raphael_ I found a way ;) – Ali Dec 15 '12 at 14:30

1 Answers1

3

Put the code to be compiled in a namespace or anonymous function wrapper and use simple optimizations. This renames all internal vars and functions but not global ones such as setStyle.

Functions which should not be renamed are defined in the global scope. This is not as much of a pain compared to defining externs and exports.

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
Ali
  • 21,572
  • 15
  • 83
  • 95