@@ -291,7 +291,7 @@ runInEachFileSystem(() => {
291291 expect ( jsContents ) . toContain ( 'i0.ɵɵdefer(1, 0, Cmp_Defer_1_DepsFn);' ) ;
292292
293293 expect ( hmrContents ) . toContain (
294- 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, Component, Dep ) {' ,
294+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, Dep, Component ) {' ,
295295 ) ;
296296 expect ( hmrContents ) . toContain ( 'const Cmp_Defer_1_DepsFn = () => [Dep];' ) ;
297297 expect ( hmrContents ) . toContain ( 'function Cmp_Defer_0_Template(rf, ctx) {' ) ;
@@ -502,5 +502,153 @@ runInEachFileSystem(() => {
502502 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, token, value, Component) {' ,
503503 ) ;
504504 } ) ;
505+
506+ it ( 'should preserve eager standalone imports in HMR even if they are not used in the template' , ( ) => {
507+ enableHmr ( {
508+ // Disable class metadata since it can add noise to the test.
509+ supportTestBed : false ,
510+ extendedDiagnostics : {
511+ checks : {
512+ // Disable the diagnostic that flags standalone imports since
513+ // we need one to simulate the case we're looking for.
514+ unusedStandaloneImports : 'suppress' ,
515+ } ,
516+ } ,
517+ } ) ;
518+
519+ env . write (
520+ 'dep.ts' ,
521+ `
522+ import {Directive} from '@angular/core';
523+
524+ @Directive({selector: '[dep]'})
525+ export class Dep {}
526+ ` ,
527+ ) ;
528+
529+ env . write (
530+ 'test.ts' ,
531+ `
532+ import {Component} from '@angular/core';
533+ import {Dep} from './dep';
534+
535+ @Component({
536+ selector: 'cmp',
537+ template: '',
538+ imports: [Dep],
539+ })
540+ export class Cmp {}
541+ ` ,
542+ ) ;
543+
544+ env . driveMain ( ) ;
545+
546+ const jsContents = env . getContents ( 'test.js' ) ;
547+ const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
548+
549+ expect ( jsContents ) . toContain ( 'dependencies: [Dep]' ) ;
550+ expect ( jsContents ) . toContain ( 'ɵɵreplaceMetadata(Cmp, m.default, [i0], [Dep]));' ) ;
551+ expect ( hmrContents ) . toContain ( 'function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, Dep) {' ) ;
552+ } ) ;
553+
554+ it ( 'should preserve eager module imports inside standalone component in HMR even if they are not used in the template' , ( ) => {
555+ enableHmr ( {
556+ // Disable class metadata since it can add noise to the test.
557+ supportTestBed : false ,
558+ } ) ;
559+
560+ env . write (
561+ 'dep.ts' ,
562+ `
563+ import {NgModule, Directive} from '@angular/core';
564+
565+ @Directive({selector: '[dep]', standalone: false})
566+ export class Dep {}
567+
568+ @NgModule({declarations: [Dep], exports: [Dep]})
569+ export class DepModule {}
570+ ` ,
571+ ) ;
572+
573+ env . write (
574+ 'test.ts' ,
575+ `
576+ import {Component} from '@angular/core';
577+ import {DepModule} from './dep';
578+
579+ @Component({
580+ selector: 'cmp',
581+ template: '',
582+ imports: [DepModule],
583+ })
584+ export class Cmp {}
585+ ` ,
586+ ) ;
587+
588+ env . driveMain ( ) ;
589+
590+ const jsContents = env . getContents ( 'test.js' ) ;
591+ const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
592+
593+ expect ( jsContents ) . toContain ( 'dependencies: [DepModule, i1.Dep]' ) ;
594+ expect ( jsContents ) . toContain ( 'ɵɵreplaceMetadata(Cmp, m.default, [i0, i1], [DepModule]));' ) ;
595+ expect ( hmrContents ) . toContain ( 'function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, DepModule) {' ) ;
596+ } ) ;
597+
598+ it ( 'should preserve eager module imports inside non-standalone component in HMR even if they are not used in the template' , ( ) => {
599+ enableHmr ( {
600+ // Disable class metadata since it can add noise to the test.
601+ supportTestBed : false ,
602+ } ) ;
603+
604+ env . write (
605+ 'dep.ts' ,
606+ `
607+ import {NgModule, Directive} from '@angular/core';
608+
609+ @Directive({selector: '[dep]', standalone: false})
610+ export class Dep {}
611+
612+ @NgModule({declarations: [Dep], exports: [Dep]})
613+ export class DepModule {}
614+ ` ,
615+ ) ;
616+
617+ env . write (
618+ 'test-module.ts' ,
619+ `
620+ import {NgModule} from '@angular/core';
621+ import {Cmp} from './test';
622+ import {DepModule} from './dep';
623+
624+ @NgModule({imports: [DepModule], declarations: [Cmp], exports: [Cmp]})
625+ export class CmpModule {}
626+ ` ,
627+ ) ;
628+
629+ env . write (
630+ 'test.ts' ,
631+ `
632+ import {Component} from '@angular/core';
633+ import {DepModule} from './dep';
634+
635+ @Component({
636+ selector: 'cmp',
637+ template: '',
638+ standalone: false,
639+ })
640+ export class Cmp {}
641+ ` ,
642+ ) ;
643+
644+ env . driveMain ( ) ;
645+
646+ const jsContents = env . getContents ( 'test.js' ) ;
647+ const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
648+
649+ expect ( jsContents ) . toContain ( 'dependencies: [i1.Dep]' ) ;
650+ expect ( jsContents ) . toContain ( 'ɵɵreplaceMetadata(Cmp, m.default, [i0, i1], []));' ) ;
651+ expect ( hmrContents ) . toContain ( 'function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces) {' ) ;
652+ } ) ;
505653 } ) ;
506654} ) ;
0 commit comments