Skip to content

[7.x backport] fix: avoid removable fields as decorator evaluation hosts - #18225

Merged
nicolo-ribaudo merged 3 commits into
babel:7.xfrom
nyan-left:fix/7.x-decorators-erased-field-host
Oct 25, 2026
Merged

nicolo-ribaudo merged 3 commits into
babel:7.xfrom
nyan-left:fix/7.x-decorators-erased-field-host

Conversation

@nyan-left

Copy link
Copy Markdown
Contributor
Q A
Fixed Issues? Fixes #18223
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link N/A
Any Dependency Changes? No
License MIT

Backport of #18224.

On Babel 7, the TypeScript transform can remove uninitialized fields when allowDeclareFields is false. If one of those fields hosts a memoized decorator assignment, the assignment is removed with it and the generated class throws TypeError: A decorator must be a function.

This skips removable fields when selecting a host and uses the existing temporary computed field when necessary, and this is obviously going to solve the problem without changing decorator evaluation order.

Regression tests cover stacked member-expression decorators, class decorator ordering, and declaration fields using Babel 7's TypeScript behavior.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! 🎉

We really appreciate you taking the time to contribute, @nyan-left.

A maintainer will take a look as soon as they can. In the meantime, please make sure that:

  • the description explains what changed and why
  • any related issues are linked
  • existing tests still pass

If anything needs adjusting we'll leave comments here. Thanks again!

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Insufficient data

Not enough activity yet to make a reliable assessment.

View full analysis →

This is an automated analysis by AgentScan

@babel-bot

babel-bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62306

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: a650f2d

@nicolo-ribaudo

nicolo-ribaudo commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Please read AI_POLICY.md

@nyan-left
nyan-left deleted the fix/7.x-decorators-erased-field-host branch September 30, 2026 14:27
@nyan-left
nyan-left restored the fix/7.x-decorators-erased-field-host branch October 6, 2026 10:46
@nyan-left

Copy link
Copy Markdown
Contributor Author

@nicolo-ribaudo

I've updated the tests to match the main PR, plus i/o tests. Kept field-order here since v7's TS preset strips untouched: string. The test changes were LLM-assisted and I've reviewed them. All three fail without the fix and pass with it.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: backport and removed AI policy violation labels Oct 6, 2026
@nicolo-ribaudo nicolo-ribaudo reopened this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x: backport PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants