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

Function extractHostBindings

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

Source from the content-addressed store, hash-verified

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