File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
compiler-cli/src/ngtsc/typecheck/src Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -719,6 +719,11 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
719719 }
720720 const emitted = emittedRef . expression ;
721721 if ( emitted instanceof WrappedNodeExpr ) {
722+ if ( refTo . node === inContext ) {
723+ // Suppress self-imports since components do not have to import themselves.
724+ return null ;
725+ }
726+
722727 let isForwardReference = false ;
723728 if ( emitted . node . getStart ( ) > inContext . getStart ( ) ) {
724729 const declaration = this . programDriver . getProgram ( )
Original file line number Diff line number Diff line change @@ -1550,6 +1550,39 @@ describe('standalone migration', () => {
15501550 ` ) ) ;
15511551 } ) ;
15521552
1553+ it ( 'should not generate a forwardRef for a self import' , async ( ) => {
1554+ writeFile ( 'decls.ts' , `
1555+ import {Component} from '@angular/core';
1556+
1557+ @Component({
1558+ selector: 'comp',
1559+ template: '<comp/>'
1560+ })
1561+ export class MyComp {}
1562+ ` ) ;
1563+
1564+ writeFile ( 'module.ts' , `
1565+ import {NgModule} from '@angular/core';
1566+ import {MyComp} from './decls';
1567+
1568+ @NgModule({declarations: [MyComp]})
1569+ export class Mod {}
1570+ ` ) ;
1571+
1572+ await runMigration ( 'convert-to-standalone' ) ;
1573+
1574+ expect ( stripWhitespace ( tree . readContent ( 'decls.ts' ) ) ) . toEqual ( stripWhitespace ( `
1575+ import {Component} from '@angular/core';
1576+
1577+ @Component({
1578+ selector: 'comp',
1579+ template: '<comp/>',
1580+ standalone: true
1581+ })
1582+ export class MyComp {}
1583+ ` ) ) ;
1584+ } ) ;
1585+
15531586 it ( 'should not generate a forwardRef when adding an imported module dependency' , async ( ) => {
15541587 writeFile ( './comp.ts' , `
15551588 import {Component, NgModule} from '@angular/core';
You can’t perform that action at this time.
0 commit comments