MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / minify_wasm_js

Function minify_wasm_js

tools/building.py:758–793  ·  view source on GitHub ↗
(js_file, wasm_file, expensive_optimizations, debug_info)

Source from the content-addressed store, hash-verified

756# minify the final wasm+JS combination. this is done after all the JS
757# and wasm optimizations; here we do the very final optimizations on them
758def minify_wasm_js(js_file, wasm_file, expensive_optimizations, debug_info):
759 # start with JSDCE, to clean up obvious JS garbage. When optimizing for size,
760 # use AJSDCE (aggressive JS DCE, performs multiple iterations). Clean up
761 # whitespace if necessary too.
762 passes = []
763 if not settings.LINKABLE:
764 passes.append('JSDCE' if not expensive_optimizations else 'AJSDCE')
765 # Don't minify if we are going to run closure compiler afterwards
766 minify = settings.MINIFY_WHITESPACE and not settings.MAYBE_CLOSURE_COMPILER
767 if minify:
768 passes.append('--minify-whitespace')
769 if passes:
770 logger.debug('running cleanup on shell code: ' + ' '.join(passes))
771 js_file = acorn_optimizer(js_file, passes)
772 # if we can optimize this js+wasm combination under the assumption no one else
773 # will see the internals, do so
774 if not settings.LINKABLE:
775 # if we are optimizing for size, shrink the combined wasm+JS
776 # TODO: support this when a symbol map is used
777 if expensive_optimizations:
778 js_file = metadce(js_file,
779 wasm_file,
780 debug_info=debug_info,
781 last=not settings.MINIFY_WASM_IMPORTS_AND_EXPORTS)
782 # now that we removed unneeded communication between js and wasm, we can clean up
783 # the js some more.
784 passes = ['AJSDCE']
785 if minify:
786 passes.append('--minify-whitespace')
787 logger.debug('running post-meta-DCE cleanup on shell code: ' + ' '.join(passes))
788 js_file = acorn_optimizer(js_file, passes)
789 if settings.MINIFY_WASM_IMPORTS_AND_EXPORTS:
790 js_file = minify_wasm_imports_and_exports(js_file, wasm_file,
791 minify_exports=settings.MINIFY_WASM_EXPORT_NAMES,
792 debug_info=debug_info)
793 return js_file
794
795
796# get the flags to pass into the very last binaryen tool invocation, that runs

Callers

nothing calls this directly

Calls 5

acorn_optimizerFunction · 0.85
metadceFunction · 0.85
appendMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected