command line compiler generates bigger file than the online version

548 views
Skip to first unread message

Eric Lapouyade

unread,
Jun 29, 2019, 12:27:56 PM6/29/19
to Closure Compiler Discuss
I am testing google closure compiler on command line.
I took the latest version : 

   
java -jar closure-compiler.jar --version
   
Closure Compiler (http://github.com/google/closure-compiler)
   
Version: v20190618
   
Built on: 2019-06-21 17:24


I am generating a compressed version of my javascript like this : 

   
 java -jar closure-compiler.jar my_script.js > out.js


The problem is that the generated code is bigger than the one I get when I use the online service at https://closure-compiler.appspot.com/home

I noticed that the command line version added, at the beginning, the following code :

   
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,c,b){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e<d;e++){var f=a[e];if(c.call(b,f,e,a))return{i:e,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
    $jscomp
.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
    $jscomp
.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");




I do not have such a code in my script: Where does it come from ? 
how can I produce the same output as the online version ?

Laura Harker

unread,
Jun 29, 2019, 1:00:10 PM6/29/19
to closure-comp...@googlegroups.com
The generated code comes from the Closure Compiler's polyfill for Array.prototype.find.

The compiler defaults to targeting the ECMAScript5 spec. If you don't need to support IE or older browsers, you can change the compiler's target language with  --language_out=ECMASCRIPT_2015 (or higher). This tells the compiler not to polyfill Array.prototype.find and also disables transpilation of newer language features.

The webservice and command line produce different results because the webservice disables polyfill injection by default. You can manually disable polyfill injection with --rewrite_polyfills=false.


--

---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/bb8f3c62-264c-4457-b85f-115ac089ce72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Lapouyade

unread,
Jun 29, 2019, 5:43:29 PM6/29/19
to closure-comp...@googlegroups.com
Thank you,

It works as expected now with your options.

Reply all
Reply to author
Forward
0 new messages