fix(ivy): align NgModule registration timing with ViewEngine (#30244)
Currently in Ivy `NgModule` registration happens when the class is declared, however this is inconsistent with ViewEngine and requires extra generated code. These changes remove the generated code for `registerModuleFactory`, pass the id through to the `ngModuleDef` and do the module registration inside `NgModuleFactory.create`. This PR resolves FW-1285. PR Close #30244
This commit is contained in:

committed by
Alex Rickabaugh

parent
2f35dbfd3b
commit
f74373f2dd
@ -67,6 +67,9 @@ export interface R3NgModuleMetadata {
|
||||
* The set of schemas that declare elements to be allowed in the NgModule.
|
||||
*/
|
||||
schemas: R3Reference[]|null;
|
||||
|
||||
/** Unique ID or expression representing the unique ID of an NgModule. */
|
||||
id: o.Expression|null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +84,8 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||
exports,
|
||||
schemas,
|
||||
containsForwardDecls,
|
||||
emitInline
|
||||
emitInline,
|
||||
id
|
||||
} = meta;
|
||||
|
||||
const additionalStatements: o.Statement[] = [];
|
||||
@ -93,7 +97,8 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||
declarations: o.Expression,
|
||||
imports: o.Expression,
|
||||
exports: o.Expression,
|
||||
schemas: o.LiteralArrayExpr
|
||||
schemas: o.LiteralArrayExpr,
|
||||
id: o.Expression
|
||||
};
|
||||
|
||||
// Only generate the keys in the metadata if the arrays have values.
|
||||
@ -130,6 +135,10 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef {
|
||||
definitionMap.schemas = o.literalArr(schemas.map(ref => ref.value));
|
||||
}
|
||||
|
||||
if (id) {
|
||||
definitionMap.id = id;
|
||||
}
|
||||
|
||||
const expression = o.importExpr(R3.defineNgModule).callFn([mapToMapExpression(definitionMap)]);
|
||||
const type = new o.ExpressionType(o.importExpr(R3.NgModuleDefWithMeta, [
|
||||
new o.ExpressionType(moduleType), tupleTypeOf(declarations), tupleTypeOf(imports),
|
||||
|
Reference in New Issue
Block a user