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

Function compileDirective

packages/core/src/render3/jit/directive.ts:302–330  ·  view source on GitHub ↗
(type: Type<any>, directive: Directive | null)

Source from the content-addressed store, hash-verified

300 * will resolve when compilation completes and the directive becomes usable.
301 */
302export 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
332function getDirectiveMetadata(type: Type<any>, metadata: Directive) {
333 const name = type && type.name;

Callers 3

directives.tsFile · 0.90
compileTypesSyncMethod · 0.85

Calls 4

getCompilerFacadeFunction · 0.90
addDirectiveFactoryDefFunction · 0.85
getDirectiveMetadataFunction · 0.70
compileDirectiveMethod · 0.65

Tested by

no test coverage detected