Skip to content

Commit 46f36a5

Browse files
crisbetoatscott
authored andcommittedFeb 12, 2025
fix(migrations): count used dependencies inside existing control flow (#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
1 parent 9366e84 commit 46f36a5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎packages/core/schematics/ng-generate/control-flow-migration/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export class CommonCollector extends RecursiveVisitor {
390390
this.count++;
391391
}
392392
}
393+
super.visitBlock(ast, null);
393394
}
394395

395396
override visitText(ast: Text) {

‎packages/core/schematics/test/control_flow_migration_spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -6479,6 +6479,39 @@ describe('control flow migration', () => {
64796479

64806480
expect(actual).toBe(expected);
64816481
});
6482+
6483+
it('should not remove common module if symbols are used inside new control flow', async () => {
6484+
writeFile(
6485+
'/comp.ts',
6486+
[
6487+
`import {CommonModule} from '@angular/common';`,
6488+
`import {Component} from '@angular/core';\n`,
6489+
`@Component({`,
6490+
` imports: [CommonModule],`,
6491+
` template: \`@if (toggle) {<div>{{ d | date }}</div>} <span *ngIf="toggle">hi</span>\``,
6492+
`})`,
6493+
`class Comp {`,
6494+
` toggle = false;`,
6495+
`}`,
6496+
].join('\n'),
6497+
);
6498+
6499+
await runMigration();
6500+
const actual = tree.readContent('/comp.ts');
6501+
const expected = [
6502+
`import {CommonModule} from '@angular/common';`,
6503+
`import {Component} from '@angular/core';\n`,
6504+
`@Component({`,
6505+
` imports: [CommonModule],`,
6506+
` template: \`@if (toggle) {<div>{{ d | date }}</div>} @if (toggle) {<span>hi</span>}\``,
6507+
`})`,
6508+
`class Comp {`,
6509+
` toggle = false;`,
6510+
`}`,
6511+
].join('\n');
6512+
6513+
expect(actual).toBe(expected);
6514+
});
64826515
});
64836516

64846517
describe('no migration needed', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.