fix(compiler): recognize @NgModule with a redundant @Injectable (#20320)

The compiler now, again, recognizes `@NgModule()` decorators on
classes with a redundant `@Injectable()` decorator.

Fixes: #19544

PR Close #20320
This commit is contained in:
Chuck Jazdzewski 2017-11-09 16:52:19 -08:00 committed by Jason Aden
parent cf618c564c
commit c33a57666b
2 changed files with 40 additions and 4 deletions

View File

@ -1392,6 +1392,42 @@ describe('ngc transformer command-line', () => {
}); });
describe('regressions', () => { 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: '<p>hello</p>',
})
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 // #19765
it('should not report an error when the resolved .css file is in outside rootDir', () => { it('should not report an error when the resolved .css file is in outside rootDir', () => {
write('src/tsconfig.json', `{ write('src/tsconfig.json', `{

View File

@ -709,15 +709,15 @@ export function analyzeFile(
} else if (metadataResolver.isPipe(symbol)) { } else if (metadataResolver.isPipe(symbol)) {
isNgSymbol = true; isNgSymbol = true;
pipes.push(symbol); pipes.push(symbol);
} else if (metadataResolver.isInjectable(symbol)) { } else if (metadataResolver.isNgModule(symbol)) {
isNgSymbol = true;
injectables.push(symbol);
} else {
const ngModule = metadataResolver.getNgModuleMetadata(symbol, false); const ngModule = metadataResolver.getNgModuleMetadata(symbol, false);
if (ngModule) { if (ngModule) {
isNgSymbol = true; isNgSymbol = true;
ngModules.push(ngModule); ngModules.push(ngModule);
} }
} else if (metadataResolver.isInjectable(symbol)) {
isNgSymbol = true;
injectables.push(symbol);
} }
} }
if (!isNgSymbol) { if (!isNgSymbol) {