@@ -2365,21 +2365,6 @@ def phase_binaryen(target, options, wasm_target):
23652365 write_file (final_js , js )
23662366
23672367
2368- def node_es6_imports ():
2369- if not settings .EXPORT_ES6 or not settings .ENVIRONMENT_MAY_BE_NODE :
2370- return ''
2371-
2372- # Multi-environment builds uses `await import` in `shell.js`
2373- if settings .ENVIRONMENT_MAY_BE_WEB :
2374- return ''
2375-
2376- # Use static import declaration if we only target Node.js
2377- return '''
2378- import { createRequire } from 'module';
2379- const require = createRequire(import.meta.url);
2380- '''
2381-
2382-
23832368def node_pthread_detection ():
23842369 # Under node we detect that we are running in a pthread by checking the
23852370 # workerData property.
@@ -2394,11 +2379,10 @@ def modularize():
23942379 logger .debug (f'Modularizing, assigning to var { settings .EXPORT_NAME } ' )
23952380 src = read_file (final_js )
23962381
2397- # Multi-environment ES6 builds require an async function
2382+ # When targetting node and ES6 we use `await import ..` in the generated code
2383+ # so the outer function needs to be marked as async.
23982384 async_emit = ''
2399- if settings .EXPORT_ES6 and \
2400- settings .ENVIRONMENT_MAY_BE_NODE and \
2401- settings .ENVIRONMENT_MAY_BE_WEB :
2385+ if settings .EXPORT_ES6 and settings .ENVIRONMENT_MAY_BE_NODE :
24022386 async_emit = 'async '
24032387
24042388 # TODO: Remove when https://bugs.webkit.org/show_bug.cgi?id=223533 is resolved.
@@ -2449,25 +2433,23 @@ def modularize():
24492433 if settings .ENVIRONMENT_MAY_BE_NODE :
24502434 script_url_node = "if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;"
24512435 if settings .MODULARIZE == 'instance' :
2452- src = '''%(node_imports)s
2436+ src = '''\
24532437 var _scriptName = %(script_url)s;
24542438 %(script_url_node)s
24552439 %(src)s
24562440''' % {
2457- 'node_imports' : node_es6_imports (),
24582441 'script_url' : script_url ,
24592442 'script_url_node' : script_url_node ,
24602443 'src' : src ,
24612444 }
24622445 else :
2463- src = '''%(node_imports)s
2446+ src = '''\
24642447 var %(EXPORT_NAME)s = (() => {
24652448 var _scriptName = %(script_url)s;
24662449 %(script_url_node)s
24672450 return (%(src)s);
24682451})();
24692452''' % {
2470- 'node_imports' : node_es6_imports (),
24712453 'EXPORT_NAME' : settings .EXPORT_NAME ,
24722454 'script_url' : script_url ,
24732455 'script_url_node' : script_url_node ,
0 commit comments