fix(core): Resolve forwardRef declarations for jit (#46334)

Fix forwardRef() usage for declarations for jit. Resolves #45741.

PR Close #46334
This commit is contained in:
Paul Draper
2022-04-23 22:21:39 -06:00
committed by Jessica Janiuk
parent b92c1a6ada
commit 3fd8948b4a
2 changed files with 21 additions and 1 deletions
+1
View File
@@ -466,6 +466,7 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
const transitiveScopes = transitiveScopesFor(moduleType);
declarations.forEach(declaration => {
declaration = resolveForwardRef(declaration);
if (declaration.hasOwnProperty(NG_COMP_DEF)) {
// A `ɵcmp` field exists - go ahead and patch the component directly.
const component = declaration as Type<any>& {ɵcmp: ComponentDef<any>};
+20 -1
View File
@@ -7,7 +7,7 @@
*/
import 'reflect-metadata';
import {Component, ContentChild, ContentChildren, Directive, ElementRef, getNgModuleById, HostBinding, HostListener, Input, NgModule, Pipe, QueryList, ViewChild, ViewChildren, ɵNgModuleDef as NgModuleDef, ɵɵngDeclareComponent as ngDeclareComponent} from '@angular/core';
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';
import {Injectable} from '@angular/core/src/di/injectable';
import {setCurrentInjector, ɵɵinject} from '@angular/core/src/di/injector_compatibility';
import {ɵɵdefineInjectable, ɵɵInjectorDef} from '@angular/core/src/di/interface/defs';
@@ -226,6 +226,25 @@ describe('render3 jit', () => {
expect(moduleDef.declarations[0]).toBe(Cmp);
});
it('compiles a module with forwardRef', () => {
@NgModule({
declarations: [forwardRef(() => Cmp)],
})
class Module {
}
@Component({
template: 'foo',
selector: 'foo',
})
class Cmp {
}
const componentDef: ComponentDef<Module> = (Cmp as any).ɵcmp;
expect(componentDef).toBeDefined();
expect(componentDef.schemas).toBeInstanceOf(Array);
});
it('compiles a module with an id and registers it correctly', () => {
@NgModule({
id: 'test',