@@ -2325,15 +2325,23 @@ def modularize():
2325
2325
if async_emit != '' and settings .EXPORT_NAME == 'config' :
2326
2326
diagnostics .warning ('emcc' , 'EXPORT_NAME should not be named "config" when targeting Safari' )
2327
2327
2328
+ src = '''
2329
+ %(maybe_async)sfunction(moduleArg = {}) {
2330
+
2331
+ %(src)s
2332
+
2333
+ return %(return_value)s
2334
+ }
2335
+ ''' % {
2336
+ 'maybe_async' : async_emit ,
2337
+ 'src' : src ,
2338
+ 'return_value' : return_value ,
2339
+ }
2340
+
2328
2341
if settings .MINIMAL_RUNTIME and not settings .PTHREADS :
2329
2342
# Single threaded MINIMAL_RUNTIME programs do not need access to
2330
2343
# document.currentScript, so a simple export declaration is enough.
2331
- src = f'''\
2332
- var { settings .EXPORT_NAME } = { async_emit } (moduleArg = {{}}) => {{
2333
- { src }
2334
- return { return_value } ;
2335
- }};
2336
- '''
2344
+ src = '/** @nocollapse */ var %s = %s' % (settings .EXPORT_NAME , src )
2337
2345
else :
2338
2346
script_url_node = ''
2339
2347
# When MODULARIZE this JS may be executed later,
@@ -2347,14 +2355,19 @@ def modularize():
2347
2355
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
2348
2356
if shared .target_environment_may_be ('node' ):
2349
2357
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir ||= __filename;"
2350
- src = f'''{ node_es6_imports ()}
2351
- var { settings .EXPORT_NAME } = { async_emit } (moduleArg = {{}}) => {{
2352
- var _scriptDir = { script_url } ;
2353
- { script_url_node }
2354
- { src }
2355
- return { return_value } ;
2356
- }};
2357
- '''
2358
+ src = '''%(node_imports)s
2359
+ var %(EXPORT_NAME)s = (() => {
2360
+ var _scriptDir = %(script_url)s;
2361
+ %(script_url_node)s
2362
+ return (%(src)s);
2363
+ })();
2364
+ ''' % {
2365
+ 'node_imports' : node_es6_imports (),
2366
+ 'EXPORT_NAME' : settings .EXPORT_NAME ,
2367
+ 'script_url' : script_url ,
2368
+ 'script_url_node' : script_url_node ,
2369
+ 'src' : src ,
2370
+ }
2358
2371
# Given the async nature of how the Module function and Module object
2359
2372
# come into existence in AudioWorkletGlobalScope, store the Module
2360
2373
# function under a different variable name so that AudioWorkletGlobalScope
@@ -2365,14 +2378,14 @@ def modularize():
2365
2378
2366
2379
# Export using a UMD style export, or ES6 exports if selected
2367
2380
if settings .EXPORT_ES6 :
2368
- src += f 'export default { settings .EXPORT_NAME } ;'
2381
+ src += 'export default %s;' % settings .EXPORT_NAME
2369
2382
elif not settings .MINIMAL_RUNTIME :
2370
- src += f '''
2383
+ src += '''\
2371
2384
if (typeof exports === 'object' && typeof module === 'object')
2372
- module.exports = { settings . EXPORT_NAME } ;
2385
+ module.exports = %( EXPORT_NAME)s ;
2373
2386
else if (typeof define === 'function' && define['amd'])
2374
- define([], () => { settings . EXPORT_NAME } );
2375
- '''
2387
+ define([], () => %( EXPORT_NAME)s );
2388
+ ''' % { 'EXPORT_NAME' : settings . EXPORT_NAME }
2376
2389
2377
2390
final_js += '.modular.js'
2378
2391
write_file (final_js , src )
0 commit comments