refactor(core): remove `getFactoryOf` from `angularCoreDiEnv` (#41040)
This function is never actually generated directly so it can be removed from the context passed to the JIT compiler. PR Close #41040
This commit is contained in:
parent
89563442b8
commit
326f167075
|
@ -71,12 +71,6 @@ export interface R3ConstructorFactoryMetadata {
|
||||||
export enum R3FactoryDelegateType {
|
export enum R3FactoryDelegateType {
|
||||||
Class,
|
Class,
|
||||||
Function,
|
Function,
|
||||||
Factory,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface R3DelegatedFactoryMetadata extends R3ConstructorFactoryMetadata {
|
|
||||||
delegate: o.Expression;
|
|
||||||
delegateType: R3FactoryDelegateType.Factory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface R3DelegatedFnOrClassMetadata extends R3ConstructorFactoryMetadata {
|
export interface R3DelegatedFnOrClassMetadata extends R3ConstructorFactoryMetadata {
|
||||||
|
@ -89,8 +83,8 @@ export interface R3ExpressionFactoryMetadata extends R3ConstructorFactoryMetadat
|
||||||
expression: o.Expression;
|
expression: o.Expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type R3FactoryMetadata = R3ConstructorFactoryMetadata|R3DelegatedFactoryMetadata|
|
export type R3FactoryMetadata =
|
||||||
R3DelegatedFnOrClassMetadata|R3ExpressionFactoryMetadata;
|
R3ConstructorFactoryMetadata|R3DelegatedFnOrClassMetadata|R3ExpressionFactoryMetadata;
|
||||||
|
|
||||||
export enum R3FactoryTarget {
|
export enum R3FactoryTarget {
|
||||||
Directive = 0,
|
Directive = 0,
|
||||||
|
@ -239,20 +233,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
|
if (isDelegatedMetadata(meta)) {
|
||||||
const delegateFactory = o.variable(`ɵ${meta.name}_BaseFactory`);
|
|
||||||
const getFactoryOf = o.importExpr(R3.getFactoryOf);
|
|
||||||
if (meta.delegate.isEquivalent(meta.internalType)) {
|
|
||||||
throw new Error(`Illegal state: compiling factory that delegates to itself`);
|
|
||||||
}
|
|
||||||
const delegateFactoryStmt =
|
|
||||||
delegateFactory.set(getFactoryOf.callFn([meta.delegate])).toDeclStmt(o.INFERRED_TYPE, [
|
|
||||||
o.StmtModifier.Exported, o.StmtModifier.Final
|
|
||||||
]);
|
|
||||||
|
|
||||||
statements.push(delegateFactoryStmt);
|
|
||||||
retExpr = makeConditionalFactory(delegateFactory.callFn([]));
|
|
||||||
} else if (isDelegatedMetadata(meta)) {
|
|
||||||
// This type is created with a delegated factory. If a type parameter is not specified, call
|
// This type is created with a delegated factory. If a type parameter is not specified, call
|
||||||
// the factory instead.
|
// the factory instead.
|
||||||
const delegateArgs =
|
const delegateArgs =
|
||||||
|
@ -418,8 +399,7 @@ export function dependenciesFromGlobalMetadata(
|
||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDelegatedMetadata(meta: R3FactoryMetadata): meta is R3DelegatedFactoryMetadata|
|
function isDelegatedMetadata(meta: R3FactoryMetadata): meta is R3DelegatedFnOrClassMetadata {
|
||||||
R3DelegatedFnOrClassMetadata {
|
|
||||||
return (meta as any).delegateType !== undefined;
|
return (meta as any).delegateType !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -313,11 +313,6 @@ export class Identifiers {
|
||||||
|
|
||||||
static listener: o.ExternalReference = {name: 'ɵɵlistener', moduleName: CORE};
|
static listener: o.ExternalReference = {name: 'ɵɵlistener', moduleName: CORE};
|
||||||
|
|
||||||
static getFactoryOf: o.ExternalReference = {
|
|
||||||
name: 'ɵɵgetFactoryOf',
|
|
||||||
moduleName: CORE,
|
|
||||||
};
|
|
||||||
|
|
||||||
static getInheritedFactory: o.ExternalReference = {
|
static getInheritedFactory: o.ExternalReference = {
|
||||||
name: 'ɵɵgetInheritedFactory',
|
name: 'ɵɵgetInheritedFactory',
|
||||||
moduleName: CORE,
|
moduleName: CORE,
|
||||||
|
|
|
@ -5,13 +5,8 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Type} from '../../interface/type';
|
|
||||||
import {isForwardRef, resolveForwardRef} from '../forward_ref';
|
|
||||||
import {ɵɵinject, ɵɵinvalidFactoryDep} from '../injector_compatibility';
|
import {ɵɵinject, ɵɵinvalidFactoryDep} from '../injector_compatibility';
|
||||||
import {getInjectableDef, getInjectorDef, ɵɵdefineInjectable, ɵɵdefineInjector} from '../interface/defs';
|
import {ɵɵdefineInjectable, ɵɵdefineInjector} from '../interface/defs';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of the @angular/core API surface used in generated expressions to the actual symbols.
|
* A mapping of the @angular/core API surface used in generated expressions to the actual symbols.
|
||||||
|
@ -22,23 +17,5 @@ export const angularCoreDiEnv: {[name: string]: Function} = {
|
||||||
'ɵɵdefineInjectable': ɵɵdefineInjectable,
|
'ɵɵdefineInjectable': ɵɵdefineInjectable,
|
||||||
'ɵɵdefineInjector': ɵɵdefineInjector,
|
'ɵɵdefineInjector': ɵɵdefineInjector,
|
||||||
'ɵɵinject': ɵɵinject,
|
'ɵɵinject': ɵɵinject,
|
||||||
'ɵɵgetFactoryOf': getFactoryOf,
|
|
||||||
'ɵɵinvalidFactoryDep': ɵɵinvalidFactoryDep,
|
'ɵɵinvalidFactoryDep': ɵɵinvalidFactoryDep,
|
||||||
};
|
};
|
||||||
|
|
||||||
function getFactoryOf<T>(type: Type<any>): ((type?: Type<T>) => T)|null {
|
|
||||||
const typeAny = type as any;
|
|
||||||
|
|
||||||
if (isForwardRef(type)) {
|
|
||||||
return (() => {
|
|
||||||
const factory = getFactoryOf<T>(resolveForwardRef(typeAny));
|
|
||||||
return factory ? factory() : null;
|
|
||||||
}) as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
const def = getInjectableDef<T>(typeAny) || getInjectorDef<T>(typeAny);
|
|
||||||
if (!def || def.factory === undefined) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return def.factory;
|
|
||||||
}
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ export const angularCoreEnv: {[name: string]: Function} =
|
||||||
'ɵɵdefineNgModule': r3.ɵɵdefineNgModule,
|
'ɵɵdefineNgModule': r3.ɵɵdefineNgModule,
|
||||||
'ɵɵdefinePipe': r3.ɵɵdefinePipe,
|
'ɵɵdefinePipe': r3.ɵɵdefinePipe,
|
||||||
'ɵɵdirectiveInject': r3.ɵɵdirectiveInject,
|
'ɵɵdirectiveInject': r3.ɵɵdirectiveInject,
|
||||||
'ɵɵgetFactoryOf': r3.ɵɵgetFactoryOf,
|
|
||||||
'ɵɵgetInheritedFactory': r3.ɵɵgetInheritedFactory,
|
'ɵɵgetInheritedFactory': r3.ɵɵgetInheritedFactory,
|
||||||
'ɵɵinject': ɵɵinject,
|
'ɵɵinject': ɵɵinject,
|
||||||
'ɵɵinjectAttribute': r3.ɵɵinjectAttribute,
|
'ɵɵinjectAttribute': r3.ɵɵinjectAttribute,
|
||||||
|
|
Loading…
Reference in New Issue