diff --git a/packages/babel-traverse/src/path/modification.ts b/packages/babel-traverse/src/path/modification.ts index 3b0ffff60213..88ffe614f610 100644 --- a/packages/babel-traverse/src/path/modification.ts +++ b/packages/babel-traverse/src/path/modification.ts @@ -132,13 +132,12 @@ export function insertAfter( let { scope } = this; if (scope.path.isPattern()) { + t.assertExpression(node); + this.replaceWith( - t.callExpression( - t.arrowFunctionExpression([], this.node as t.Expression), - [], - ), + t.callExpression(t.arrowFunctionExpression([], node), []), ); - (this.get("callee.body") as NodePath).insertAfter(nodes); + (this.get("callee.body") as NodePath).insertAfter(nodes); return [this]; }