Skip to content

Fix live debugger curried function instrumentation - #441

Draft
watson wants to merge 1 commit into
watson/DEBUG-5793/fix-safarifrom
watson/fix-nested-functions
Draft

Fix live debugger curried function instrumentation#441
watson wants to merge 1 commit into
watson/DEBUG-5793/fix-safarifrom
watson/fix-nested-functions

Conversation

@watson

Copy link
Copy Markdown
Contributor

What and why?

Fixes a Live Debugger transform bug where curried functions like this could emit invalid JavaScript:

constmake=(dep)=>functionnamed(){returndep;};

Before this fix, the outer arrow instrumentation could overwrite the inner function's closing-brace instrumentation. The generated output effectively looked like this, with the inner try missing its catch/finally:

constmake=(dep)=>{const$dd_p0=$dd_probes('src/utils.ts;make');try{if($dd_p0)$dd_entry($dd_p0,this,{dep});const$dd_rv0=functionnamed(){const$dd_p1=$dd_probes('src/utils.ts;named');try{let$dd_rv1;if($dd_p1)$dd_entry($dd_p1,this);return($dd_rv1=dep,$dd_p1 ? $dd_return($dd_p1,$dd_rv1,this) : $dd_rv1);};if($dd_p0)$dd_return($dd_p0,$dd_rv0,this,{dep});return$dd_rv0;}catch(e){if($dd_p0)$dd_throw($dd_p0,e,this,{dep});throwe;}};

That invalid output fails downstream parsers with errors like Missing catch or finally clause or Expected a semicolon.

How?

The expression-body path now updates the first body character as before, but appends the suffix at bodyEnd instead of rewriting [bodyEnd - 1, bodyEnd]. This keeps the inner block-body postamble intact when the arrow body is another function or arrow.

Added table-driven nested-function regression coverage for named function expressions, exported function-expression factories, triple-nested callback shapes, and curried arrows across namedOnly modes.

@watsonGraphite App

watson commented Jun 29, 2026

Copy link
Copy Markdown
ContributorAuthor

@datadog-datadog-prod-us1

datadog-datadog-prod-us1Bot commented Jun 29, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e5064e7 | Docs | Datadog PR Page | Give us feedback!

Arrow expression-body instrumentation rewrote the body's final character to add the outer
suffix. When the expression body was itself a function or arrow, that character could
also be the inner function's closing brace, so the outer write dropped the inner catch
block and produced invalid JavaScript.
Append the outer suffix after the expression body instead, preserving the inner function
postamble. Add nested and curried regression cases that re-parse transformed output
under both namedOnly modes.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@watson