Skip to content

Commit

Permalink
fix(core): Resolve forwardRef declarations for jit (#46334)
Browse files Browse the repository at this point in the history
Fix forwardRef() usage for declarations for jit. Resolves #45741.

PR Close #46334
  • Loading branch information
pauldraper authored and jessicajaniuk committed Jun 13, 2022
1 parent 131d029 commit b1a3dec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/render3/jit/module.ts
Expand Up @@ -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>};
Expand Down
21 changes: 20 additions & 1 deletion packages/core/test/render3/ivy/jit_spec.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b1a3dec

Please sign in to comment.