(type: Type<any>, directive: Directive | null)
| 293 | * will resolve when compilation completes and the directive becomes usable. |
| 294 | */ |
| 295 | export function compileDirective(type: Type<any>, directive: Directive | null): void { |
| 296 | let ngDirectiveDef: any = null; |
| 297 | |
| 298 | addDirectiveFactoryDef(type, directive || {}); |
| 299 | |
| 300 | Object.defineProperty(type, NG_DIR_DEF, { |
| 301 | get: () => { |
| 302 | if (ngDirectiveDef === null) { |
| 303 | // `directive` can be null in the case of abstract directives as a base class |
| 304 | // that use `@Directive()` with no selector. In that case, pass empty object to the |
| 305 | // `directiveMetadata` function instead of null. |
| 306 | const meta = getDirectiveMetadata(type, directive || {}); |
| 307 | const compiler = getCompilerFacade({ |
| 308 | usage: JitCompilerUsage.Decorator, |
| 309 | kind: 'directive', |
| 310 | type, |
| 311 | }); |
| 312 | ngDirectiveDef = compiler.compileDirective( |
| 313 | angularCoreEnv, |
| 314 | meta.sourceMapUrl, |
| 315 | meta.metadata, |
| 316 | ); |
| 317 | } |
| 318 | return ngDirectiveDef; |
| 319 | }, |
| 320 | // Make the property configurable in dev mode to allow overriding in tests |
| 321 | configurable: !!ngDevMode, |
| 322 | }); |
| 323 | } |
| 324 | |
| 325 | function getDirectiveMetadata(type: Type<any>, metadata: Directive) { |
| 326 | const name = type && type.name; |
no test coverage detected
searching dependent graphs…