Fix live debugger curried function instrumentation by watson · Pull Request #441 · DataDog/build-plugins · GitHub
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

@watson watson commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What and why?

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

const make = (dep) => function named() {
    return dep;
};

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:

const make = (dep) => {
    const $dd_p0 = $dd_probes('src/utils.ts;make');
    try {
        if ($dd_p0) $dd_entry($dd_p0, this, {dep});
        const $dd_rv0 = function named() {
            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}); throw e; }
};

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.

watson commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 29, 2026

Copy link
Copy Markdown

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.
@watson watson force-pushed the watson/fix-nested-functions branch from 503521e to e5064e7 Compare July 1, 2026 13:03
@watson watson force-pushed the watson/DEBUG-5793/fix-safari branch from 01561a1 to 937be82 Compare July 1, 2026 13:03
Sign up for free to 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