fix(ivy): semantic module check incorrectly handles nested arrays (#30993)

In View Engine, developers can pass bootstrap and entry components
as nested arrays. e.g.

```ts
export const MyOtherEntryComponents = [A, B, C]

@NgModule({
  entryComponents: [MyComp, MyOtherEntryComponents]
})
```

Currently using nested arrays for these properties causes
unexpected errors to be reported in Ivy since the semantic
NgModule checks aren't properly recursing into the nested
entry/bootstrap components. This issue has been unveiled by
enabling the strict function parameter checks.

PR Close #30993
This commit is contained in:
Paul Gschwendtner
2019-06-11 22:53:03 +02:00
committed by Miško Hevery
parent dda781ecce
commit e061e638cb
4 changed files with 89 additions and 10 deletions

View File

@ -0,0 +1,77 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, NgModule} from '@angular/core';
import {TestBed} from '@angular/core/testing';
describe('NgModule', () => {
@Component({template: 'hello'})
class TestCmp {
}
@Component({template: 'hello'})
class TestCmp2 {
}
describe('entryComponents', () => {
it('should throw when specified entry component is not added to a module', () => {
@NgModule({entryComponents: [TestCmp, [TestCmp2]]})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
TestBed.createComponent(TestCmp);
TestBed.createComponent(TestCmp2);
}).toThrowError(/not part of any NgModule/);
});
it('should not throw when specified entry component is added to a module', () => {
@NgModule({declarations: [TestCmp, TestCmp2], entryComponents: [TestCmp, [TestCmp2]]})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
TestBed.createComponent(TestCmp);
TestBed.createComponent(TestCmp2);
}).not.toThrow();
});
});
describe('bootstrap', () => {
it('should throw when specified bootstrap component is not added to a module', () => {
@NgModule({bootstrap: [TestCmp, [TestCmp2]]})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
TestBed.createComponent(TestCmp);
TestBed.createComponent(TestCmp2);
}).toThrowError(/not part of any NgModule/);
});
it('should not throw when specified bootstrap component is added to a module', () => {
@NgModule({declarations: [TestCmp, TestCmp2], bootstrap: [TestCmp, [TestCmp2]]})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
TestBed.createComponent(TestCmp);
TestBed.createComponent(TestCmp2);
}).not.toThrow();
});
});
});