Fix nested paren arrow bodies in Live Debugger by watson · Pull Request #405 · DataDog/build-plugins · GitHub
Skip to content

Fix nested paren arrow bodies in Live Debugger#405

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
watson/fix-parenteses
Jun 10, 2026
Merged

Fix nested paren arrow bodies in Live Debugger#405
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
watson/fix-parenteses

Conversation

@watson

@watson watson commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What and why?

Fix Live Debugger instrumentation for arrow expression bodies wrapped in multiple parentheses. Babel exposes the unwrapped expression range for these bodies, so the previous paren-stripping logic could leave wrapper parens around the injected block and generate invalid JavaScript.

Input examples that now transform correctly:

const getNumber = () => ((1));
const getObject = () => (({a: 1}));

Before this fix, const getNumber = () => ((1)); could be transformed into invalid syntax shaped like this:

const getNumber = () => ({
const $dd_p0 = $dd_probes('src/utils.ts;getNumber');
try {
  const $dd_rv0 = 1;
  return $dd_rv0;
} catch(e) {
  throw e;
}
});

The injected block was left inside a parenthesized expression, so the first const caused a syntax error.

After this fix, the same input is still instrumented and produces a valid block-bodied arrow function shaped like this:

const getNumber = () => {
const $dd_p0 = $dd_probes('src/utils.ts;getNumber');
try {
  const $dd_rv0 = 1;
  if ($dd_p0) $dd_return($dd_p0, $dd_rv0, this);
  return $dd_rv0;
} catch(e) {
  if ($dd_p0) $dd_throw($dd_p0, e, this);
  throw e;
}
};

Single-wrapper cases such as () => (1) and () => ({a: 1}) already worked and continue to work.

How?

Remove every wrapper paren found between Babel's recorded arrow body range and the containing arrow function end before injecting the block body. Added regression tests covering nested parenthesized scalar and object expression bodies, and verified with yarn test:unit packages/plugins/live-debugger/src/transform/index.test.ts.

Live Debugger converts arrow expression bodies into block bodies before
injecting capture logic.

Babel reports nested parenthesized bodies like `() => ((1))` as the
inner expression range. Remove all wrapper parens around that range so
the injected block body remains syntactically valid.

Add regression coverage for scalar and object expression bodies wrapped
in nested parentheses.
@watson watson requested review from a team and yoannmoinet as code owners June 10, 2026 19:52

watson commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@watson

watson commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jun 10, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants