Rhino w. Closure compiler generating already existing functions

126 Views Asked by At

I'm using closure compiler to optimize a require.js project.

I'm using an "app.build.js" file like this method suggests:

http://requirejs.org/docs/optimization.html#wholeproject

the optimize option is set to "closure" and I run it in Java through Rhino like this:

java -classpath ./tools/lib/rhino/js.jar;./tools/lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main ./tools/require/r.js -o app.build.js dir=./temp optimize=closure

I'm using this config for closure compiler in app.build.js:

closure: {
    CompilerOptions: {},
    CompilationLevel: 'SIMPLE_OPTIMIZATIONS', 
    loggingLevel: 'WARNING'
}

After fixing some ERRORS due to the "use strict" rules, everything works fine and my project gets minified in one file. This is when running the build on Window 10.

But if I run it on another machine (under Ubuntu 16.04), some methods are name "on" by closure compiler. Thus at runtime, when I try to register a listener using "this.on("EVENT"..." It calls a random method and crash everything.

Note that "this.on" was defined in the parent class (using require extends mechanism). I've try to define it in the current class instead: closure compiler create another "on" method anyway, right next to it, which overrides the first one at runtime :'(

I'v tried to optimize only the corresponding file alone: The issue is still present, except another method is named "on", the other are named "o0" "oa" etc...

Has anyone ever exprience such a problem and do you know how to avoid it ? Maybe some compiler options I'm not aware of?

I'm using closure-compiler v20180204 (current last one)

Edit:

Seems like closure compiler is not responsible here. Indeed, using closure comp in SIMPLE mode doesn't rename anything. and using closure compiler in ADVANCED mode by itself (java -jar closure.jar ...) is working just fine.

So the question is: do Rhino apply some renaming rules when using the optimization="closure" mode? If it's the case, can we edit those rules in any mean?

0

There are 0 best solutions below