From 937055ce020d51d14084b32340ee04ecf12a23cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 3 Aug 2022 10:07:59 -0400 Subject: [PATCH] fix: helper-wrap-function compat with traverse --- packages/babel-helper-wrap-function/src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-wrap-function/src/index.ts b/packages/babel-helper-wrap-function/src/index.ts index 744e238457bd..71dc174006b4 100644 --- a/packages/babel-helper-wrap-function/src/index.ts +++ b/packages/babel-helper-wrap-function/src/index.ts @@ -97,7 +97,12 @@ function plainFunction( let functionId = null; let node; if (path.isArrowFunctionExpression()) { - path = path.arrowFunctionToExpression({ noNewArrows }); + if (process.env.BABEL_8_BREAKING) { + path = path.arrowFunctionToExpression({ noNewArrows }); + } else { + // arrowFunctionToExpression returns undefined in @babel/traverse < 7.18.10 + path = path.arrowFunctionToExpression({ noNewArrows }) ?? path; + } node = path.node as t.FunctionDeclaration | t.FunctionExpression; } else { node = path.node as t.FunctionDeclaration | t.FunctionExpression;