mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(migrations): account for let declarations in control flow migration (#59861)
Fixes that the control flow migration wasn't accounting for `@let` when determining which symbols are used. PR Close #59861
This commit is contained in:
committed by
Andrew Scott
parent
1119f85ca9
commit
aa285c548c
@@ -10,6 +10,7 @@ import {
|
||||
Attribute,
|
||||
Block,
|
||||
Element,
|
||||
LetDeclaration,
|
||||
ParseTreeResult,
|
||||
RecursiveVisitor,
|
||||
Text,
|
||||
@@ -399,6 +400,13 @@ export class CommonCollector extends RecursiveVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
override visitLetDeclaration(decl: LetDeclaration): void {
|
||||
if (this.hasPipes(decl.value)) {
|
||||
this.count++;
|
||||
}
|
||||
super.visitLetDeclaration(decl, null);
|
||||
}
|
||||
|
||||
private hasDirectives(input: string): boolean {
|
||||
return commonModuleDirectives.has(input);
|
||||
}
|
||||
|
||||
@@ -6512,6 +6512,39 @@ describe('control flow migration', () => {
|
||||
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
|
||||
it('should not remove common module if symbols are used inside @let', async () => {
|
||||
writeFile(
|
||||
'/comp.ts',
|
||||
[
|
||||
`import {CommonModule} from '@angular/common';`,
|
||||
`import {Component} from '@angular/core';\n`,
|
||||
`@Component({`,
|
||||
` imports: [CommonModule],`,
|
||||
` template: \`@let foo = 123 | date; <span *ngIf="foo">{{foo}}</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: \`@let foo = 123 | date; @if (foo) {<span>{{foo}}</span>}\``,
|
||||
`})`,
|
||||
`class Comp {`,
|
||||
` toggle = false;`,
|
||||
`}`,
|
||||
].join('\n');
|
||||
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('no migration needed', () => {
|
||||
|
||||
Reference in New Issue
Block a user