@@ -485,16 +485,16 @@ def add_to_path(dirname):
485
485
486
486
487
487
@ToolchainProfiler .profile ()
488
- def closure_transpile (filename , pretty ):
488
+ def closure_transpile (filename ):
489
489
user_args = []
490
490
closure_cmd , env = get_closure_compiler_and_env (user_args )
491
491
closure_cmd += ['--language_out' , 'ES5' ]
492
492
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 )
494
494
495
495
496
496
@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 ):
498
498
user_args = []
499
499
env_args = os .environ .get ('EMCC_CLOSURE_ARGS' )
500
500
if env_args :
@@ -573,10 +573,10 @@ def closure_compiler(filename, pretty, advanced=True, extra_closure_args=None):
573
573
args += user_args
574
574
575
575
cmd = closure_cmd + args
576
- return run_closure_cmd (cmd , filename , env , pretty = pretty )
576
+ return run_closure_cmd (cmd , filename , env )
577
577
578
578
579
- def run_closure_cmd (cmd , filename , env , pretty ):
579
+ def run_closure_cmd (cmd , filename , env ):
580
580
cmd += ['--js' , filename ]
581
581
582
582
# 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):
605
605
606
606
# Specify output file relative to the temp directory to avoid specifying non-7-bit-ASCII path names.
607
607
cmd += ['--js_output_file' , os .path .relpath (outfile , tempfiles .tmpdir )]
608
- if pretty :
608
+ if not settings . MINIFY_WHITESPACE :
609
609
cmd += ['--formatting' , 'PRETTY_PRINT' ]
610
610
611
611
shared .print_compiler_stage (cmd )
@@ -645,7 +645,7 @@ def move_to_safe_7bit_ascii_filename(filename):
645
645
646
646
# Exit and print final hint to get clearer output
647
647
msg = f'closure compiler failed (rc: { proc .returncode } ): { shared .shlex_join (cmd )} '
648
- if not pretty :
648
+ if settings . MINIFY_WHITESPACE :
649
649
msg += ' the error message may be clearer with -g1 and EMCC_DEBUG=2 set'
650
650
exit_with_error (msg )
651
651
@@ -657,7 +657,7 @@ def move_to_safe_7bit_ascii_filename(filename):
657
657
logger .warn (proc .stderr )
658
658
659
659
# Exit and/or print final hint to get clearer output
660
- if not pretty :
660
+ if settings . MINIFY_WHITESPACE :
661
661
logger .warn ('(rerun with -g1 linker flag for an unminified output)' )
662
662
elif DEBUG != 2 :
663
663
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):
670
670
671
671
# minify the final wasm+JS combination. this is done after all the JS
672
672
# 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 ):
674
674
# start with JSDCE, to clean up obvious JS garbage. When optimizing for size,
675
675
# use AJSDCE (aggressive JS DCE, performs multiple iterations). Clean up
676
676
# whitespace if necessary too.
677
677
passes = []
678
678
if not settings .LINKABLE :
679
679
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 :
681
683
passes .append ('minifyWhitespace' )
682
684
if passes :
683
685
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
688
690
# if we are optimizing for size, shrink the combined wasm+JS
689
691
# TODO: support this when a symbol map is used
690
692
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 )
692
694
# now that we removed unneeded communication between js and wasm, we can clean up
693
695
# the js some more.
694
696
passes = ['AJSDCE' ]
695
- if minify_whitespace :
697
+ if minify :
696
698
passes .append ('minifyWhitespace' )
697
699
logger .debug ('running post-meta-DCE cleanup on shell code: ' + ' ' .join (passes ))
698
700
js_file = acorn_optimizer (js_file , passes )
699
701
if settings .MINIFY_WASM_IMPORTS_AND_EXPORTS :
700
702
js_file = minify_wasm_imports_and_exports (js_file , wasm_file ,
701
- minify_whitespace = minify_whitespace ,
702
703
minify_exports = settings .MINIFY_WASM_EXPORT_NAMES ,
703
704
debug_info = debug_info )
704
705
return js_file
705
706
706
707
707
708
# 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 ):
709
710
logger .debug ('running meta-DCE' )
710
711
temp_files = shared .get_temp_files ()
711
712
# first, get the JS part of the graph
@@ -788,7 +789,7 @@ def metadce(js_file, wasm_file, minify_whitespace, debug_info):
788
789
unused .append (name )
789
790
# remove them
790
791
passes = ['applyDCEGraphRemovals' ]
791
- if minify_whitespace :
792
+ if settings . MINIFY_WHITESPACE :
792
793
passes .append ('minifyWhitespace' )
793
794
extra_info = {'unused' : unused }
794
795
return acorn_optimizer (js_file , passes , extra_info = json .dumps (extra_info ))
@@ -819,7 +820,7 @@ def asyncify_lazy_load_code(wasm_target, debug):
819
820
debug = debug )
820
821
821
822
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 ):
823
824
logger .debug ('minifying wasm imports and exports' )
824
825
# run the pass
825
826
if minify_exports :
@@ -850,13 +851,13 @@ def minify_wasm_imports_and_exports(js_file, wasm_file, minify_whitespace, minif
850
851
mapping [old ] = new
851
852
# apply them
852
853
passes = ['applyImportAndExportNameChanges' ]
853
- if minify_whitespace :
854
+ if settings . MINIFY_WHITESPACE :
854
855
passes .append ('minifyWhitespace' )
855
856
extra_info = {'mapping' : mapping }
856
857
return acorn_optimizer (js_file , passes , extra_info = json .dumps (extra_info ))
857
858
858
859
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 ):
860
861
logger .debug ('wasm2js' )
861
862
args = ['--emscripten' ]
862
863
if opt_level > 0 :
@@ -876,7 +877,7 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
876
877
passes += ['minifyNames' ]
877
878
if symbols_file_js :
878
879
passes += ['symbolMap=%s' % symbols_file_js ]
879
- if minify_whitespace :
880
+ if settings . MINIFY_WHITESPACE :
880
881
passes += ['minifyWhitespace' ]
881
882
passes += ['last' ]
882
883
if passes :
@@ -897,7 +898,7 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
897
898
temp = shared .get_temp_files ().get ('.js' ).name
898
899
with open (temp , 'a' ) as f :
899
900
f .write (wasm2js_js )
900
- temp = closure_compiler (temp , pretty = not minify_whitespace , advanced = False )
901
+ temp = closure_compiler (temp , advanced = False )
901
902
wasm2js_js = utils .read_file (temp )
902
903
# closure may leave a trailing `;`, which would be invalid given where we place
903
904
# this code (inside parens)
0 commit comments