@@ -5442,6 +5442,71 @@ describe('control flow migration', () => {
54425442
54435443 expect ( actual ) . toBe ( expected ) ;
54445444 } ) ;
5445+
5446+ it ( 'should not modify `imports` initialized to a variable reference' , async ( ) => {
5447+ writeFile ( '/comp.ts' , [
5448+ `import {Component} from '@angular/core';` ,
5449+ `import {CommonModule} from '@angular/common';\n` ,
5450+ `const IMPORTS = [CommonModule];\n` ,
5451+ `@Component({` ,
5452+ ` imports: IMPORTS,` ,
5453+ ` template: '<span *ngIf="show">Content here</span>',` ,
5454+ `})` ,
5455+ `class Comp {` ,
5456+ ` show = false;` ,
5457+ `}` ,
5458+ ] . join ( '\n' ) ) ;
5459+
5460+ await runMigration ( ) ;
5461+ const actual = tree . readContent ( '/comp.ts' ) ;
5462+ const expected = [
5463+ `import {Component} from '@angular/core';` ,
5464+ `import {CommonModule} from '@angular/common';\n` ,
5465+ `const IMPORTS = [CommonModule];\n` ,
5466+ `@Component({` ,
5467+ ` imports: IMPORTS,` ,
5468+ ` template: '@if (show) {<span>Content here</span>}',` ,
5469+ `})` ,
5470+ `class Comp {` ,
5471+ ` show = false;` ,
5472+ `}` ,
5473+ ] . join ( '\n' ) ;
5474+
5475+ expect ( actual ) . toBe ( expected ) ;
5476+ } ) ;
5477+
5478+ it ( 'should handle spread elements in the `imports` array' , async ( ) => {
5479+ writeFile ( '/comp.ts' , [
5480+ `import {Component} from '@angular/core';` ,
5481+ `import {CommonModule} from '@angular/common';\n` ,
5482+ `const BEFORE = [];\n` ,
5483+ `const AFTER = [];\n` ,
5484+ `@Component({` ,
5485+ ` imports: [...BEFORE, CommonModule, ...AFTER],` ,
5486+ ` template: '<span *ngIf="show">Content here</span>',` ,
5487+ `})` ,
5488+ `class Comp {` ,
5489+ ` show = false;` ,
5490+ `}` ,
5491+ ] . join ( '\n' ) ) ;
5492+
5493+ await runMigration ( ) ;
5494+ const actual = tree . readContent ( '/comp.ts' ) ;
5495+ const expected = [
5496+ `import {Component} from '@angular/core';\n\n` ,
5497+ `const BEFORE = [];\n` ,
5498+ `const AFTER = [];\n` ,
5499+ `@Component({` ,
5500+ ` imports: [...BEFORE, ...AFTER],` ,
5501+ ` template: '@if (show) {<span>Content here</span>}',` ,
5502+ `})` ,
5503+ `class Comp {` ,
5504+ ` show = false;` ,
5505+ `}` ,
5506+ ] . join ( '\n' ) ;
5507+
5508+ expect ( actual ) . toBe ( expected ) ;
5509+ } ) ;
54455510 } ) ;
54465511
54475512 describe ( 'no migration needed' , ( ) => {
0 commit comments