MCPcopy Index your code
hub / github.com/angular/angular / extractHostBindings

Function extractHostBindings

packages/compiler/src/jit_compiler_facade.ts:917–951  ·  view source on GitHub ↗
(
  propMetadata: {[key: string]: any[]},
  sourceSpan: ParseSourceSpan,
  host?: {[key: string]: string},
)

Source from the content-addressed store, hash-verified

915}
916
917function extractHostBindings(
918 propMetadata: {[key: string]: any[]},
919 sourceSpan: ParseSourceSpan,
920 host?: {[key: string]: string},
921): ParsedHostBindings {
922 // First parse the declarations from the metadata.
923 const bindings = parseHostBindings(host || {});
924
925 // Next, loop over the properties of the object, looking for @HostBinding and @HostListener.
926 for (const field in propMetadata) {
927 if (propMetadata.hasOwnProperty(field)) {
928 propMetadata[field].forEach((ann) => {
929 if (isHostBinding(ann)) {
930 // Since this is a decorator, we know that the value is a class member. Always access it
931 // through `this` so that further down the line it can't be confused for a literal value
932 // (e.g. if there's a property called `true`).
933 bindings.properties[ann.hostPropertyName || field] = getSafePropertyAccessString(
934 'this',
935 field,
936 );
937 } else if (isHostListener(ann)) {
938 bindings.listeners[ann.eventName || field] = `${field}(${(ann.args || []).join(',')})`;
939 }
940 });
941 }
942 }
943
944 // After that check host bindings for errors
945 const errors = verifyHostBindings(bindings, sourceSpan);
946 if (errors.length) {
947 throw new Error(errors.map((error: ParseError) => error.msg).join('\n'));
948 }
949
950 return bindings;
951}
952
953function isHostBinding(value: any): value is HostBinding {
954 return value.ngMetadataName === 'HostBinding';

Callers 1

Calls 8

parseHostBindingsFunction · 0.90
verifyHostBindingsFunction · 0.90
isHostBindingFunction · 0.85
isHostListenerFunction · 0.85
mapMethod · 0.80
joinMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…