Skip to content

Angular 20 build mangles class names #30420

Closed
@wein2011

Description

@wein2011

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

19.2.14

Description

The name of the class provided by a ClassDecoratorContext is mangled in 20.0.0.

Unfortunately, this renders the new stage 3 class decorators useless.

Minimal Reproduction

  1. Create an Angular sample application and add the following code to main.ts
export const setClassDef = () => (_target: unknown, context: ClassDecoratorContext) => {
  console.log(context.name);
};

@setClassDef()
export class MyClass {
}`
  1. In tsconfig.json, set experimentalDecorators to false. This will allow the use of the new stage 3 decorators.
  2. Install the packages
  3. Serve the application with npm run start
  4. Review the console output in the developer tools of the browser

I have attached a reproduction package:

code.zip

Exception or Error

When running with Angular 19.2.14, the output will show "MyClass2". This is the actual name of the class and a numeric suffix.

When running with Angular 20.0.0, the output will show "_a".

However, Angular 20.0.0 should also output "MyClass2".

Your Environment

Angular CLI: 20.0.0
Node: 22.16.0
Package Manager: npm 10.9.2
OS: win32 x64

Angular: 20.0.0
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.0
@angular-devkit/core         20.0.0
@angular-devkit/schematics   20.0.0
@schematics/angular          20.0.0
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.1

Anything else relevant?

This could be related to the Vite/esbuild configuration for 20.0.0. for keepNames.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions