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

Function extractHostBindings

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

Source from the content-addressed store, hash-verified

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