@@ -513,6 +513,10 @@ def do_split_module(wasm_file, options):
513513 building .run_binaryen_command ('wasm-split' , wasm_file + '.orig' , outfile = wasm_file , args = args )
514514
515515
516+ def get_worker_js_suffix ():
517+ return '.worker.mjs' if settings .EXPORT_ES6 else '.worker.js'
518+
519+
516520def setup_pthreads (target ):
517521 if settings .RELOCATABLE :
518522 # phtreads + dyanmic linking has certain limitations
@@ -569,7 +573,7 @@ def setup_pthreads(target):
569573 building .user_requested_exports .update (worker_imports )
570574
571575 # set location of worker.js
572- settings .PTHREAD_WORKER_FILE = unsuffixed_basename (target ) + '.worker.js'
576+ settings .PTHREAD_WORKER_FILE = unsuffixed_basename (target ) + get_worker_js_suffix ()
573577
574578 if settings .MINIMAL_RUNTIME :
575579 building .user_requested_exports .add ('exit' )
@@ -1999,12 +2003,27 @@ def phase_memory_initializer(memfile):
19992003 final_js += '.mem.js'
20002004
20012005
2006+ # Unmangle previously mangled `import.meta` and `await import` references in
2007+ # both main code and libraries.
2008+ # See also: `preprocess` in parseTools.js.
2009+ def fix_es6_import_statements (js_file ):
2010+ if not settings .EXPORT_ES6 or not settings .USE_ES6_IMPORT_META :
2011+ return
2012+
2013+ src = read_file (js_file )
2014+ write_file (js_file , src
2015+ .replace ('EMSCRIPTEN$IMPORT$META' , 'import.meta' )
2016+ .replace ('EMSCRIPTEN$AWAIT$IMPORT' , 'await import' ))
2017+
2018+
20022019def create_worker_file (input_file , target_dir , output_file ):
20032020 output_file = os .path .join (target_dir , output_file )
20042021 input_file = utils .path_from_root (input_file )
20052022 contents = shared .read_and_preprocess (input_file , expand_macros = True )
20062023 write_file (output_file , contents )
20072024
2025+ fix_es6_import_statements (output_file )
2026+
20082027 # Minify the worker JS file, if JS minification is enabled.
20092028 if settings .MINIFY_WHITESPACE :
20102029 contents = building .acorn_optimizer (output_file , ['minifyWhitespace' ], return_output = True )
@@ -2045,17 +2064,8 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
20452064 # mode)
20462065 final_js = building .closure_compiler (final_js , advanced = False , extra_closure_args = options .closure_args )
20472066
2048- # Unmangle previously mangled `import.meta` and `await import` references in
2049- # both main code and libraries.
2050- # See also: `preprocess` in parseTools.js.
2051- if settings .EXPORT_ES6 and settings .USE_ES6_IMPORT_META :
2052- src = read_file (final_js )
2053- final_js += '.esmeta.js'
2054- write_file (final_js , src
2055- .replace ('EMSCRIPTEN$IMPORT$META' , 'import.meta' )
2056- .replace ('EMSCRIPTEN$AWAIT$IMPORT' , 'await import' ))
2057- shared .get_temp_files ().note (final_js )
2058- save_intermediate ('es6-module' )
2067+ fix_es6_import_statements (final_js )
2068+ save_intermediate ('es6-module' )
20592069
20602070 # Apply pre and postjs files
20612071 if options .extern_pre_js or options .extern_post_js :
@@ -2600,7 +2610,7 @@ def generate_worker_js(target, js_target, target_basename):
26002610 proxy_worker_filename = get_subresource_location (js_target )
26012611 else :
26022612 # compiler output goes in .worker.js file
2603- move_file (js_target , shared .replace_suffix (js_target , '.worker.js' ))
2613+ move_file (js_target , shared .replace_suffix (js_target , get_worker_js_suffix () ))
26042614 worker_target_basename = target_basename + '.worker'
26052615 proxy_worker_filename = (settings .PROXY_TO_WORKER_FILENAME or worker_target_basename ) + '.js'
26062616
0 commit comments