Skip to content

Commit

Permalink
fix(migrations): count used dependencies inside existing control flow (
Browse files Browse the repository at this point in the history
…#59861)

Fixes that the control flow migration wasn't checking the content of pre-existing control flow nodes for dependencies.

Fixes #59846.

PR Close #59861
  • Loading branch information
crisbeto authored and atscott committed Feb 12, 2025
1 parent 9366e84 commit 46f36a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export class CommonCollector extends RecursiveVisitor {
this.count++;
}
}
super.visitBlock(ast, null);
}

override visitText(ast: Text) {
Expand Down
33 changes: 33 additions & 0 deletions packages/core/schematics/test/control_flow_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6479,6 +6479,39 @@ describe('control flow migration', () => {

expect(actual).toBe(expected);
});

it('should not remove common module if symbols are used inside new control flow', async () => {
writeFile(
'/comp.ts',
[
`import {CommonModule} from '@angular/common';`,
`import {Component} from '@angular/core';\n`,
`@Component({`,
` imports: [CommonModule],`,
` template: \`@if (toggle) {<div>{{ d | date }}</div>} <span *ngIf="toggle">hi</span>\``,
`})`,
`class Comp {`,
` toggle = false;`,
`}`,
].join('\n'),
);

await runMigration();
const actual = tree.readContent('/comp.ts');
const expected = [
`import {CommonModule} from '@angular/common';`,
`import {Component} from '@angular/core';\n`,
`@Component({`,
` imports: [CommonModule],`,
` template: \`@if (toggle) {<div>{{ d | date }}</div>} @if (toggle) {<span>hi</span>}\``,
`})`,
`class Comp {`,
` toggle = false;`,
`}`,
].join('\n');

expect(actual).toBe(expected);
});
});

describe('no migration needed', () => {
Expand Down

0 comments on commit 46f36a5

Please sign in to comment.