Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrations): CF Migration fix missing alias for bound ngifs #53296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function migrateNgIf(etm: ElementToMigrate, tmpl: string, offset: number): Resul
function buildIfBlock(etm: ElementToMigrate, tmpl: string, offset: number): Result {
const aliasAttrs = etm.aliasAttrs!;
const aliases = [...aliasAttrs.aliases.keys()];
if (aliasAttrs.item) {
aliases.push(aliasAttrs.item);
}

// includes the mandatory semicolon before as
const lbString = etm.hasLineBreaks ? '\n' : '';
Expand Down Expand Up @@ -133,6 +136,9 @@ function buildStandardIfElseBlock(
function buildBoundIfElseBlock(etm: ElementToMigrate, tmpl: string, offset: number): Result {
const aliasAttrs = etm.aliasAttrs!;
const aliases = [...aliasAttrs.aliases.keys()];
if (aliasAttrs.item) {
aliases.push(aliasAttrs.item);
}

// includes the mandatory semicolon before as
let condition = etm.attr.value.replace(' as ', '; as ');
Expand Down
29 changes: 29 additions & 0 deletions packages/core/schematics/test/control_flow_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,35 @@ describe('control flow migration', () => {
].join('\n'));
});

it('should migrate an if case as a binding with let variable with no value', async () => {
writeFile('/comp.ts', `
import {Component} from '@angular/core';
import {NgIf} from '@angular/common';

@Component({
templateUrl: './comp.html'
})
class Comp {
show = false;
}
`);

writeFile('/comp.html', [
`<ng-template [ngIf]="viewModel$ | async" let-vm>`,
` {{vm | json}}`,
`</ng-template>`,
].join('\n'));

await runMigration();
const content = tree.readContent('/comp.html');

expect(content).toBe([
`@if (viewModel$ | async; as vm) {`,
` {{vm | json}}`,
`}`,
].join('\n'));
});

it('should migrate an if else case as bindings', async () => {
writeFile('/comp.ts', `
import {Component} from '@angular/core';
Expand Down