fix(ivy): pass `schemas` field to nested views (#31913)

Prior to this commit, the `schemas` configuration was applied to top-level view only. That leads to problems when using unknown props with elements inside nested views (for example generated as a result of *ngIf). This commit passes `schemas` information down to nested views to make sure that all the checks are consistent.

PR Close #31913
This commit is contained in:
Andrew Kushnir 2019-07-30 12:32:50 -07:00 committed by Alex Rickabaugh
parent e8b8f6d09b
commit d0d875a3fe
2 changed files with 63 additions and 2 deletions

View File

@ -76,7 +76,8 @@ export function ɵɵtemplate(
resolveDirectives(tView, lView, tContainerNode, localRefs || null); resolveDirectives(tView, lView, tContainerNode, localRefs || null);
const embeddedTView = tContainerNode.tViews = createTView( const embeddedTView = tContainerNode.tViews = createTView(
-1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null); -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null,
tView.schemas);
if (tView.queries !== null) { if (tView.queries !== null) {
tView.queries.template(tView, tContainerNode); tView.queries.template(tView, tContainerNode);
embeddedTView.queries = tView.queries.embeddedTView(tContainerNode); embeddedTView.queries = tView.queries.embeddedTView(tContainerNode);

View File

@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Component, NgModule} from '@angular/core'; import {CommonModule} from '@angular/common';
import {Component, NO_ERRORS_SCHEMA, NgModule} from '@angular/core';
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
describe('NgModule', () => { describe('NgModule', () => {
@ -74,4 +75,63 @@ describe('NgModule', () => {
}); });
}); });
describe('schemas', () => {
it('should throw on unknown props if NO_ERRORS_SCHEMA is absent', () => {
@Component({
selector: 'my-comp',
template: `
<ng-container *ngIf="condition">
<div [unknown-prop]="true"></div>
</ng-container>
`,
})
class MyComp {
condition = true;
}
@NgModule({
imports: [CommonModule],
declarations: [MyComp],
})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
}).toThrowError(/Can't bind to 'unknown-prop' since it isn't a known property of 'div'/);
});
it('should not throw on unknown props if NO_ERRORS_SCHEMA is present', () => {
@Component({
selector: 'my-comp',
template: `
<ng-container *ngIf="condition">
<div [unknown-prop]="true"></div>
</ng-container>
`,
})
class MyComp {
condition = true;
}
@NgModule({
imports: [CommonModule],
schemas: [NO_ERRORS_SCHEMA],
declarations: [MyComp],
})
class MyModule {
}
TestBed.configureTestingModule({imports: [MyModule]});
expect(() => {
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
}).not.toThrow();
});
});
}); });