MCPcopy Index your code
hub / github.com/angular/angular / compileNgModule

Function compileNgModule

packages/compiler/src/render3/r3_module_compiler.ts:229–289  ·  view source on GitHub ↗
(meta: R3NgModuleMetadata)

Source from the content-addressed store, hash-verified

227 * Construct an `R3NgModuleDef` for the given `R3NgModuleMetadata`.
228 */
229export function compileNgModule(meta: R3NgModuleMetadata): R3CompiledExpression {
230 const statements: o.Statement[] = [];
231 const definitionMap = new DefinitionMap<R3NgModuleDefMap>();
232 definitionMap.set('type', meta.type.value);
233
234 // Assign bootstrap definition. In local compilation mode (i.e., for
235 // `R3NgModuleMetadataKind.LOCAL`) we assign the bootstrap field using the runtime
236 // `ɵɵsetNgModuleScope`.
237 if (meta.kind === R3NgModuleMetadataKind.Global && meta.bootstrap.length > 0) {
238 definitionMap.set('bootstrap', refsToArray(meta.bootstrap, meta.containsForwardDecls));
239 }
240
241 if (meta.selectorScopeMode === R3SelectorScopeMode.Inline) {
242 // If requested to emit scope information inline, pass the `declarations`, `imports` and
243 // `exports` to the `ɵɵdefineNgModule()` call directly.
244
245 if (meta.declarations.length > 0) {
246 definitionMap.set('declarations', refsToArray(meta.declarations, meta.containsForwardDecls));
247 }
248
249 if (meta.imports.length > 0) {
250 definitionMap.set('imports', refsToArray(meta.imports, meta.containsForwardDecls));
251 }
252
253 if (meta.exports.length > 0) {
254 definitionMap.set('exports', refsToArray(meta.exports, meta.containsForwardDecls));
255 }
256 } else if (meta.selectorScopeMode === R3SelectorScopeMode.SideEffect) {
257 // In this mode, scope information is not passed into `ɵɵdefineNgModule` as it
258 // would prevent tree-shaking of the declarations, imports and exports references. Instead, it's
259 // patched onto the NgModule definition with a `ɵɵsetNgModuleScope` call that's guarded by the
260 // `ngJitMode` flag.
261 const setNgModuleScopeCall = generateSetNgModuleScopeCall(meta);
262 if (setNgModuleScopeCall !== null) {
263 statements.push(setNgModuleScopeCall);
264 }
265 } else {
266 // Selector scope emit was not requested, so skip it.
267 }
268
269 if (meta.schemas !== null && meta.schemas.length > 0) {
270 definitionMap.set('schemas', o.literalArr(meta.schemas.map((ref) => ref.value)));
271 }
272
273 if (meta.id !== null) {
274 definitionMap.set('id', meta.id);
275
276 // Generate a side-effectful call to register this NgModule by its id, as per the semantics of
277 // NgModule ids.
278 statements.push(
279 o.importExpr(R3.registerNgModuleType).callFn([meta.type.value, meta.id]).toStmt(),
280 );
281 }
282
283 const expression = o
284 .importExpr(R3.defineNgModule)
285 .callFn([definitionMap.toLiteralMap()], undefined, true);
286 const type = createNgModuleType(meta);

Callers 4

compileNgModuleMethod · 0.90
compileFullMethod · 0.90
compileLocalMethod · 0.90

Calls 7

setMethod · 0.95
toLiteralMapMethod · 0.95
refsToArrayFunction · 0.90
createNgModuleTypeFunction · 0.85
mapMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…