* Combine the `contextSelectors` with the `hostMarker` and the `otherSelectors` * to create a selector that matches the same as `:host-context()`. * * Given a single context selector `A` we need to output selectors that match on the host and as an * ancestor of the host: * * ``` * A <hostMark
( contextSelectors: string[], otherSelectors: string, pseudoPrefix = '', )
| 1246 | * @param otherSelectors the rest of the selectors that are not context selectors. |
| 1247 | */ |
| 1248 | function _combineHostContextSelectors( |
| 1249 | contextSelectors: string[], |
| 1250 | otherSelectors: string, |
| 1251 | pseudoPrefix = '', |
| 1252 | ): string { |
| 1253 | const hostMarker = _polyfillHostNoCombinator; |
| 1254 | _polyfillHostRe.lastIndex = 0; // reset the regex to ensure we get an accurate test |
| 1255 | const otherSelectorsHasHost = _polyfillHostRe.test(otherSelectors); |
| 1256 | |
| 1257 | // If there are no context selectors then just output a host marker |
| 1258 | if (contextSelectors.length === 0) { |
| 1259 | return hostMarker + otherSelectors; |
| 1260 | } |
| 1261 | |
| 1262 | const combined: string[] = [contextSelectors.pop() || '']; |
| 1263 | while (contextSelectors.length > 0) { |
| 1264 | const length = combined.length; |
| 1265 | const contextSelector = contextSelectors.pop(); |
| 1266 | for (let i = 0; i < length; i++) { |
| 1267 | const previousSelectors = combined[i]; |
| 1268 | // Add the new selector as a descendant of the previous selectors |
| 1269 | combined[length * 2 + i] = previousSelectors + ' ' + contextSelector; |
| 1270 | // Add the new selector as an ancestor of the previous selectors |
| 1271 | combined[length + i] = contextSelector + ' ' + previousSelectors; |
| 1272 | // Add the new selector to act on the same element as the previous selectors |
| 1273 | combined[i] = contextSelector + previousSelectors; |
| 1274 | } |
| 1275 | } |
| 1276 | // Finally connect the selector to the `hostMarker`s: either acting directly on the host |
| 1277 | // (A<hostMarker>) or as an ancestor (A <hostMarker>). |
| 1278 | return combined |
| 1279 | .map((s) => |
| 1280 | otherSelectorsHasHost |
| 1281 | ? `${pseudoPrefix}${s}${otherSelectors}` |
| 1282 | : `${pseudoPrefix}${s}${hostMarker}${otherSelectors}, ${pseudoPrefix}${s} ${hostMarker}${otherSelectors}`, |
| 1283 | ) |
| 1284 | .join(','); |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * Mutate the given `groups` array so that there are `multiples` clones of the original array |
no test coverage detected
searching dependent graphs…