Skip to content

Add decorator support to Live Debugger instrumentation#448

Draft
watson wants to merge 1 commit into
watson/more-fixesfrom
watson/support-decorators
Draft

Add decorator support to Live Debugger instrumentation#448
watson wants to merge 1 commit into
watson/more-fixesfrom
watson/support-decorators

Conversation

@watson

@watson watson commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What and why?

The Live Debugger transform parsed every file with only Babel's jsx and typescript plugins. Any file using decorators — Angular, NestJS, TypeORM, MobX, and similar frameworks — therefore failed to parse and was silently skipped (returned uninstrumented, though never miscompiled). Because decorator-heavy stacks can make up a large share of a codebase, Live Debugger could end up with little to no visibility into them. This enables decorator parsing so those files are instrumented, with an option to select which decorator grammar to accept.

How?

Adds a decorators option ('legacy' | 'modern', default 'legacy'), because Babel cannot enable the two decorator proposals in a single parse pass. legacy maps to the decorators-legacy plugin (TypeScript's experimentalDecorators semantics, including the parameter decorators used heavily in dependency injection) and is the right default for the vast majority of real-world code; modern maps to decorators + decoratorAutoAccessors (TC39 Stage 3, including accessor fields and decorators before export). A file written in the non-selected style still fails safe — it is skipped, never miscompiled.

The option is validated and defaulted in validate.ts, threaded through the plugin handler into transformCode, and applied by a new getParserPlugins helper that builds the Babel plugin list; the parser plugin list is now typed as ParserPlugin[] rather than string[]. Tests cover validation (default value, both accepted values, rejection of invalid input) and the transform itself (legacy decorators with parameter decorators instrument by default, Stage 3 decorators instrument under modern, and the two grammars are confirmed mutually exclusive). The README documents the option and its table of contents was regenerated with yarn cli integrity. Defaulting to legacy adds no measurable parse overhead for decorator-free files, verified by benchmarking parse timings with and without the plugin.

The transform parsed sources with only the `jsx` and `typescript` Babel plugins, so any file using
decorators (Angular, NestJS, TypeORM, MobX, ...) failed to parse and was skipped entirely, leaving
its functions uninstrumented.

Enable decorator parsing and expose a `decorators` option to pick the grammar, since Babel cannot
enable both decorator proposals at once:

- `legacy` (default): TypeScript `experimentalDecorators` semantics, including parameter decorators.
  This covers the overwhelming majority of real-world decorator usage.
- `modern`: the TC39 Stage 3 proposal, including `accessor` fields and decorators before `export`.

A file written in the non-selected style still fails safe -- it is skipped, never miscompiled.
Defaulting to `legacy` adds no measurable parse overhead for codebases without decorators.

Add validation and defaulting for the option, thread it through to the parser, and cover both
modes with tests. Update the README and regenerate its table of contents.

watson commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

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