From ddd617646efec4b672c78e6e878eb2210fbd65ce Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 25 Jan 2024 19:14:47 +0100 Subject: [PATCH] Acorn optimizer: Allow top-level await expressions (#21117) `-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. --- test/test_other.py | 3 ++- tools/acorn-optimizer.mjs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 4dabc8ecb352..79098a8b0306 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', diff --git a/tools/acorn-optimizer.mjs b/tools/acorn-optimizer.mjs index c62e29f06666..f877761d636e 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: true, }); } catch (err) { err.message += (() => {