feat(core): properly support inheritance
## Inheritance Semantics:
Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @Component / ...)
Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.
Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.
## Example
E.g. the following is a valid use of inheritance and it will
also inherit all metadata:
```
@Directive({selector: 'someDir'})
class ParentDirective {
constructor(someDep: SomeDep) {}
ngOnInit() {}
}
class ChildDirective extends ParentDirective {}
```
Closes #11606
Closes #12892
This commit is contained in:
@@ -262,7 +262,7 @@ export function makeDecorator(
|
||||
const metaCtor = makeMetadataCtor([props]);
|
||||
|
||||
function DecoratorFactory(objOrType: any): (cls: any) => any {
|
||||
if (!(Reflect && Reflect.getMetadata)) {
|
||||
if (!(Reflect && Reflect.getOwnMetadata)) {
|
||||
throw 'reflect-metadata shim is required when using class decorators';
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ export function makeParamDecorator(
|
||||
return ParamDecorator;
|
||||
|
||||
function ParamDecorator(cls: any, unusedKey: any, index: number): any {
|
||||
const parameters: any[][] = Reflect.getMetadata('parameters', cls) || [];
|
||||
const parameters: any[][] = Reflect.getOwnMetadata('parameters', cls) || [];
|
||||
|
||||
// there might be gaps if some in between parameters do not have annotations.
|
||||
// we pad with nulls.
|
||||
|
||||
Reference in New Issue
Block a user