Skip to content

Commit 71ee417

Browse files
JoostKdylhunn
authored andcommitted
refactor(core): remove unused logic from reflection capabilities (angular#45335)
This commit removes a bunch of methodss from `ReflectionCapabilities` as they have gone unused. This also removes `Reflector` as it doesn't serve any purpose and it is not exposed as public API, so can be safely removed. PR Close angular#45335
1 parent 8198bb9 commit 71ee417

11 files changed

Lines changed: 5 additions & 929 deletions

File tree

modules/benchmarks/src/old/di/di_benchmark.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@
77
*/
88

99
import {Injectable, ReflectiveInjector, ReflectiveKey} from '@angular/core';
10-
import {reflector} from '@angular/core/src/reflection/reflection';
11-
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
1210
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
1311
import {bindAction, getIntParameter, microBenchmark} from '@angular/testing/src/benchmark_util';
1412

1513
let count = 0;
1614

17-
function setupReflector() {
18-
reflector.reflectionCapabilities = new ReflectionCapabilities();
19-
}
20-
2115
export function main() {
2216
BrowserDomAdapter.makeCurrent();
2317
const iterations = getIntParameter('iterations');
2418

2519
// This benchmark does not use bootstrap and needs to create a reflector
26-
setupReflector();
2720
const bindings = [A, B, C, D, E];
2821
const injector = ReflectiveInjector.resolveAndCreate(bindings);
2922

packages/core/src/core_private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export {DEFAULT_LOCALE_ID as ɵDEFAULT_LOCALE_ID} from './i18n/localization';
2222
export {ComponentFactory as ɵComponentFactory} from './linker/component_factory';
2323
export {clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponentResourcesQueue, resolveComponentResources as ɵresolveComponentResources} from './metadata/resource_loading';
2424
export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/reflection_capabilities';
25-
export {GetterFn as ɵGetterFn, MethodFn as ɵMethodFn, SetterFn as ɵSetterFn} from './reflection/types';
2625
export {allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, BypassType as ɵBypassType, getSanitizationBypassType as ɵgetSanitizationBypassType, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue, unwrapSafeValue as ɵunwrapSafeValue} from './sanitization/bypass';
2726
export {_sanitizeHtml as ɵ_sanitizeHtml} from './sanitization/html_sanitizer';
2827
export {_sanitizeUrl as ɵ_sanitizeUrl} from './sanitization/url_sanitizer';

packages/core/src/di/reflective_provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88

99
import {Type} from '../interface/type';
10-
import {reflector} from '../reflection/reflection';
1110

1211
import {resolveForwardRef} from './forward_ref';
1312
import {InjectionToken} from './injection_token';
1413
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './interface/provider';
14+
import {getReflect} from './jit/util';
1515
import {Inject, Optional, Self, SkipSelf} from './metadata';
1616
import {invalidProviderError, mixingMultiProvidersWithRegularProvidersError, noAnnotationError} from './reflective_errors';
1717
import {ReflectiveKey} from './reflective_key';
@@ -107,7 +107,7 @@ function resolveReflectiveFactory(provider: NormalizedProvider): ResolvedReflect
107107
let resolvedDeps: ReflectiveDependency[];
108108
if (provider.useClass) {
109109
const useClass = resolveForwardRef(provider.useClass);
110-
factoryFn = reflector.factory(useClass);
110+
factoryFn = getReflect().factory(useClass);
111111
resolvedDeps = _dependenciesFor(useClass);
112112
} else if (provider.useExisting) {
113113
factoryFn = (aliasInstance: any) => aliasInstance;
@@ -211,7 +211,7 @@ export function constructDependencies(
211211
}
212212

213213
function _dependenciesFor(typeOrFunc: any): ReflectiveDependency[] {
214-
const params = reflector.parameters(typeOrFunc);
214+
const params = getReflect().parameters(typeOrFunc);
215215

216216
if (!params) return [];
217217
if (params.some(p => p == null)) {

packages/core/src/di/util.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

packages/core/src/reflection/platform_reflection_capabilities.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
*/
88

99
import {Type} from '../interface/type';
10-
import {GetterFn, MethodFn, SetterFn} from './types';
1110

1211
export interface PlatformReflectionCapabilities {
13-
isReflectionEnabled(): boolean;
1412
factory(type: Type<any>): Function;
1513
hasLifecycleHook(type: any, lcProperty: string): boolean;
16-
guards(type: any): {[key: string]: any};
1714

1815
/**
1916
* Return a list of annotations/types for constructor parameters
@@ -29,11 +26,4 @@ export interface PlatformReflectionCapabilities {
2926
* Return a object literal which describes the annotations on Class fields/properties.
3027
*/
3128
propMetadata(typeOrFunc: Type<any>): {[key: string]: any[]};
32-
getter(name: string): GetterFn;
33-
setter(name: string): SetterFn;
34-
method(name: string): MethodFn;
35-
importUri(type: Type<any>): string;
36-
resourceUri(type: Type<any>): string;
37-
resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any;
38-
resolveEnum(enumIdentifier: any, name: string): any;
3929
}

packages/core/src/reflection/reflection.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/core/src/reflection/reflection_capabilities.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import {isType, Type} from '../interface/type';
1010
import {newArray} from '../util/array_utils';
1111
import {ANNOTATIONS, PARAMETERS, PROP_METADATA} from '../util/decorators';
1212
import {global} from '../util/global';
13-
import {stringify} from '../util/stringify';
1413

1514
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
16-
import {GetterFn, MethodFn, SetterFn} from './types';
1715

1816

1917

@@ -86,10 +84,6 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
8684
this._reflect = reflect || global['Reflect'];
8785
}
8886

89-
isReflectionEnabled(): boolean {
90-
return true;
91-
}
92-
9387
factory<T>(t: Type<T>): (args: any[]) => T {
9488
return (...args: any[]) => new t(...args);
9589
}
@@ -280,45 +274,6 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
280274
hasLifecycleHook(type: any, lcProperty: string): boolean {
281275
return type instanceof Type && lcProperty in type.prototype;
282276
}
283-
284-
guards(type: any): {[key: string]: any} {
285-
return {};
286-
}
287-
288-
getter(name: string): GetterFn {
289-
return <GetterFn>new Function('o', 'return o.' + name + ';');
290-
}
291-
292-
setter(name: string): SetterFn {
293-
return <SetterFn>new Function('o', 'v', 'return o.' + name + ' = v;');
294-
}
295-
296-
method(name: string): MethodFn {
297-
const functionBody = `if (!o.${name}) throw new Error('"${name}" is undefined');
298-
return o.${name}.apply(o, args);`;
299-
return <MethodFn>new Function('o', 'args', functionBody);
300-
}
301-
302-
// There is not a concept of import uri in Js, but this is useful in developing Dart applications.
303-
importUri(type: any): string {
304-
// StaticSymbol
305-
if (typeof type === 'object' && type['filePath']) {
306-
return type['filePath'];
307-
}
308-
// Runtime type
309-
return `./${stringify(type)}`;
310-
}
311-
312-
resourceUri(type: any): string {
313-
return `./${stringify(type)}`;
314-
}
315-
316-
resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any {
317-
return runtime;
318-
}
319-
resolveEnum(enumIdentifier: any, name: string): any {
320-
return enumIdentifier[name];
321-
}
322277
}
323278

324279
function convertTsickleDecoratorIntoMetadata(decoratorInvocations: any[]): any[] {

packages/core/src/reflection/reflector.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/core/src/reflection/types.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)