@@ -2442,15 +2442,25 @@ def phase_binaryen(target, options, wasm_target):
2442
2442
def modularize ():
2443
2443
global final_js
2444
2444
logger .debug (f'Modularizing, creating factory function called `{ settings .EXPORT_NAME } `' )
2445
- src = building .read_and_preprocess (utils .path_from_root ('src/modularize.js' ), expand_macros = True )
2446
- src = do_replace (src , '<<< INNER_JS_CODE >>>' , read_file (final_js ))
2445
+ modularize_src = building .read_and_preprocess (utils .path_from_root ('src/modularize.js' ), expand_macros = True )
2446
+ if settings .MINIFY_WHITESPACE :
2447
+ with shared .get_temp_files ().get_file (suffix = '.js' ) as tmp :
2448
+ write_file (tmp , modularize_src )
2449
+ minified_file = building .acorn_optimizer (tmp , ['--minify-whitespace' ])
2450
+ modularize_src = read_file (minified_file )
2451
+
2452
+ # Replace INNER_JS_CODE in the minified code
2453
+ full_src = do_replace (modularize_src , '"<<< INNER_JS_CODE >>>"' , read_file (final_js ))
2447
2454
final_js += '.modular.js'
2448
- write_file (final_js , src )
2455
+ write_file (final_js , full_src )
2449
2456
shared .get_temp_files ().note (final_js )
2450
2457
save_intermediate ('modularized' )
2451
2458
2452
- if settings .MINIFY_WHITESPACE :
2453
- final_js = building .acorn_optimizer (final_js , ['--minify-whitespace' ])
2459
+ # FIXME(https://github.com/emscripten-core/emscripten/issues/24558): Running acorn at this
2460
+ # late phase seems to cause OOM (some kind of inifite loop perhaps) in node.
2461
+ # Instead we minify src/modularize.js in isolation above.
2462
+ #if settings.MINIFY_WHITESPACE:
2463
+ # final_js = building.acorn_optimizer(final_js, ['--minify-whitespace'])
2454
2464
2455
2465
2456
2466
def module_export_name_substitution ():
0 commit comments