( moduleType: NgModuleType, ngModule: NgModule, allowDuplicateDeclarationsInRoot: boolean = false, )
| 123 | * root. |
| 124 | */ |
| 125 | export function compileNgModuleDefs( |
| 126 | moduleType: NgModuleType, |
| 127 | ngModule: NgModule, |
| 128 | allowDuplicateDeclarationsInRoot: boolean = false, |
| 129 | ): void { |
| 130 | ngDevMode && assertDefined(moduleType, 'Required value moduleType'); |
| 131 | ngDevMode && assertDefined(ngModule, 'Required value ngModule'); |
| 132 | const declarations: Type<any>[] = flatten(ngModule.declarations || EMPTY_ARRAY); |
| 133 | let ngModuleDef: any = null; |
| 134 | Object.defineProperty(moduleType, NG_MOD_DEF, { |
| 135 | configurable: true, |
| 136 | get: () => { |
| 137 | if (ngModuleDef === null) { |
| 138 | if (ngDevMode && ngModule.imports && ngModule.imports.indexOf(moduleType) > -1) { |
| 139 | // We need to assert this immediately, because allowing it to continue will cause it to |
| 140 | // go into an infinite loop before we've reached the point where we throw all the errors. |
| 141 | throw new Error(`'${stringifyForError(moduleType)}' module can't import itself`); |
| 142 | } |
| 143 | const compiler = getCompilerFacade({ |
| 144 | usage: JitCompilerUsage.Decorator, |
| 145 | kind: 'NgModule', |
| 146 | type: moduleType, |
| 147 | }); |
| 148 | ngModuleDef = compiler.compileNgModule(angularCoreEnv, `ng:///${moduleType.name}/ɵmod.js`, { |
| 149 | type: moduleType, |
| 150 | bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(resolveForwardRef), |
| 151 | declarations: declarations.map(resolveForwardRef), |
| 152 | imports: flatten(ngModule.imports || EMPTY_ARRAY) |
| 153 | .map(resolveForwardRef) |
| 154 | .map(expandModuleWithProviders), |
| 155 | exports: flatten(ngModule.exports || EMPTY_ARRAY) |
| 156 | .map(resolveForwardRef) |
| 157 | .map(expandModuleWithProviders), |
| 158 | schemas: ngModule.schemas ? flatten(ngModule.schemas) : null, |
| 159 | id: ngModule.id || null, |
| 160 | }); |
| 161 | // Set `schemas` on ngModuleDef to an empty array in JIT mode to indicate that runtime |
| 162 | // should verify that there are no unknown elements in a template. In AOT mode, that check |
| 163 | // happens at compile time and `schemas` information is not present on Component and Module |
| 164 | // defs after compilation (so the check doesn't happen the second time at runtime). |
| 165 | if (!ngModuleDef.schemas) { |
| 166 | ngModuleDef.schemas = []; |
| 167 | } |
| 168 | } |
| 169 | return ngModuleDef; |
| 170 | }, |
| 171 | }); |
| 172 | |
| 173 | let ngFactoryDef: any = null; |
| 174 | Object.defineProperty(moduleType, NG_FACTORY_DEF, { |
| 175 | get: () => { |
| 176 | if (ngFactoryDef === null) { |
| 177 | const compiler = getCompilerFacade({ |
| 178 | usage: JitCompilerUsage.Decorator, |
| 179 | kind: 'NgModule', |
| 180 | type: moduleType, |
| 181 | }); |
| 182 | ngFactoryDef = compiler.compileFactory(angularCoreEnv, `ng:///${moduleType.name}/ɵfac.js`, { |
no test coverage detected
searching dependent graphs…