fix(core): add noSideEffects()
to make*Decorator()
functions (#35769)
This causes all the `make*Decorator()` functions to be considered pure and to be eligible for associated tree shaking by Closure. PR Close #35769
This commit is contained in:
parent
4052dd8188
commit
dc6a7918e3
@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
import {Type} from '../interface/type';
|
import {Type} from '../interface/type';
|
||||||
|
|
||||||
|
import {noSideEffects} from './closure';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface implemented by all Angular type decorators, which allows them to be used as
|
* An interface implemented by all Angular type decorators, which allows them to be used as
|
||||||
* decorators as well as Angular syntax.
|
* decorators as well as Angular syntax.
|
||||||
@ -44,6 +48,7 @@ export function makeDecorator<T>(
|
|||||||
additionalProcessing?: (type: Type<T>) => void,
|
additionalProcessing?: (type: Type<T>) => void,
|
||||||
typeFn?: (type: Type<T>, ...args: any[]) => void):
|
typeFn?: (type: Type<T>, ...args: any[]) => void):
|
||||||
{new (...args: any[]): any; (...args: any[]): any; (...args: any[]): (cls: any) => any;} {
|
{new (...args: any[]): any; (...args: any[]): any; (...args: any[]): (cls: any) => any;} {
|
||||||
|
return noSideEffects(() => {
|
||||||
const metaCtor = makeMetadataCtor(props);
|
const metaCtor = makeMetadataCtor(props);
|
||||||
|
|
||||||
function DecoratorFactory(
|
function DecoratorFactory(
|
||||||
@ -77,6 +82,7 @@ export function makeDecorator<T>(
|
|||||||
DecoratorFactory.prototype.ngMetadataName = name;
|
DecoratorFactory.prototype.ngMetadataName = name;
|
||||||
(DecoratorFactory as any).annotationCls = DecoratorFactory;
|
(DecoratorFactory as any).annotationCls = DecoratorFactory;
|
||||||
return DecoratorFactory as any;
|
return DecoratorFactory as any;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeMetadataCtor(props?: (...args: any[]) => any): any {
|
function makeMetadataCtor(props?: (...args: any[]) => any): any {
|
||||||
@ -92,6 +98,7 @@ function makeMetadataCtor(props?: (...args: any[]) => any): any {
|
|||||||
|
|
||||||
export function makeParamDecorator(
|
export function makeParamDecorator(
|
||||||
name: string, props?: (...args: any[]) => any, parentClass?: any): any {
|
name: string, props?: (...args: any[]) => any, parentClass?: any): any {
|
||||||
|
return noSideEffects(() => {
|
||||||
const metaCtor = makeMetadataCtor(props);
|
const metaCtor = makeMetadataCtor(props);
|
||||||
function ParamDecoratorFactory(
|
function ParamDecoratorFactory(
|
||||||
this: unknown | typeof ParamDecoratorFactory, ...args: any[]): any {
|
this: unknown | typeof ParamDecoratorFactory, ...args: any[]): any {
|
||||||
@ -127,14 +134,17 @@ export function makeParamDecorator(
|
|||||||
ParamDecoratorFactory.prototype.ngMetadataName = name;
|
ParamDecoratorFactory.prototype.ngMetadataName = name;
|
||||||
(<any>ParamDecoratorFactory).annotationCls = ParamDecoratorFactory;
|
(<any>ParamDecoratorFactory).annotationCls = ParamDecoratorFactory;
|
||||||
return ParamDecoratorFactory;
|
return ParamDecoratorFactory;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makePropDecorator(
|
export function makePropDecorator(
|
||||||
name: string, props?: (...args: any[]) => any, parentClass?: any,
|
name: string, props?: (...args: any[]) => any, parentClass?: any,
|
||||||
additionalProcessing?: (target: any, name: string, ...args: any[]) => void): any {
|
additionalProcessing?: (target: any, name: string, ...args: any[]) => void): any {
|
||||||
|
return noSideEffects(() => {
|
||||||
const metaCtor = makeMetadataCtor(props);
|
const metaCtor = makeMetadataCtor(props);
|
||||||
|
|
||||||
function PropDecoratorFactory(this: unknown | typeof PropDecoratorFactory, ...args: any[]): any {
|
function PropDecoratorFactory(
|
||||||
|
this: unknown | typeof PropDecoratorFactory, ...args: any[]): any {
|
||||||
if (this instanceof PropDecoratorFactory) {
|
if (this instanceof PropDecoratorFactory) {
|
||||||
metaCtor.apply(this, args);
|
metaCtor.apply(this, args);
|
||||||
return this;
|
return this;
|
||||||
@ -165,4 +175,5 @@ export function makePropDecorator(
|
|||||||
PropDecoratorFactory.prototype.ngMetadataName = name;
|
PropDecoratorFactory.prototype.ngMetadataName = name;
|
||||||
(<any>PropDecoratorFactory).annotationCls = PropDecoratorFactory;
|
(<any>PropDecoratorFactory).annotationCls = PropDecoratorFactory;
|
||||||
return PropDecoratorFactory;
|
return PropDecoratorFactory;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -220,5 +220,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ɵɵinject"
|
"name": "ɵɵinject"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "noSideEffects"
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
x
Reference in New Issue
Block a user