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

Function compileNgModuleDef

packages/compiler-cli/preprocessor/src/processor.ts:2926–3259  ·  view source on GitHub ↗
(
  className: string,
  ngModule: nga.NgModuleMetadata,
  deps: any,
  ctx: HybridCompilerContext,
  classes: nga.ClassMetadata[] = [],
  classMeta?: nga.ClassMetadata,
  content?: MagicString | string,
  filePath?: string,
  diagnostics?: nga.NgDiagnostic[],
)

Source from the content-addressed store, hash-verified

2924}
2925
2926function compileNgModuleDef(
2927 className: string,
2928 ngModule: nga.NgModuleMetadata,
2929 deps: any,
2930 ctx: HybridCompilerContext,
2931 classes: nga.ClassMetadata[] = [],
2932 classMeta?: nga.ClassMetadata,
2933 content?: MagicString | string,
2934 filePath?: string,
2935 diagnostics?: nga.NgDiagnostic[],
2936): CompiledNgModuleDef {
2937 const {optimize, emitDeclarationOnly} = ctx;
2938 const {declarations, imports, injectorImports, exports, bootstrap} = ngModule;
2939 const sourceText = typeof content === 'string' ? content : content?.original;
2940
2941 const mapToVarArr = (names: nga.ReferenceMetadata[] | undefined) =>
2942 names ? o.literalArr(names.map((d) => refToExpression(d))) : null;
2943
2944 const mapToRefs = (names: nga.ReferenceMetadata[] | undefined) =>
2945 names
2946 ? names.map((ref) => ({
2947 value: refToExpression(ref),
2948 type: refToTypeExpression(ref),
2949 }))
2950 : [];
2951
2952 // LOCAL compilation mode emits NgModule imports/exports/declarations/bootstrap VERBATIM,
2953 // as `WrappedNodeExpr` of the raw AST node — no resolution/filtering/flattening — matching
2954 // ngtsc (ɵɵsetNgModuleScope metadata: handler.ts#L566-L603; ɵinj.imports: handler.ts#L670-L688).
2955 // https://github.com/angular/angular/blob/e3ac727/packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts#L566-L603
2956 // We reproduce "the raw node" by slicing the original source text at the captured span.
2957 const guards = ctx.complianceMode ? [] : (classMeta?.laterDeclarationReferences ?? []);
2958 const rawExprFromSpan = (
2959 span: nga.SpanMetadata | undefined | null,
2960 functionSpans?: nga.SpanMetadata[],
2961 ): o.Expression | null =>
2962 span && content !== undefined
2963 ? new o.WrappedNodeExpr(new RawSource(sliceGuarded(content, span, guards, functionSpans)))
2964 : null;
2965
2966 const rawExprsFromSpans = (
2967 spans: nga.SpanMetadata[] | undefined | null,
2968 ): o.Expression[] | null =>
2969 spans && content !== undefined
2970 ? spans.map(
2971 (span) => new o.WrappedNodeExpr(new RawSource(sliceGuarded(content, span, guards))),
2972 )
2973 : null;
2974
2975 const buildIsolatedTypeTupleExpr = (
2976 tuple: nga.IsolatedTypeTupleMetadata | undefined | null,
2977 ): o.Expression | null => {
2978 if (!tuple) {
2979 return null;
2980 }
2981
2982 const buildIsolatedTypeElementExpr = (el: nga.IsolatedTypeElementMetadata): o.Expression => {
2983 switch (el.kind) {

Callers 1

compileClassesFunction · 0.85

Calls 15

compileFactoryFunctionFunction · 0.90
compileNgModuleFunction · 0.90
compileInjectorFunction · 0.90
rawExprFromSpanFunction · 0.85
refNameFunction · 0.85
mapToRefsFunction · 0.85
refToTypeExpressionFunction · 0.85
mapToVarArrFunction · 0.85
refToExpressionFunction · 0.85
scopeArrayFunction · 0.85
injectorImportsExprsFunction · 0.85

Tested by

no test coverage detected