Skip to content

Standalone migration doesn't detect shorthand declarations in NgModules #62787

@tomer953

Description

@tomer953

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

The standalone migration fails to detect components declared using a shorthand property in the @NgModule metadata. As a result, such components are not migrated to standalone.

Reproduction:

const declarations = [BuzzComponent, FizzComponent];

@NgModule({
  declarations,
  imports: [BarComponent, FooComponent],
  exports: [BarComponent, BuzzComponent, FizzComponent, FooComponent],
})
export class SharedModule {}

Expected Behavior:

BuzzComponent + FizzComponent should be migrated to standalone.

Actual Behavior:
They are ignored, and the migration does not touch them.

Cause:

The migration script only handles PropertyAssignment nodes:

https://github.com/angular/angular/blob/main/packages/core/schematics/ng-generate/standalone-migration/to-standalone.ts#L309

if (ts.isPropertyAssignment(declarationsProp)) {
  if (ts.isArrayLiteralExpression(declarationsProp.initializer)) {
    // ...
  }
}

Suggested Fix:
Update the check to also handle ShorthandPropertyAssignment:

if (
  ts.isPropertyAssignment(declarationsProp) ||
  ts.isShorthandPropertyAssignment(declarationsProp)
) {
  // Handle both regular and shorthand property assignments
}

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-adxywkeg?file=src%2Fmodules%2Fshared.module.ts

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 20.0.0
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64

Angular: 20.0.0
... animations, 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.2
zone.js                      0.15.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: migrationsIssues related to `ng update`/`ng generate` migrationshelp wantedAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions