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

Function extractHostBindings

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

Source from the content-addressed store, hash-verified

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