MCPcopy Create free account
hub / github.com/angular/angular / compileNgModule

Function compileNgModule

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

Source from the content-addressed store, hash-verified

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