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

Function compileDirective

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

Source from the content-addressed store, hash-verified

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