Skip to content

Conversation

rbuckton
Copy link
Contributor

Fixes a crash when transforming Stage 3 decorators when both class element decorators and class constructor parameter decorators are present.

Fixes #58269

@rbuckton rbuckton requested a review from jakebailey October 14, 2024 20:28
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 14, 2024
export function getAllDecoratorsOfClass(node: ClassLikeDeclaration, useLegacyDecorators: boolean): AllDecorators | undefined {
const decorators = getDecorators(node);
const parameters = getDecoratorsOfParameters(getFirstConstructorWithBody(node));
const parameters = useLegacyDecorators ? getDecoratorsOfParameters(getFirstConstructorWithBody(node)) : undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should getDecoratorsOfParameters take the parameter and return undefined instead of copying the ternary to all call sites?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branching is cheaper at runtime than invocation, so probably not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit overoptimized but alright.

Copy link
Contributor Author

@rbuckton rbuckton Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case specifically, just passing the argument to getDecoratorsOfParameters means iterating over all class elements to find a constructor, which is unnecessary work.

@rbuckton rbuckton merged commit 40caf34 into main Oct 14, 2024
32 checks passed
@rbuckton rbuckton deleted the fix58269 branch October 14, 2024 21:45
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debug Failure in transformClassLike in "ghost" after #56955
3 participants