File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
ng-generate/control-flow-migration Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
Attribute ,
11
11
Block ,
12
12
Element ,
13
+ LetDeclaration ,
13
14
ParseTreeResult ,
14
15
RecursiveVisitor ,
15
16
Text ,
@@ -399,6 +400,13 @@ export class CommonCollector extends RecursiveVisitor {
399
400
}
400
401
}
401
402
403
+ override visitLetDeclaration ( decl : LetDeclaration ) : void {
404
+ if ( this . hasPipes ( decl . value ) ) {
405
+ this . count ++ ;
406
+ }
407
+ super . visitLetDeclaration ( decl , null ) ;
408
+ }
409
+
402
410
private hasDirectives ( input : string ) : boolean {
403
411
return commonModuleDirectives . has ( input ) ;
404
412
}
Original file line number Diff line number Diff line change @@ -6512,6 +6512,39 @@ describe('control flow migration', () => {
6512
6512
6513
6513
expect ( actual ) . toBe ( expected ) ;
6514
6514
} ) ;
6515
+
6516
+ it ( 'should not remove common module if symbols are used inside @let' , async ( ) => {
6517
+ writeFile (
6518
+ '/comp.ts' ,
6519
+ [
6520
+ `import {CommonModule} from '@angular/common';` ,
6521
+ `import {Component} from '@angular/core';\n` ,
6522
+ `@Component({` ,
6523
+ ` imports: [CommonModule],` ,
6524
+ ` template: \`@let foo = 123 | date; <span *ngIf="foo">{{foo}}</span>\`` ,
6525
+ `})` ,
6526
+ `class Comp {` ,
6527
+ ` toggle = false;` ,
6528
+ `}` ,
6529
+ ] . join ( '\n' ) ,
6530
+ ) ;
6531
+
6532
+ await runMigration ( ) ;
6533
+ const actual = tree . readContent ( '/comp.ts' ) ;
6534
+ const expected = [
6535
+ `import {CommonModule} from '@angular/common';` ,
6536
+ `import {Component} from '@angular/core';\n` ,
6537
+ `@Component({` ,
6538
+ ` imports: [CommonModule],` ,
6539
+ ` template: \`@let foo = 123 | date; @if (foo) {<span>{{foo}}</span>}\`` ,
6540
+ `})` ,
6541
+ `class Comp {` ,
6542
+ ` toggle = false;` ,
6543
+ `}` ,
6544
+ ] . join ( '\n' ) ;
6545
+
6546
+ expect ( actual ) . toBe ( expected ) ;
6547
+ } ) ;
6515
6548
} ) ;
6516
6549
6517
6550
describe ( 'no migration needed' , ( ) => {
You can’t perform that action at this time.
0 commit comments