fix heuristic for transforming await expressions on server

async-abort-signal
Rich Harris 7 months ago
parent bcdddc6efb
commit 2703ac6096

@ -7,7 +7,17 @@ import * as b from '../../../../utils/builders.js';
* @param {Context} context
*/
export function AwaitExpression(node, context) {
if (context.state.scope.function_depth > 1) {
// if `await` is inside a function, or inside `<script module>`,
// allow it, otherwise error
if (
context.state.scope.function_depth === 0 ||
context.path.some(
(node) =>
node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression'
)
) {
return context.next();
}

Loading…
Cancel
Save