refactor(core): delete unused reflector code
This commit is contained in:

committed by
Igor Minar

parent
bd1dcb5f11
commit
38e2203b24
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ReflectionInfo, Reflector} from '@angular/core/src/reflection/reflection';
|
||||
import {Reflector} from '@angular/core/src/reflection/reflection';
|
||||
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
|
||||
import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
|
||||
|
||||
@ -71,40 +71,12 @@ export function main() {
|
||||
|
||||
beforeEach(() => { reflector = new Reflector(new ReflectionCapabilities()); });
|
||||
|
||||
describe('usage tracking', () => {
|
||||
beforeEach(() => { reflector = new Reflector(null); });
|
||||
|
||||
it('should be disabled by default', () => {
|
||||
expect(() => reflector.listUnusedKeys()).toThrowError('Usage tracking is disabled');
|
||||
});
|
||||
|
||||
it('should report unused keys', () => {
|
||||
reflector.trackUsage();
|
||||
expect(reflector.listUnusedKeys()).toEqual([]);
|
||||
|
||||
reflector.registerType(AType, new ReflectionInfo(null, null, () => 'AType'));
|
||||
reflector.registerType(TestObj, new ReflectionInfo(null, null, () => 'TestObj'));
|
||||
expect(reflector.listUnusedKeys()).toEqual([AType, TestObj]);
|
||||
|
||||
reflector.factory(AType);
|
||||
expect(reflector.listUnusedKeys()).toEqual([TestObj]);
|
||||
|
||||
reflector.factory(TestObj);
|
||||
expect(reflector.listUnusedKeys()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('factory', () => {
|
||||
it('should create a factory for the given type', () => {
|
||||
const obj = reflector.factory(TestObj)(1, 2);
|
||||
expect(obj.a).toEqual(1);
|
||||
expect(obj.b).toEqual(2);
|
||||
});
|
||||
|
||||
it('should return a registered factory if available', () => {
|
||||
reflector.registerType(TestObj, new ReflectionInfo(null, null, () => 'fake'));
|
||||
expect(reflector.factory(TestObj)()).toEqual('fake');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parameters', () => {
|
||||
@ -117,16 +89,6 @@ export function main() {
|
||||
const p = reflector.parameters(ClassWithoutDecorators);
|
||||
expect(p.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should return registered parameters if available', () => {
|
||||
reflector.registerType(TestObj, new ReflectionInfo(null, [[1], [2]]));
|
||||
expect(reflector.parameters(TestObj)).toEqual([[1], [2]]);
|
||||
});
|
||||
|
||||
it('should return an empty list when no parameters field in the stored type info', () => {
|
||||
reflector.registerType(TestObj, new ReflectionInfo());
|
||||
expect(reflector.parameters(TestObj)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('propMetadata', () => {
|
||||
@ -136,11 +98,6 @@ export function main() {
|
||||
expect(p['c']).toEqual([new PropDecorator('p3')]);
|
||||
expect(p['someMethod']).toEqual([new PropDecorator('p4')]);
|
||||
});
|
||||
|
||||
it('should return registered meta if available', () => {
|
||||
reflector.registerType(TestObj, new ReflectionInfo(null, null, null, null, {'a': [1, 2]}));
|
||||
expect(reflector.propMetadata(TestObj)).toEqual({'a': [1, 2]});
|
||||
});
|
||||
});
|
||||
|
||||
describe('annotations', () => {
|
||||
@ -149,11 +106,6 @@ export function main() {
|
||||
expect(p).toEqual([new ClassDecorator({value: 'class'})]);
|
||||
});
|
||||
|
||||
it('should return registered annotations if available', () => {
|
||||
reflector.registerType(TestObj, new ReflectionInfo([1, 2]));
|
||||
expect(reflector.annotations(TestObj)).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
it('should work for a class without annotations', () => {
|
||||
const p = reflector.annotations(ClassWithoutDecorators);
|
||||
expect(p).toEqual([]);
|
||||
@ -165,11 +117,6 @@ export function main() {
|
||||
const getA = reflector.getter('a');
|
||||
expect(getA(new TestObj(1, 2))).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return a registered getter if available', () => {
|
||||
reflector.registerGetters({'abc': (obj: any) => 'fake'});
|
||||
expect(reflector.getter('abc')('anything')).toEqual('fake');
|
||||
});
|
||||
});
|
||||
|
||||
describe('setter', () => {
|
||||
@ -179,15 +126,6 @@ export function main() {
|
||||
setA(obj, 100);
|
||||
expect(obj.a).toEqual(100);
|
||||
});
|
||||
|
||||
it('should return a registered setter if available', () => {
|
||||
let updateMe: any;
|
||||
|
||||
reflector.registerSetters({'abc': (obj: any, value: any) => { updateMe = value; }});
|
||||
reflector.setter('abc')('anything', 'fake');
|
||||
|
||||
expect(updateMe).toEqual('fake');
|
||||
});
|
||||
});
|
||||
|
||||
describe('method', () => {
|
||||
@ -196,11 +134,6 @@ export function main() {
|
||||
const obj = new TestObj(1, 2);
|
||||
expect(func(obj, ['value'])).toEqual('value');
|
||||
});
|
||||
|
||||
it('should return a registered method if available', () => {
|
||||
reflector.registerMethods({'abc': (obj: any, args: any) => args});
|
||||
expect(reflector.method('abc')('anything', ['fake'])).toEqual(['fake']);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user