Skip to content

Commit

Permalink
Fix transform of delete a?.b in function params
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 3, 2023
1 parent 8f576af commit 6b36e3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export function transformOptionalChain(
// Replace `function (a, x = a.b?.c) {}` to `function (a, x = (() => a.b?.c)() ){}`
// so the temporary variable can be injected in correct scope
if (scope.path.isPattern() && needsMemoize(path)) {
path.replaceWith(template.ast`(() => ${path.node})()` as t.Statement);
replacementPath.replaceWith(
template.expression.ast`(() => ${replacementPath.node})()`,
);
// The injected optional chain will be queued and eventually transformed when visited
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function f(x = delete a()?.b) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function f(x = (() => {
var _a;
return (_a = a()) === null || _a === void 0 ? true : delete _a.b;
})()) {}

0 comments on commit 6b36e3c

Please sign in to comment.