Skip to content

Control flow schematic: empty ngSwitchDefault is not migrated #53235

@mattlewis92

Description

@mattlewis92

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

core

Is this a regression?

No

Description

Input:

<ng-container [ngSwitch]="type">
  <ng-container *ngSwitchCase="'foo'"> Foo </ng-container>
  <ng-container *ngSwitchCase="'bar'"> Bar </ng-container>
  <ng-container *ngSwitchDefault></ng-container>
</ng-container>

Output:

@switch (type) {
  @case ('foo') {
    Foo
  }
  @case ('bar') {
    Bar
  }
  <ng-container *ngSwitchDefault></ng-container>
}

I guess the <ng-container *ngSwitchDefault></ng-container> should just be omitted or an empty @default {} block is created.

A warning is printed to the console when migrating which I guess is the root cause of this:

*ngSwitchDefault: TypeError: Cannot read properties of undefined (reading 'sourceSpan')

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

The angular compiler then emits this error when trying to AoT compile the converted code:

error NG5002: @switch block can only contain @case and @default blocks

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

Angular CLI: 17.0.3
Node: 20.9.0
Package Manager: pnpm 8.11.0
OS: darwin arm64

Angular: 17.1.0-next.1+sha-f1b7d40
... core

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1700.1
@angular-devkit/build-angular       17.0.3
@angular-devkit/core                17.0.3
@angular-devkit/schematics          17.0.3
@angular/animations                 17.0.4
@angular/cdk                        17.0.1
@angular/cli                        17.0.3
@angular/common                     17.0.4
@angular/compiler                   17.0.4
@angular/compiler-cli               17.0.4
@angular/elements                   17.0.4
@angular/forms                      17.0.4
@angular/google-maps                15.2.9
@angular/language-service           17.0.4
@angular/localize                   17.0.4
@angular/platform-browser           17.0.4
@angular/platform-browser-dynamic   17.0.4
@angular/router                     17.0.4
@angular/service-worker             17.0.4
@schematics/angular                 17.0.3
ng-packagr                          17.0.2
rxjs                                7.8.0
typescript                          5.2.2
webpack                             5.88.2
zone.js                             0.14.2

Anything else?

Noting that I have installed the latest dev build against the main branch via "@angular/core": "angular/core-builds#17.1.0-next.1+f1b7d40", to get the latest fixes

Metadata

Metadata

Assignees

Labels

area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)state: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions