( type: 'component' | 'directive', selector: string | null, nameSpan: ParseSourceSpan, hostObjectLiteralBindings: HostObjectLiteralBinding[], hostBindingDecorators: HostBindingDecorator[], hostListenerDecorators: HostListenerDecorator[], )
| 96 | * @param meta Metadata used to construct the host element. |
| 97 | */ |
| 98 | export function createHostElement( |
| 99 | type: 'component' | 'directive', |
| 100 | selector: string | null, |
| 101 | nameSpan: ParseSourceSpan, |
| 102 | hostObjectLiteralBindings: HostObjectLiteralBinding[], |
| 103 | hostBindingDecorators: HostBindingDecorator[], |
| 104 | hostListenerDecorators: HostListenerDecorator[], |
| 105 | ): HostElement | null { |
| 106 | const bindings: BoundAttribute[] = []; |
| 107 | const listeners: BoundEvent[] = []; |
| 108 | let parser: BindingParser | null = null; |
| 109 | |
| 110 | for (const binding of hostObjectLiteralBindings) { |
| 111 | // We only support type checking of static bindings. |
| 112 | parser ??= makeBindingParser(); |
| 113 | createNodeFromHostLiteralProperty(binding, parser, bindings, listeners); |
| 114 | } |
| 115 | |
| 116 | for (const decorator of hostBindingDecorators) { |
| 117 | createNodeFromBindingDecorator(decorator, bindings); |
| 118 | } |
| 119 | |
| 120 | for (const decorator of hostListenerDecorators) { |
| 121 | parser ??= makeBindingParser(); |
| 122 | createNodeFromListenerDecorator(decorator, parser, listeners); |
| 123 | } |
| 124 | |
| 125 | // The element will be a no-op if there are no bindings. |
| 126 | if (bindings.length === 0 && listeners.length === 0) { |
| 127 | return null; |
| 128 | } |
| 129 | |
| 130 | const tagNames: string[] = []; |
| 131 | |
| 132 | if (selector !== null) { |
| 133 | const parts = CssSelector.parse(selector); |
| 134 | |
| 135 | for (const part of parts) { |
| 136 | if (part.element !== null) { |
| 137 | tagNames.push(part.element); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // If none of the selectors have a tag name, fall back to `ng-component`/`ng-directive`. |
| 143 | // This is how the runtime handles components without tag names as well. |
| 144 | if (tagNames.length === 0) { |
| 145 | tagNames.push(`ng-${type}`); |
| 146 | } |
| 147 | |
| 148 | return new HostElement(tagNames, bindings, listeners, nameSpan); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Creates an AST node that can be used as a guard in `if` statements to distinguish TypeScript |
no test coverage detected
searching dependent graphs…