From 60ee6e64355556962fddbdddd31d34e0310872b5 Mon Sep 17 00:00:00 2001 From: Laurent Christophe Date: Tue, 15 Feb 2022 17:10:07 +0100 Subject: [PATCH] feat: support top-level await in modules I thought this was turned on logn ago. But I forgot a flag in the parser as well as declaring the variable that holds the value being pass to await. --- components/instrumentation/default/index.mjs | 1 + components/instrumentation/default/visit.mjs | 6 ++++++ components/instrumentation/default/visit.test.mjs | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/instrumentation/default/index.mjs b/components/instrumentation/default/index.mjs index d92fb6910..300130f84 100644 --- a/components/instrumentation/default/index.mjs +++ b/components/instrumentation/default/index.mjs @@ -83,6 +83,7 @@ export default (dependencies) => { parseEstree(content, { allowHashBang: true, sourceType: type, + allowAwaitOutsideFunction: type === "module", ecmaVersion: configuration.language.version, locations: true, }), diff --git a/components/instrumentation/default/visit.mjs b/components/instrumentation/default/visit.mjs index d1795c5b1..00ad827d2 100644 --- a/components/instrumentation/default/visit.mjs +++ b/components/instrumentation/default/visit.mjs @@ -305,6 +305,12 @@ export default (dependencies) => { type: "Program", sourceType: type, body: [ + makeVariableDeclaration("let", [ + makeVariableDeclarator( + makeIdentifier(`${runtime}_JUMP`), + makeLiteral(null), + ), + ]), makeVariableDeclaration("let", [ makeVariableDeclarator( makeIdentifier(`${runtime}_JUMP_ID`), diff --git a/components/instrumentation/default/visit.test.mjs b/components/instrumentation/default/visit.test.mjs index da08694d6..0fe022f56 100644 --- a/components/instrumentation/default/visit.test.mjs +++ b/components/instrumentation/default/visit.test.mjs @@ -218,7 +218,8 @@ assertEqual( ), normalize( ` - let $_JUMP_ID = null + let $_JUMP = null; + let $_JUMP_ID = null; try { } catch ($_ERROR) { if ($_JUMP_ID !== null) { $.recordAfterJump($_JUMP_ID);