feat(ivy): produce Renderer2 back-patching and factories. (#22506)
Produces back-patch as described in the #22235 and referenced in #22480. This just contains the compiler implementations and the corresponding unit tests. Connecting the dots as described in #22480 will be in a follow on change. PR Close #22506
This commit is contained in:

committed by
Kara Erickson

parent
5412e10bcd
commit
b0b9ca3386
46
packages/compiler/src/render3/r3_module_factory_compiler.ts
Normal file
46
packages/compiler/src/render3/r3_module_factory_compiler.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {StaticReflector} from '../aot/static_reflector';
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeSummary, CompileTypeMetadata, identifierName} from '../compile_metadata';
|
||||
import {CompileMetadataResolver} from '../metadata_resolver';
|
||||
import * as o from '../output/output_ast';
|
||||
import {OutputContext} from '../util';
|
||||
|
||||
import {Identifiers as R3} from './r3_identifiers';
|
||||
|
||||
/**
|
||||
* Write a Renderer2 compatibility module factory to the output context.
|
||||
*/
|
||||
export function compileModuleFactory(
|
||||
outputCtx: OutputContext, module: CompileNgModuleMetadata,
|
||||
backPatchReferenceOf: (module: CompileTypeMetadata) => o.Expression,
|
||||
resolver: CompileMetadataResolver) {
|
||||
const ngModuleFactoryVar = `${identifierName(module.type)}NgFactory`;
|
||||
|
||||
const parentInjector = 'parentInjector';
|
||||
const createFunction = o.fn(
|
||||
[new o.FnParam(parentInjector, o.DYNAMIC_TYPE)],
|
||||
[new o.IfStmt(
|
||||
o.THIS_EXPR.prop(R3.PATCH_DEPS).notIdentical(o.literal(true, o.INFERRED_TYPE)),
|
||||
[
|
||||
o.THIS_EXPR.prop(R3.PATCH_DEPS).set(o.literal(true, o.INFERRED_TYPE)).toStmt(),
|
||||
backPatchReferenceOf(module.type).callFn([]).toStmt()
|
||||
])],
|
||||
o.INFERRED_TYPE, null, `${ngModuleFactoryVar}_Create`);
|
||||
|
||||
const moduleFactoryLiteral = o.literalMap([
|
||||
{key: 'moduleType', value: outputCtx.importExpr(module.type.reference), quoted: false},
|
||||
{key: 'create', value: createFunction, quoted: false}
|
||||
]);
|
||||
|
||||
outputCtx.statements.push(
|
||||
o.variable(ngModuleFactoryVar).set(moduleFactoryLiteral).toDeclStmt(o.DYNAMIC_TYPE, [
|
||||
o.StmtModifier.Exported, o.StmtModifier.Final
|
||||
]));
|
||||
}
|
Reference in New Issue
Block a user