fix(ivy): support schemas at runtime (#28637)

Accounts for schemas in when validating properties in Ivy.

This PR resolves FW-819.

A couple of notes:
* I had to rework the test slightly, in order to have it fail when we expect it to. The one in master is passing since Ivy's validation runs during the update phase, rather than creation.
* I had to deviate from the design in FW-819 and not add an `enableSchema` instruction, because the schema is part of the `NgModule` scope, however the scope is only assigned to a component once all of the module's declarations have been resolved and some of them can be async. Instead, I opted to have the `schemas` on the component definition.

PR Close #28637
This commit is contained in:
Kristiyan Kostadinov
2019-02-12 00:03:04 +01:00
committed by Miško Hevery
parent 7cbc36fdac
commit 80a5934af6
18 changed files with 162 additions and 76 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, InjectionToken, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, Self, Type, forwardRef, getModuleFactory, ɵivyEnabled as ivyEnabled} from '@angular/core';
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, InjectionToken, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, Self, Type, forwardRef, getModuleFactory, ɵivyEnabled as ivyEnabled} from '@angular/core';
import {Console} from '@angular/core/src/console';
import {InjectableDef, defineInjectable} from '@angular/core/src/di/interface/defs';
import {getNgModuleDef} from '@angular/core/src/render3/definition';
@ -266,22 +266,29 @@ function declareTests(config?: {useJit: boolean}) {
expect(() => fixture.detectChanges()).toThrowError(/Can't bind to 'someUnknownProp'/);
});
fixmeIvy('FW-819: ngtsc compiler should support schemas')
.it('should not error on unknown bound properties on custom elements when using the CUSTOM_ELEMENTS_SCHEMA',
() => {
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
class ComponentUsingInvalidProperty {
}
it('should not error on unknown bound properties on custom elements when using the CUSTOM_ELEMENTS_SCHEMA',
() => {
@Component({template: '<some-element [someUnknownProp]="true"></some-element>'})
class ComponentUsingInvalidProperty {
}
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [ComponentUsingInvalidProperty]
})
class SomeModule {
}
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [ComponentUsingInvalidProperty],
expect(() => createModule(SomeModule)).not.toThrow();
});
// Note that we need to add the component to `entryComponents`, because of the
// `createComp` call below. In Ivy the property validation happens during the
// update phase so we need to create the component, in order for it to run.
entryComponents: [ComponentUsingInvalidProperty]
})
class SomeModule {
}
expect(() => {
const fixture = createComp(ComponentUsingInvalidProperty, SomeModule);
fixture.detectChanges();
}).not.toThrow();
});
});
describe('id', () => {