forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): property support inheritance
Inheritance Semantics: Class Decorators: 1) list all decorators of all parent classes and of the class itself (in this 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. Property / Method decorators: 1) per property / method, list all decorators of all parent classes and of the class itself (in this order) 2) per property, only use the last decorator of each kind (e.g. @input / ...) Lifeclyce hooks: Merge the lifecycle hooks of all parent classes and of the class itself E.g. the following is a valid use of inheritance and it will also inherit all metadata: ``` @directive( class ParentDirective { constructor(someDep: SomeDep) {} } class ChildDirective extends ParentDirective {} ``` Closes angular#11606 Closes angular#12892
- Loading branch information
Showing
19 changed files
with
968 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @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 {PipeResolver} from '@angular/compiler/src/pipe_resolver'; | ||
import {Pipe} from '@angular/core/src/metadata'; | ||
import {stringify} from '../src/facade/lang'; | ||
|
||
@Pipe({name: 'somePipe', pure: true}) | ||
class SomePipe { | ||
} | ||
|
||
class SimpleClass {} | ||
|
||
export function main() { | ||
describe('PipeResolver', () => { | ||
let resolver: PipeResolver; | ||
|
||
beforeEach(() => { resolver = new PipeResolver(); }); | ||
|
||
it('should read out the metadata from the class', () => { | ||
const moduleMetadata = resolver.resolve(SomePipe); | ||
expect(moduleMetadata).toEqual(new Pipe({name: 'somePipe', pure: true})); | ||
}); | ||
|
||
it('should throw when simple class has no pipe decorator', () => { | ||
expect(() => resolver.resolve(SimpleClass)) | ||
.toThrowError(`No Pipe decorator found on ${stringify(SimpleClass)}`); | ||
}); | ||
|
||
it('should support inheriting the metadata', function() { | ||
@Pipe({name: 'p'}) | ||
class Parent { | ||
} | ||
|
||
class ChildNoDecorator extends Parent {} | ||
|
||
@Pipe({name: 'c'}) | ||
class ChildWithDecorator extends Parent { | ||
} | ||
|
||
expect(resolver.resolve(ChildNoDecorator)).toEqual(new Pipe({name: 'p'})); | ||
|
||
expect(resolver.resolve(ChildWithDecorator)).toEqual(new Pipe({name: 'c'})); | ||
}); | ||
|
||
}); | ||
} |
Oops, something went wrong.