@@ -513,6 +513,10 @@ def do_split_module(wasm_file, options):
513
513
building .run_binaryen_command ('wasm-split' , wasm_file + '.orig' , outfile = wasm_file , args = args )
514
514
515
515
516
+ def get_worker_js_suffix ():
517
+ return '.worker.mjs' if settings .EXPORT_ES6 else '.worker.js'
518
+
519
+
516
520
def setup_pthreads (target ):
517
521
if settings .RELOCATABLE :
518
522
# phtreads + dyanmic linking has certain limitations
@@ -569,7 +573,7 @@ def setup_pthreads(target):
569
573
building .user_requested_exports .update (worker_imports )
570
574
571
575
# 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 ()
573
577
574
578
if settings .MINIMAL_RUNTIME :
575
579
building .user_requested_exports .add ('exit' )
@@ -1999,12 +2003,27 @@ def phase_memory_initializer(memfile):
1999
2003
final_js += '.mem.js'
2000
2004
2001
2005
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
+
2002
2019
def create_worker_file (input_file , target_dir , output_file ):
2003
2020
output_file = os .path .join (target_dir , output_file )
2004
2021
input_file = utils .path_from_root (input_file )
2005
2022
contents = shared .read_and_preprocess (input_file , expand_macros = True )
2006
2023
write_file (output_file , contents )
2007
2024
2025
+ fix_es6_import_statements (output_file )
2026
+
2008
2027
# Minify the worker JS file, if JS minification is enabled.
2009
2028
if settings .MINIFY_WHITESPACE :
2010
2029
contents = building .acorn_optimizer (output_file , ['minifyWhitespace' ], return_output = True )
@@ -2045,17 +2064,8 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
2045
2064
# mode)
2046
2065
final_js = building .closure_compiler (final_js , advanced = False , extra_closure_args = options .closure_args )
2047
2066
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' )
2059
2069
2060
2070
# Apply pre and postjs files
2061
2071
if options .extern_pre_js or options .extern_post_js :
@@ -2600,7 +2610,7 @@ def generate_worker_js(target, js_target, target_basename):
2600
2610
proxy_worker_filename = get_subresource_location (js_target )
2601
2611
else :
2602
2612
# 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 () ))
2604
2614
worker_target_basename = target_basename + '.worker'
2605
2615
proxy_worker_filename = (settings .PROXY_TO_WORKER_FILENAME or worker_target_basename ) + '.js'
2606
2616
0 commit comments