From 72a4f28187be5f25a7d9f0d48506f06d1514ebe9 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 20 Jan 2024 10:38:43 +0100 Subject: [PATCH 1/3] Acorn optimizer: Allow top-level await expressions `-pthread` + `-sEXPORT_ES6` emits a top-level await expression in the main worker file after commit 49ab23a. Ensure the Acorn optimizer is aware of this. --- tools/acorn-optimizer.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/acorn-optimizer.mjs b/tools/acorn-optimizer.mjs index c62e29f066665..328282e1585fa 100755 --- a/tools/acorn-optimizer.mjs +++ b/tools/acorn-optimizer.mjs @@ -2029,6 +2029,7 @@ try { preserveParens: closureFriendly, onComment: closureFriendly ? sourceComments : undefined, sourceType: exportES6 ? 'module' : 'script', + allowAwaitOutsideFunction: exportES6, }); } catch (err) { err.message += (() => { From 8191423281151961b4fe8b521206a96214a2db9a Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 25 Jan 2024 13:27:54 +0100 Subject: [PATCH 2/3] Incorporate feedback --- tools/acorn-optimizer.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/acorn-optimizer.mjs b/tools/acorn-optimizer.mjs index 328282e1585fa..f877761d636eb 100755 --- a/tools/acorn-optimizer.mjs +++ b/tools/acorn-optimizer.mjs @@ -2029,7 +2029,7 @@ try { preserveParens: closureFriendly, onComment: closureFriendly ? sourceComments : undefined, sourceType: exportES6 ? 'module' : 'script', - allowAwaitOutsideFunction: exportES6, + allowAwaitOutsideFunction: true, }); } catch (err) { err.message += (() => { From 7c9773b3f3e19b5ac798ac45b7b0c620283d66a8 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 25 Jan 2024 13:49:34 +0100 Subject: [PATCH 3/3] Add test case --- test/test_other.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 9e6960aaf100c..80ff29d8e8a13 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -407,7 +407,8 @@ def test_export_es6_allows_export_in_post_js(self): @parameterized({ '': ([],), # load a worker before startup to check ES6 modules there as well - 'pthreads': (['-pthread', '-sPTHREAD_POOL_SIZE=1'],), + # pass -O2 to ensure the worker JS file is minified with Acorn + 'pthreads': (['-O2', '-pthread', '-sPTHREAD_POOL_SIZE=1'],), }) def test_export_es6(self, args, package_json): self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6',