(
propMetadata: {[key: string]: any[]},
sourceSpan: ParseSourceSpan,
host?: {[key: string]: string},
)
| 915 | } |
| 916 | |
| 917 | function 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 | |
| 953 | function isHostBinding(value: any): value is HostBinding { |
| 954 | return value.ngMetadataName === 'HostBinding'; |
no test coverage detected
searching dependent graphs…