@@ -485,16 +485,16 @@ def add_to_path(dirname):
485485
486486
487487@ToolchainProfiler .profile ()
488- def closure_transpile (filename , pretty ):
488+ def closure_transpile (filename ):
489489 user_args = []
490490 closure_cmd , env = get_closure_compiler_and_env (user_args )
491491 closure_cmd += ['--language_out' , 'ES5' ]
492492 closure_cmd += ['--compilation_level' , 'WHITESPACE_ONLY' ]
493- return run_closure_cmd (closure_cmd , filename , env , pretty )
493+ return run_closure_cmd (closure_cmd , filename , env )
494494
495495
496496@ToolchainProfiler .profile ()
497- def closure_compiler (filename , pretty , advanced = True , extra_closure_args = None ):
497+ def closure_compiler (filename , advanced = True , extra_closure_args = None ):
498498 user_args = []
499499 env_args = os .environ .get ('EMCC_CLOSURE_ARGS' )
500500 if env_args :
@@ -573,10 +573,10 @@ def closure_compiler(filename, pretty, advanced=True, extra_closure_args=None):
573573 args += user_args
574574
575575 cmd = closure_cmd + args
576- return run_closure_cmd (cmd , filename , env , pretty = pretty )
576+ return run_closure_cmd (cmd , filename , env )
577577
578578
579- def run_closure_cmd (cmd , filename , env , pretty ):
579+ def run_closure_cmd (cmd , filename , env ):
580580 cmd += ['--js' , filename ]
581581
582582 # Closure compiler is unable to deal with path names that are not 7-bit ASCII:
@@ -605,7 +605,7 @@ def move_to_safe_7bit_ascii_filename(filename):
605605
606606 # Specify output file relative to the temp directory to avoid specifying non-7-bit-ASCII path names.
607607 cmd += ['--js_output_file' , os .path .relpath (outfile , tempfiles .tmpdir )]
608- if pretty :
608+ if not settings . MINIFY_WHITESPACE :
609609 cmd += ['--formatting' , 'PRETTY_PRINT' ]
610610
611611 shared .print_compiler_stage (cmd )
@@ -645,7 +645,7 @@ def move_to_safe_7bit_ascii_filename(filename):
645645
646646 # Exit and print final hint to get clearer output
647647 msg = f'closure compiler failed (rc: { proc .returncode } ): { shared .shlex_join (cmd )} '
648- if not pretty :
648+ if settings . MINIFY_WHITESPACE :
649649 msg += ' the error message may be clearer with -g1 and EMCC_DEBUG=2 set'
650650 exit_with_error (msg )
651651
@@ -657,7 +657,7 @@ def move_to_safe_7bit_ascii_filename(filename):
657657 logger .warn (proc .stderr )
658658
659659 # Exit and/or print final hint to get clearer output
660- if not pretty :
660+ if settings . MINIFY_WHITESPACE :
661661 logger .warn ('(rerun with -g1 linker flag for an unminified output)' )
662662 elif DEBUG != 2 :
663663 logger .warn ('(rerun with EMCC_DEBUG=2 enabled to dump Closure input file)' )
@@ -670,14 +670,16 @@ def move_to_safe_7bit_ascii_filename(filename):
670670
671671# minify the final wasm+JS combination. this is done after all the JS
672672# and wasm optimizations; here we do the very final optimizations on them
673- def minify_wasm_js (js_file , wasm_file , expensive_optimizations , minify_whitespace , debug_info ):
673+ def minify_wasm_js (js_file , wasm_file , expensive_optimizations , debug_info ):
674674 # start with JSDCE, to clean up obvious JS garbage. When optimizing for size,
675675 # use AJSDCE (aggressive JS DCE, performs multiple iterations). Clean up
676676 # whitespace if necessary too.
677677 passes = []
678678 if not settings .LINKABLE :
679679 passes .append ('JSDCE' if not expensive_optimizations else 'AJSDCE' )
680- if minify_whitespace :
680+ # Don't minify if we are going to run closure compiler afterwards
681+ minify = settings .MINIFY_WHITESPACE and not settings .USE_CLOSURE_COMPILER
682+ if minify :
681683 passes .append ('minifyWhitespace' )
682684 if passes :
683685 logger .debug ('running cleanup on shell code: ' + ' ' .join (passes ))
@@ -688,24 +690,23 @@ def minify_wasm_js(js_file, wasm_file, expensive_optimizations, minify_whitespac
688690 # if we are optimizing for size, shrink the combined wasm+JS
689691 # TODO: support this when a symbol map is used
690692 if expensive_optimizations :
691- js_file = metadce (js_file , wasm_file , minify_whitespace = minify_whitespace , debug_info = debug_info )
693+ js_file = metadce (js_file , wasm_file , debug_info = debug_info )
692694 # now that we removed unneeded communication between js and wasm, we can clean up
693695 # the js some more.
694696 passes = ['AJSDCE' ]
695- if minify_whitespace :
697+ if minify :
696698 passes .append ('minifyWhitespace' )
697699 logger .debug ('running post-meta-DCE cleanup on shell code: ' + ' ' .join (passes ))
698700 js_file = acorn_optimizer (js_file , passes )
699701 if settings .MINIFY_WASM_IMPORTS_AND_EXPORTS :
700702 js_file = minify_wasm_imports_and_exports (js_file , wasm_file ,
701- minify_whitespace = minify_whitespace ,
702703 minify_exports = settings .MINIFY_WASM_EXPORT_NAMES ,
703704 debug_info = debug_info )
704705 return js_file
705706
706707
707708# run binaryen's wasm-metadce to dce both js and wasm
708- def metadce (js_file , wasm_file , minify_whitespace , debug_info ):
709+ def metadce (js_file , wasm_file , debug_info ):
709710 logger .debug ('running meta-DCE' )
710711 temp_files = shared .get_temp_files ()
711712 # first, get the JS part of the graph
@@ -788,7 +789,7 @@ def metadce(js_file, wasm_file, minify_whitespace, debug_info):
788789 unused .append (name )
789790 # remove them
790791 passes = ['applyDCEGraphRemovals' ]
791- if minify_whitespace :
792+ if settings . MINIFY_WHITESPACE :
792793 passes .append ('minifyWhitespace' )
793794 extra_info = {'unused' : unused }
794795 return acorn_optimizer (js_file , passes , extra_info = json .dumps (extra_info ))
@@ -819,7 +820,7 @@ def asyncify_lazy_load_code(wasm_target, debug):
819820 debug = debug )
820821
821822
822- def minify_wasm_imports_and_exports (js_file , wasm_file , minify_whitespace , minify_exports , debug_info ):
823+ def minify_wasm_imports_and_exports (js_file , wasm_file , minify_exports , debug_info ):
823824 logger .debug ('minifying wasm imports and exports' )
824825 # run the pass
825826 if minify_exports :
@@ -850,13 +851,13 @@ def minify_wasm_imports_and_exports(js_file, wasm_file, minify_whitespace, minif
850851 mapping [old ] = new
851852 # apply them
852853 passes = ['applyImportAndExportNameChanges' ]
853- if minify_whitespace :
854+ if settings . MINIFY_WHITESPACE :
854855 passes .append ('minifyWhitespace' )
855856 extra_info = {'mapping' : mapping }
856857 return acorn_optimizer (js_file , passes , extra_info = json .dumps (extra_info ))
857858
858859
859- def wasm2js (js_file , wasm_file , opt_level , minify_whitespace , use_closure_compiler , debug_info , symbols_file = None , symbols_file_js = None ):
860+ def wasm2js (js_file , wasm_file , opt_level , use_closure_compiler , debug_info , symbols_file = None , symbols_file_js = None ):
860861 logger .debug ('wasm2js' )
861862 args = ['--emscripten' ]
862863 if opt_level > 0 :
@@ -876,7 +877,7 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
876877 passes += ['minifyNames' ]
877878 if symbols_file_js :
878879 passes += ['symbolMap=%s' % symbols_file_js ]
879- if minify_whitespace :
880+ if settings . MINIFY_WHITESPACE :
880881 passes += ['minifyWhitespace' ]
881882 passes += ['last' ]
882883 if passes :
@@ -897,7 +898,7 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
897898 temp = shared .get_temp_files ().get ('.js' ).name
898899 with open (temp , 'a' ) as f :
899900 f .write (wasm2js_js )
900- temp = closure_compiler (temp , pretty = not minify_whitespace , advanced = False )
901+ temp = closure_compiler (temp , advanced = False )
901902 wasm2js_js = utils .read_file (temp )
902903 # closure may leave a trailing `;`, which would be invalid given where we place
903904 # this code (inside parens)
0 commit comments