Skip to content

Fix panic on anonymous class declaration with decorator targeting ES2022#3926

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-anonymous-class-decorator-issue
Draft

Fix panic on anonymous class declaration with decorator targeting ES2022#3926
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-anonymous-class-decorator-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

visitClassDeclaration in the ES decorator transformer assumed all non-export default class declarations have names, hitting a debug assertion panic for anonymous decorated classes like:

class {
  @x
  m() {}
};
  • Added a branch for unnamed non-export default class declarations that emits the transformed IIFE as an expression statement ((() => { ... })();) rather than attempting a variable binding
  • Added compiler test case anonymousClassDecoratorEs2022.ts

…ng ES2022

Handle the case where an anonymous class declaration (not export default) has
decorators. Instead of asserting that a name must exist, emit the IIFE as an
expression statement.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/a8b3bbaf-a8f1-4207-973a-1001c1b3537d

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsgo panic with anonymous class declaration and member decorator Fix panic on anonymous class declaration with decorator targeting ES2022 May 16, 2026
Copilot AI requested a review from jakebailey May 16, 2026 20:13
Comment on lines -1066 to -1067
} else {
debug.Assert(classNode.Name() != nil, "A class declaration that is not a default export must have a name.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot The original code said:

Debug.assertIsDefined(node.name, "A class declaration that is not a default export must have a name.");

Removing an assert that the old code does not make sense unless you can prove that the old compiler also crashes on this input

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.

tsgo panics when an anonymous class declaration has a member decorator when downleveling to ES2022

2 participants