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:
Pete Bacon Darwin 2021-03-02 11:57:48 +00:00 committed by Andrew Kushnir
parent 89563442b8
commit 326f167075
4 changed files with 5 additions and 54 deletions

View File

@ -71,12 +71,6 @@ export interface R3ConstructorFactoryMetadata {
export enum R3FactoryDelegateType {
Class,
Function,
Factory,
}
export interface R3DelegatedFactoryMetadata extends R3ConstructorFactoryMetadata {
delegate: o.Expression;
delegateType: R3FactoryDelegateType.Factory;
}
export interface R3DelegatedFnOrClassMetadata extends R3ConstructorFactoryMetadata {
@ -89,8 +83,8 @@ export interface R3ExpressionFactoryMetadata extends R3ConstructorFactoryMetadat
expression: o.Expression;
}
export type R3FactoryMetadata = R3ConstructorFactoryMetadata|R3DelegatedFactoryMetadata|
R3DelegatedFnOrClassMetadata|R3ExpressionFactoryMetadata;
export type R3FactoryMetadata =
R3ConstructorFactoryMetadata|R3DelegatedFnOrClassMetadata|R3ExpressionFactoryMetadata;
export enum R3FactoryTarget {
Directive = 0,
@ -239,20 +233,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3FactoryFn {
return r;
}
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
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)) {
if (isDelegatedMetadata(meta)) {
// This type is created with a delegated factory. If a type parameter is not specified, call
// the factory instead.
const delegateArgs =
@ -418,8 +399,7 @@ export function dependenciesFromGlobalMetadata(
return deps;
}
function isDelegatedMetadata(meta: R3FactoryMetadata): meta is R3DelegatedFactoryMetadata|
R3DelegatedFnOrClassMetadata {
function isDelegatedMetadata(meta: R3FactoryMetadata): meta is R3DelegatedFnOrClassMetadata {
return (meta as any).delegateType !== undefined;
}

View File

@ -313,11 +313,6 @@ export class Identifiers {
static listener: o.ExternalReference = {name: 'ɵɵlistener', moduleName: CORE};
static getFactoryOf: o.ExternalReference = {
name: 'ɵɵgetFactoryOf',
moduleName: CORE,
};
static getInheritedFactory: o.ExternalReference = {
name: 'ɵɵgetInheritedFactory',
moduleName: CORE,

View File

@ -5,13 +5,8 @@
* 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
*/
import {Type} from '../../interface/type';
import {isForwardRef, resolveForwardRef} from '../forward_ref';
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.
@ -22,23 +17,5 @@ export const angularCoreDiEnv: {[name: string]: Function} = {
'ɵɵdefineInjectable': ɵɵdefineInjectable,
'ɵɵdefineInjector': ɵɵdefineInjector,
'ɵɵinject': ɵɵinject,
'ɵɵgetFactoryOf': getFactoryOf,
'ɵɵ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;
}

View File

@ -37,7 +37,6 @@ export const angularCoreEnv: {[name: string]: Function} =
'ɵɵdefineNgModule': r3.ɵɵdefineNgModule,
'ɵɵdefinePipe': r3.ɵɵdefinePipe,
'ɵɵdirectiveInject': r3.ɵɵdirectiveInject,
'ɵɵgetFactoryOf': r3.ɵɵgetFactoryOf,
'ɵɵgetInheritedFactory': r3.ɵɵgetInheritedFactory,
'ɵɵinject': ɵɵinject,
'ɵɵinjectAttribute': r3.ɵɵinjectAttribute,