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