GHC JS Backend - Improve compiled size

True. Sorry about that. These are the errors:

$ npx google-closure-compiler --js=all.js --externs all.externs.js --js_output_file=out.min.js --compilation_level ADVANCED_OPTIMIZATIONS --language_in UNSTABLE 

... warnings ...

all.js:8831:11: ERROR - [JSC_UNDEFINED_VARIABLE] variable MK_INTEGER_S is undeclared
  8831|     return MK_INTEGER_S(parseInt(str, 10));
                   ^^^^^^^^^^^^

all.js:8833:11: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$ghcjsbn_readInteger is undeclared
  8833|     return h$ghcjsbn_readInteger(str);
                   ^^^^^^^^^^^^^^^^^^^^^

all.js:8904:126: ERROR - [JSC_UNDEFINED_VARIABLE] variable a is undeclared
  8904|     while(--i>=0) r = (h$c2(h$ghczmprimZCGHCziTypesziZC_con_e, ((h$c1(h$ghczminternalZCGHCziInternalziJSziPrimziJSVal_con_e, (a[i])))), (r)));
                                                                                                                                      ^

all.js:8931:14: ERROR - [JSC_UNDEFINED_VARIABLE] variable ls is undeclared
  8931|     for(var i=ls-k;i>=0;i-=k) r = (h$c2(h$ghczmprimZCGHCziTypesziZC_con_e, ((h$c1(h$ghczminternalZCGHCziInternalziJSziPrimziJSVal_con_e, (x.substr(i,i+k))))), (r)));
                      ^^

all.js:19980:0: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$stg_absentErrorzh is undeclared
  19980| h$stg_absentErrorzh(b,c);
         ^^^^^^^^^^^^^^^^^^^

all.js:19986:0: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$stg_paniczh is undeclared
  19986| h$stg_paniczh(h$ghczmprimZCGHCziPrimziPaniczilvl_1,h$ghczmprimZCGHCziPrimziPaniczilvl_2);
         ^^^^^^^^^^^^^

6 error(s), 80 warning(s)

UPDATE:
It seems like I have gotten it to work now thanks to the old wiki that @alexfmpe linked.
I used the additional option --jscomp_off=checkVars and then it completed successfully.
So my command was: $ npx google-closure-compiler --js=all.js --jscomp_off=checkVars --externs all.externs.js --js_output_file=out.min.js --compilation_level ADVANCED_OPTIMIZATIONS --language_in UNSTABLE

The file is now 3.3 MiB. And from my initial testing everything seems to still work as expected!

But I assume I should also use the following two additional options: --isolation_mode=IIFE --assume_function_wrapper as documented in the old wiki and its also used in the Makefile mentioned before.

1 Like