Skip to content

Commit 3fd8948

Browse files
pauldraperthePunderWoman
authored andcommitted
fix(core): Resolve forwardRef declarations for jit (#46334)
Fix forwardRef() usage for declarations for jit. Resolves #45741. PR Close #46334
1 parent b92c1a6 commit 3fd8948

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/core/src/render3/jit/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
466466
const transitiveScopes = transitiveScopesFor(moduleType);
467467

468468
declarations.forEach(declaration => {
469+
declaration = resolveForwardRef(declaration);
469470
if (declaration.hasOwnProperty(NG_COMP_DEF)) {
470471
// A `ɵcmp` field exists - go ahead and patch the component directly.
471472
const component = declaration as Type<any>& {ɵcmp: ComponentDef<any>};

packages/core/test/render3/ivy/jit_spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import 'reflect-metadata';
99

10-
import {Component, ContentChild, ContentChildren, Directive, ElementRef, getNgModuleById, HostBinding, HostListener, Input, NgModule, Pipe, QueryList, ViewChild, ViewChildren, ɵNgModuleDef as NgModuleDef, ɵɵngDeclareComponent as ngDeclareComponent} from '@angular/core';
10+
import {Component, ContentChild, ContentChildren, Directive, ElementRef, forwardRef, getNgModuleById, HostBinding, HostListener, Input, NgModule, Pipe, QueryList, ViewChild, ViewChildren, ɵNgModuleDef as NgModuleDef, ɵɵngDeclareComponent as ngDeclareComponent} from '@angular/core';
1111
import {Injectable} from '@angular/core/src/di/injectable';
1212
import {setCurrentInjector, ɵɵinject} from '@angular/core/src/di/injector_compatibility';
1313
import {ɵɵdefineInjectable, ɵɵInjectorDef} from '@angular/core/src/di/interface/defs';
@@ -226,6 +226,25 @@ describe('render3 jit', () => {
226226
expect(moduleDef.declarations[0]).toBe(Cmp);
227227
});
228228

229+
it('compiles a module with forwardRef', () => {
230+
@NgModule({
231+
declarations: [forwardRef(() => Cmp)],
232+
})
233+
class Module {
234+
}
235+
236+
@Component({
237+
template: 'foo',
238+
selector: 'foo',
239+
})
240+
class Cmp {
241+
}
242+
243+
const componentDef: ComponentDef<Module> = (Cmp as any).ɵcmp;
244+
expect(componentDef).toBeDefined();
245+
expect(componentDef.schemas).toBeInstanceOf(Array);
246+
});
247+
229248
it('compiles a module with an id and registers it correctly', () => {
230249
@NgModule({
231250
id: 'test',

0 commit comments

Comments
 (0)