GeezerVison is showing github.com — fix(core): incorrectly throwing error for self-referencing component … · ChellappanRajan/angular@5adfa8e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/src/render3/jit/directive.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,7 +245,7 @@ function getStandaloneDefFunctions(type: Type<any>, imports: Type<any>[]): { | 245 | 245 | // Standalone components are always able to self-reference, so include the component's own | 246 | 246 | // definition in its `directiveDefs`. | 247 | 247 | cachedDirectiveDefs = [getComponentDef(type)!]; | 248 | | - const seen = new Set<Type<unknown>>(); | | 248 | + const seen = new Set<Type<unknown>>([type]); | 249 | 249 |
| 250 | 250 | for (const rawDep of imports) { | 251 | 251 | ngDevMode && verifyStandaloneImport(rawDep, type); | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/acceptance/component_spec.ts +64-2Lines changed: 64 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | * found in the LICENSE file at https://angular.io/license | 7 | 7 | */ | 8 | 8 |
| 9 | | -import {DOCUMENT} from '@angular/common'; | 10 | | -import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core'; | | 9 | +import {DOCUMENT, NgIf} from '@angular/common'; | | 10 | +import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, forwardRef, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core'; | 11 | 11 | import {stringifyForError} from '@angular/core/src/render3/util/stringify_utils'; | 12 | 12 | import {TestBed} from '@angular/core/testing'; | 13 | 13 | import {expect} from '@angular/platform-browser/testing/src/matchers'; | @@ -400,6 +400,68 @@ describe('component', () => { | 400 | 400 | .toThrowError( | 401 | 401 | /NG0300: Multiple components match node with tagname comp: CompA and CompB/); | 402 | 402 | }); | | 403 | + | | 404 | + it('should not throw if a standalone component imports itself', () => { | | 405 | + @Component({ | | 406 | + selector: 'comp', | | 407 | + template: '<comp *ngIf="recurse"/>hello', | | 408 | + standalone: true, | | 409 | + imports: [Comp, NgIf] | | 410 | + }) | | 411 | + class Comp { | | 412 | + @Input() recurse = false; | | 413 | + } | | 414 | + | | 415 | + @Component({ | | 416 | + template: '<comp [recurse]="true"/>', | | 417 | + standalone: true, | | 418 | + imports: [Comp], | | 419 | + }) | | 420 | + class App { | | 421 | + } | | 422 | + | | 423 | + let textContent = ''; | | 424 | + | | 425 | + expect(() => { | | 426 | + const fixture = TestBed.createComponent(App); | | 427 | + fixture.detectChanges(); | | 428 | + textContent = fixture.nativeElement.textContent.trim(); | | 429 | + }).not.toThrow(); | | 430 | + | | 431 | + // Ensure that the component actually rendered. | | 432 | + expect(textContent).toBe('hellohello'); | | 433 | + }); | | 434 | + | | 435 | + it('should not throw if a standalone component imports itself using a forwardRef', () => { | | 436 | + @Component({ | | 437 | + selector: 'comp', | | 438 | + template: '<comp *ngIf="recurse"/>hello', | | 439 | + standalone: true, | | 440 | + imports: [forwardRef(() => Comp), NgIf] | | 441 | + }) | | 442 | + class Comp { | | 443 | + @Input() recurse = false; | | 444 | + } | | 445 | + | | 446 | + @Component({ | | 447 | + template: '<comp [recurse]="true"/>', | | 448 | + standalone: true, | | 449 | + imports: [Comp], | | 450 | + }) | | 451 | + class App { | | 452 | + } | | 453 | + | | 454 | + let textContent = ''; | | 455 | + | | 456 | + expect(() => { | | 457 | + const fixture = TestBed.createComponent(App); | | 458 | + fixture.detectChanges(); | | 459 | + textContent = fixture.nativeElement.textContent.trim(); | | 460 | + }).not.toThrow(); | | 461 | + | | 462 | + // Ensure that the component actually rendered. | | 463 | + expect(textContent).toBe('hellohello'); | | 464 | + }); | 403 | 465 | }); | 404 | 466 |
| 405 | 467 | it('should use a new ngcontent attribute for child elements created w/ Renderer2', () => { | |
|