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 {
1010 Attribute ,
1111 Block ,
1212 Element ,
13+ LetDeclaration ,
1314 ParseTreeResult ,
1415 RecursiveVisitor ,
1516 Text ,
@@ -399,6 +400,13 @@ export class CommonCollector extends RecursiveVisitor {
399400 }
400401 }
401402
403+ override visitLetDeclaration ( decl : LetDeclaration ) : void {
404+ if ( this . hasPipes ( decl . value ) ) {
405+ this . count ++ ;
406+ }
407+ super . visitLetDeclaration ( decl , null ) ;
408+ }
409+
402410 private hasDirectives ( input : string ) : boolean {
403411 return commonModuleDirectives . has ( input ) ;
404412 }
Original file line number Diff line number Diff line change @@ -6512,6 +6512,39 @@ describe('control flow migration', () => {
65126512
65136513 expect ( actual ) . toBe ( expected ) ;
65146514 } ) ;
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+ } ) ;
65156548 } ) ;
65166549
65176550 describe ( 'no migration needed' , ( ) => {
You can’t perform that action at this time.
0 commit comments