Skip to content

Control flow migration: ternary in ngIf condition not migrated correctly #53384

Closed

Description

@mattlewis92

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

core

Is this a regression?

No

Description

Input:

<div *ngIf="!vm.isEmpty; else vm.loading ? loader : empty"></div>

<ng-template #loader>Loading</ng-template>
<ng-template #empty>Empty</ng-template>

Output:

@if (!vm.isEmpty) {
  <div></div>
} @else {
  #vm.loading ? loader  empty|
}
<ng-template #loader>Loading</ng-template>
<ng-template #empty>Empty</ng-template>

Expected output:

@if (!vm.isEmpty) {
  <div></div>
} @else if (vm.loading) {
  Loading
} else {
  Empty
}

Or for something a bit more generic that would handle other types of conditions beyond ternaries:

@if (!vm.isEmpty) {
  <div></div>
} @else {
  <ng-template [ngTemplateOutput]="vm.loading ? loader : empty"></ng-template>
}
<ng-template #loader>Loading</ng-template>
<ng-template #empty>Empty</ng-template>

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

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

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

Angular: 17.0.5+sha-7c863d7
... core

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

Anything else?

This is using the latest build of angular from the main branch via "@angular/core": "angular/core-builds#17.0.5+7c863d7"

Activity

  1. added
    area: migrations
    core: control flow
    on Dec 6, 2023
  2. added this to the needsTriage milestone on Dec 6, 2023
  3. self-assigned this
    on Dec 6, 2023
  4. jessicajaniuk commented on Dec 6, 2023

    @jessicajaniuk
    Contributor

    The last 3 bugs you've reported are difficult ones as the migration does not expect a condition there. I don't know that we'll be able to handle those cases since that involves parsing out JS code. We'll discuss.

  5. mattlewis92 commented on Dec 6, 2023

    @mattlewis92
    ContributorAuthor

    The last 3 bugs you've reported are difficult ones as the migration does not expect a condition there. I don't know that we'll be able to handle those cases since that involves parsing out JS code. We'll discuss.

    Sure no problem! Even if it just prints a warning instead of creating invalid code that would be fine.

  6. jessicajaniuk commented on Dec 6, 2023

    @jessicajaniuk
    Contributor

    I think I have a solution here, but it would definitely be your latter suggestion.

  7. added a commit that references this issue on Dec 6, 2023
    e2ccdaf
  8. jessicajaniuk commented on Dec 6, 2023

    @jessicajaniuk
    Contributor

    Fix is in #53394. This actually fixes all three of these issues.

  9. added a commit that references this issue on Dec 6, 2023
    836aeba
  10. angular-automatic-lock-bot commented on Jan 6, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Jan 6, 2024
  12. added a commit that references this issue on Jan 23, 2024
    e2aed2e
  13. added a commit that references this issue on Jan 26, 2024
    8e0fb99
  14. added a commit that references this issue on Jan 26, 2024
    d9505c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: migrationscore: control flow

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions