diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index b142b41bf6..e92ee8ba8b 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -1392,6 +1392,42 @@ describe('ngc transformer command-line', () => { }); describe('regressions', () => { + //#19544 + it('should recognize @NgModule() directive with a redundant @Injectable()', () => { + write('src/tsconfig.json', `{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "outDir": "../dist", + "rootDir": ".", + "rootDirs": [ + ".", + "../dist" + ] + }, + "files": ["test-module.ts"] + }`); + write('src/test.component.ts', ` + import {Component} from '@angular/core'; + + @Component({ + template: '

hello

', + }) + export class TestComponent {} + `); + write('src/test-module.ts', ` + import {Injectable, NgModule} from '@angular/core'; + import {TestComponent} from './test.component'; + + @NgModule({declarations: [TestComponent]}) + @Injectable() + export class TestModule {} + `); + const messages: string[] = []; + const exitCode = + main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message)); + expect(exitCode).toBe(0, 'Compile failed unexpectedly.\n ' + messages.join('\n ')); + }); + // #19765 it('should not report an error when the resolved .css file is in outside rootDir', () => { write('src/tsconfig.json', `{ diff --git a/packages/compiler/src/aot/compiler.ts b/packages/compiler/src/aot/compiler.ts index 22be0661ae..07b5ccc517 100644 --- a/packages/compiler/src/aot/compiler.ts +++ b/packages/compiler/src/aot/compiler.ts @@ -709,15 +709,15 @@ export function analyzeFile( } else if (metadataResolver.isPipe(symbol)) { isNgSymbol = true; pipes.push(symbol); - } else if (metadataResolver.isInjectable(symbol)) { - isNgSymbol = true; - injectables.push(symbol); - } else { + } else if (metadataResolver.isNgModule(symbol)) { const ngModule = metadataResolver.getNgModuleMetadata(symbol, false); if (ngModule) { isNgSymbol = true; ngModules.push(ngModule); } + } else if (metadataResolver.isInjectable(symbol)) { + isNgSymbol = true; + injectables.push(symbol); } } if (!isNgSymbol) {