@@ -102,12 +102,13 @@ runInEachFileSystem(() => {
102102 const jsContents = env . getContents ( 'test.js' ) ;
103103 const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
104104
105+ expect ( jsContents ) . toContain ( `import * as i0 from "@angular/core";` ) ;
105106 expect ( jsContents ) . toContain ( 'function Cmp_HmrLoad(t) {' ) ;
106107 expect ( jsContents ) . toContain (
107108 'import(/* @vite-ignore */\n"/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t))' ,
108109 ) ;
109110 expect ( jsContents ) . toContain (
110- ').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, i0 , ' +
111+ ').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0] , ' +
111112 '[Dep, transformValue, TOKEN, Component, Inject, ViewChild, Input]));' ,
112113 ) ;
113114 expect ( jsContents ) . toContain ( 'Cmp_HmrLoad(Date.now());' ) ;
@@ -117,12 +118,82 @@ runInEachFileSystem(() => {
117118 ) ;
118119
119120 expect ( hmrContents ) . toContain (
120- 'export default function Cmp_UpdateMetadata(Cmp, __ngCore__ , Dep, transformValue, TOKEN, Component, Inject, ViewChild, Input) {' ,
121+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces , Dep, transformValue, TOKEN, Component, Inject, ViewChild, Input) {' ,
121122 ) ;
123+ expect ( hmrContents ) . toContain ( `const ɵhmr0 = ɵɵnamespaces[0];` ) ;
122124 expect ( hmrContents ) . toContain ( 'Cmp.ɵfac = function Cmp_Factory' ) ;
123- expect ( hmrContents ) . toContain ( 'Cmp.ɵcmp = /*@__PURE__*/ __ngCore__.ɵɵdefineComponent' ) ;
124- expect ( hmrContents ) . toContain ( '__ngCore__.ɵsetClassMetadata(Cmp,' ) ;
125- expect ( hmrContents ) . toContain ( '__ngCore__.ɵsetClassDebugInfo(Cmp,' ) ;
125+ expect ( hmrContents ) . toContain ( 'Cmp.ɵcmp = /*@__PURE__*/ ɵhmr0.ɵɵdefineComponent' ) ;
126+ expect ( hmrContents ) . toContain ( 'ɵhmr0.ɵsetClassMetadata(Cmp,' ) ;
127+ expect ( hmrContents ) . toContain ( 'ɵhmr0.ɵsetClassDebugInfo(Cmp,' ) ;
128+ } ) ;
129+
130+ it ( 'should generate an HMR initializer and update function for a class that depends on multiple namespaces' , ( ) => {
131+ enableHmr ( ) ;
132+ env . write (
133+ 'dep.ts' ,
134+ `
135+ import {Directive, NgModule} from '@angular/core';
136+
137+ @Directive({
138+ selector: '[dep]',
139+ standalone: true,
140+ })
141+ export class Dep {}
142+
143+ @NgModule({
144+ imports: [Dep],
145+ exports: [Dep]
146+ })
147+ export class DepModule {}
148+ ` ,
149+ ) ;
150+
151+ env . write (
152+ 'test.ts' ,
153+ `
154+ import {Component, ViewChild, Input, Inject} from '@angular/core';
155+ import {DepModule} from './dep';
156+
157+ @Component({
158+ selector: 'cmp',
159+ standalone: true,
160+ template: '<div dep><div>',
161+ imports: [DepModule],
162+ })
163+ export class Cmp {}
164+ ` ,
165+ ) ;
166+
167+ env . driveMain ( ) ;
168+
169+ const jsContents = env . getContents ( 'test.js' ) ;
170+ const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
171+ expect ( jsContents ) . toContain ( `import * as i0 from "@angular/core";` ) ;
172+ expect ( jsContents ) . toContain ( `import * as i1 from "./dep";` ) ;
173+ expect ( jsContents ) . toContain ( 'function Cmp_HmrLoad(t) {' ) ;
174+ expect ( jsContents ) . toContain (
175+ 'import(/* @vite-ignore */\n"/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t))' ,
176+ ) ;
177+ expect ( jsContents ) . toContain (
178+ ').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0, i1], ' +
179+ '[DepModule, Component]));' ,
180+ ) ;
181+ expect ( jsContents ) . toContain ( 'Cmp_HmrLoad(Date.now());' ) ;
182+ expect ( jsContents ) . toContain (
183+ 'import.meta.hot && import.meta.hot.on("angular:component-update", ' +
184+ 'd => d.id === "test.ts%40Cmp" && Cmp_HmrLoad(d.timestamp)' ,
185+ ) ;
186+
187+ expect ( hmrContents ) . toContain (
188+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, DepModule, Component) {' ,
189+ ) ;
190+ expect ( hmrContents ) . toContain ( `const ɵhmr0 = ɵɵnamespaces[0];` ) ;
191+ expect ( hmrContents ) . toContain ( `const ɵhmr1 = ɵɵnamespaces[1];` ) ;
192+ expect ( hmrContents ) . toContain ( 'Cmp.ɵfac = function Cmp_Factory' ) ;
193+ expect ( hmrContents ) . toContain ( 'Cmp.ɵcmp = /*@__PURE__*/ ɵhmr0.ɵɵdefineComponent' ) ;
194+ expect ( hmrContents ) . toContain ( 'ɵhmr0.ɵsetClassMetadata(Cmp,' ) ;
195+ expect ( hmrContents ) . toContain ( 'ɵhmr0.ɵsetClassDebugInfo(Cmp,' ) ;
196+ expect ( hmrContents ) . toContain ( 'dependencies: [DepModule, ɵhmr1.Dep]' ) ;
126197 } ) ;
127198
128199 it ( 'should generate an HMR update function for a component that has embedded views' , ( ) => {
@@ -144,10 +215,10 @@ runInEachFileSystem(() => {
144215 const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
145216
146217 expect ( hmrContents ) . toContain (
147- 'export default function Cmp_UpdateMetadata(Cmp, __ngCore__ , Component) {' ,
218+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces , Component) {' ,
148219 ) ;
149220 expect ( hmrContents ) . toContain ( 'function Cmp_Conditional_0_Template(rf, ctx) {' ) ;
150- expect ( hmrContents ) . toContain ( '__ngCore__ .ɵɵtemplate(0, Cmp_Conditional_0_Template, 1, 0);' ) ;
221+ expect ( hmrContents ) . toContain ( 'ɵhmr0 .ɵɵtemplate(0, Cmp_Conditional_0_Template, 1, 0);' ) ;
151222 } ) ;
152223
153224 it ( 'should generate an HMR update function for a component whose definition produces variables' , ( ) => {
@@ -169,12 +240,12 @@ runInEachFileSystem(() => {
169240 const hmrContents = env . driveHmr ( 'test.ts' , 'Cmp' ) ;
170241
171242 expect ( hmrContents ) . toContain (
172- 'export default function Cmp_UpdateMetadata(Cmp, __ngCore__ , Component) {' ,
243+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces , Component) {' ,
173244 ) ;
174245 expect ( hmrContents ) . toContain ( 'const _c0 = [[["header"]], "*"];' ) ;
175246 expect ( hmrContents ) . toContain ( 'const _c1 = ["header", "*"];' ) ;
176247 expect ( hmrContents ) . toContain ( 'ngContentSelectors: _c1' ) ;
177- expect ( hmrContents ) . toContain ( '__ngCore__ .ɵɵprojectionDef(_c0);' ) ;
248+ expect ( hmrContents ) . toContain ( 'ɵhmr0 .ɵɵprojectionDef(_c0);' ) ;
178249 } ) ;
179250
180251 it ( 'should not defer dependencies when HMR is enabled' , ( ) => {
@@ -219,11 +290,11 @@ runInEachFileSystem(() => {
219290 expect ( jsContents ) . toContain ( 'i0.ɵɵdefer(1, 0, Cmp_Defer_1_DepsFn);' ) ;
220291
221292 expect ( hmrContents ) . toContain (
222- 'export default function Cmp_UpdateMetadata(Cmp, __ngCore__ , Component, Dep) {' ,
293+ 'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces , Component, Dep) {' ,
223294 ) ;
224295 expect ( hmrContents ) . toContain ( 'const Cmp_Defer_1_DepsFn = () => [Dep];' ) ;
225296 expect ( hmrContents ) . toContain ( 'function Cmp_Defer_0_Template(rf, ctx) {' ) ;
226- expect ( hmrContents ) . toContain ( '__ngCore__ .ɵɵdefer(1, 0, Cmp_Defer_1_DepsFn);' ) ;
297+ expect ( hmrContents ) . toContain ( 'ɵhmr0 .ɵɵdefer(1, 0, Cmp_Defer_1_DepsFn);' ) ;
227298 expect ( hmrContents ) . not . toContain ( 'import(' ) ;
228299 } ) ;
229300
0 commit comments