I am looking for a way to dynamically change variable and function names in a JavaScript file under certain conditions, similar to how a JavaScript minifier operates. Here is an example: I start with the following JavaScript code:
var something=5;
something++;
function doSomething(n){
alert(n);
}
doSomething(something):
Now, I want to swap out something
and doSomething
with somethingElse
and doSomethingElse
, resulting in the modified Javascript code below:
var somethingElse=5;
somethingElse++;
function doSomethingElse(n){
alert(n);
}
doSomethingElse(somethingElse):
I believe this task can be accomplished using Rhino or Google Closure Compiler (which is Rhino-based), although I'm uncertain of the exact process. Any alternative suggestions are also welcome.
Thank you