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

Function _combineHostContextSelectors

packages/compiler/src/shadow_css.ts:1281–1318  ·  view source on GitHub ↗

* 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 = '',
)

Source from the content-addressed store, hash-verified

1279 * @param otherSelectors the rest of the selectors that are not context selectors.
1280 */
1281function _combineHostContextSelectors(
1282 contextSelectors: string[],
1283 otherSelectors: string,
1284 pseudoPrefix = '',
1285): string {
1286 const hostMarker = _polyfillHostNoCombinator;
1287 _polyfillHostRe.lastIndex = 0; // reset the regex to ensure we get an accurate test
1288 const otherSelectorsHasHost = _polyfillHostRe.test(otherSelectors);
1289
1290 // If there are no context selectors then just output a host marker
1291 if (contextSelectors.length === 0) {
1292 return hostMarker + otherSelectors;
1293 }
1294
1295 const combined: string[] = [contextSelectors.pop() || ''];
1296 while (contextSelectors.length > 0) {
1297 const length = combined.length;
1298 const contextSelector = contextSelectors.pop();
1299 for (let i = 0; i < length; i++) {
1300 const previousSelectors = combined[i];
1301 // Add the new selector as a descendant of the previous selectors
1302 combined[length * 2 + i] = previousSelectors + ' ' + contextSelector;
1303 // Add the new selector as an ancestor of the previous selectors
1304 combined[length + i] = contextSelector + ' ' + previousSelectors;
1305 // Add the new selector to act on the same element as the previous selectors
1306 combined[i] = contextSelector + previousSelectors;
1307 }
1308 }
1309 // Finally connect the selector to the `hostMarker`s: either acting directly on the host
1310 // (A<hostMarker>) or as an ancestor (A <hostMarker>).
1311 return combined
1312 .map((s) =>
1313 otherSelectorsHasHost
1314 ? `${pseudoPrefix}${s}${otherSelectors}`
1315 : `${pseudoPrefix}${s}${hostMarker}${otherSelectors}, ${pseudoPrefix}${s} ${hostMarker}${otherSelectors}`,
1316 )
1317 .join(',');
1318}
1319
1320/**
1321 * Mutate the given `groups` array so that there are `multiples` clones of the original array

Calls 4

popMethod · 0.80
mapMethod · 0.80
joinMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected