perf(core): Remove decorator DSL which depends on Reflect
BREAKING CHANGE It is no longer possible to declare classes in this format. ``` Component({...}). Class({ constructor: function() {...} }) ``` This format would only work with JIT and with ES5. This mode doesn’t allow build tools like Webpack to process and optimize the code, which results in prohibitively large bundles. We are removing this API because we are trying to ensure that everyone is on the fast path by default, and it is not possible to get on the fast path using the ES5 DSL. The replacement is to use TypeScript and `@Decorator` format. ``` @Component({...}) class { constructor() {...} } ```
This commit is contained in:
@ -13,8 +13,20 @@ export interface PlatformReflectionCapabilities {
|
||||
isReflectionEnabled(): boolean;
|
||||
factory(type: Type<any>): Function;
|
||||
hasLifecycleHook(type: any, lcProperty: string): boolean;
|
||||
|
||||
/**
|
||||
* Return a list of annotations/types for constructor parameters
|
||||
*/
|
||||
parameters(type: Type<any>): any[][];
|
||||
|
||||
/**
|
||||
* Return a list of annotations declared on the class
|
||||
*/
|
||||
annotations(type: Type<any>): any[];
|
||||
|
||||
/**
|
||||
* Return a object literal which describes the annotations on Class fields/properties.
|
||||
*/
|
||||
propMetadata(typeOrFunc: Type<any>): {[key: string]: any[]};
|
||||
getter(name: string): GetterFn;
|
||||
setter(name: string): SetterFn;
|
||||
|
@ -8,9 +8,12 @@
|
||||
|
||||
import {Type, isType} from '../type';
|
||||
import {global, stringify} from '../util';
|
||||
import {ANNOTATIONS, PARAMETERS, PROP_METADATA} from '../util/decorators';
|
||||
|
||||
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
|
||||
import {GetterFn, MethodFn, SetterFn} from './types';
|
||||
|
||||
|
||||
/**
|
||||
* Attention: This regex has to hold even if the code is minified!
|
||||
*/
|
||||
@ -85,12 +88,11 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
}
|
||||
|
||||
// API for metadata created by invoking the decorators.
|
||||
if (this._reflect != null && this._reflect.getOwnMetadata != null) {
|
||||
const paramAnnotations = this._reflect.getOwnMetadata('parameters', type);
|
||||
const paramTypes = this._reflect.getOwnMetadata('design:paramtypes', type);
|
||||
if (paramTypes || paramAnnotations) {
|
||||
return this._zipTypesAndAnnotations(paramTypes, paramAnnotations);
|
||||
}
|
||||
const paramAnnotations = type.hasOwnProperty(PARAMETERS) && (type as any)[PARAMETERS];
|
||||
const paramTypes = this._reflect && this._reflect.getOwnMetadata &&
|
||||
this._reflect.getOwnMetadata('design:paramtypes', type);
|
||||
if (paramTypes || paramAnnotations) {
|
||||
return this._zipTypesAndAnnotations(paramTypes, paramAnnotations);
|
||||
}
|
||||
|
||||
// If a class has no decorators, at least create metadata
|
||||
@ -130,8 +132,8 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
}
|
||||
|
||||
// API for metadata created by invoking the decorators.
|
||||
if (this._reflect && this._reflect.getOwnMetadata) {
|
||||
return this._reflect.getOwnMetadata('annotations', typeOrFunc);
|
||||
if (typeOrFunc.hasOwnProperty(ANNOTATIONS)) {
|
||||
return (typeOrFunc as any)[ANNOTATIONS];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -169,8 +171,8 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||
}
|
||||
|
||||
// API for metadata created by invoking the decorators.
|
||||
if (this._reflect && this._reflect.getOwnMetadata) {
|
||||
return this._reflect.getOwnMetadata('propMetadata', typeOrFunc);
|
||||
if (typeOrFunc.hasOwnProperty(PROP_METADATA)) {
|
||||
return (typeOrFunc as any)[PROP_METADATA];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user