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 {noSideEffects} from './closure';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An interface implemented by all Angular type decorators, which allows them to be used as
|
||||
* decorators as well as Angular syntax.
|
||||
|
@ -44,6 +48,7 @@ export function makeDecorator<T>(
|
|||
additionalProcessing?: (type: Type<T>) => void,
|
||||
typeFn?: (type: Type<T>, ...args: any[]) => void):
|
||||
{new (...args: any[]): any; (...args: any[]): any; (...args: any[]): (cls: any) => any;} {
|
||||
return noSideEffects(() => {
|
||||
const metaCtor = makeMetadataCtor(props);
|
||||
|
||||
function DecoratorFactory(
|
||||
|
@ -77,6 +82,7 @@ export function makeDecorator<T>(
|
|||
DecoratorFactory.prototype.ngMetadataName = name;
|
||||
(DecoratorFactory as any).annotationCls = DecoratorFactory;
|
||||
return DecoratorFactory as any;
|
||||
});
|
||||
}
|
||||
|
||||
function makeMetadataCtor(props?: (...args: any[]) => any): any {
|
||||
|
@ -92,6 +98,7 @@ function makeMetadataCtor(props?: (...args: any[]) => any): any {
|
|||
|
||||
export function makeParamDecorator(
|
||||
name: string, props?: (...args: any[]) => any, parentClass?: any): any {
|
||||
return noSideEffects(() => {
|
||||
const metaCtor = makeMetadataCtor(props);
|
||||
function ParamDecoratorFactory(
|
||||
this: unknown | typeof ParamDecoratorFactory, ...args: any[]): any {
|
||||
|
@ -127,14 +134,17 @@ export function makeParamDecorator(
|
|||
ParamDecoratorFactory.prototype.ngMetadataName = name;
|
||||
(<any>ParamDecoratorFactory).annotationCls = ParamDecoratorFactory;
|
||||
return ParamDecoratorFactory;
|
||||
});
|
||||
}
|
||||
|
||||
export function makePropDecorator(
|
||||
name: string, props?: (...args: any[]) => any, parentClass?: any,
|
||||
additionalProcessing?: (target: any, name: string, ...args: any[]) => void): any {
|
||||
return noSideEffects(() => {
|
||||
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) {
|
||||
metaCtor.apply(this, args);
|
||||
return this;
|
||||
|
@ -165,4 +175,5 @@ export function makePropDecorator(
|
|||
PropDecoratorFactory.prototype.ngMetadataName = name;
|
||||
(<any>PropDecoratorFactory).annotationCls = PropDecoratorFactory;
|
||||
return PropDecoratorFactory;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -220,5 +220,8 @@
|
|||
},
|
||||
{
|
||||
"name": "ɵɵinject"
|
||||
},
|
||||
{
|
||||
"name": "noSideEffects"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue