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

Function _combineHostContextSelectors

packages/compiler/src/shadow_css.ts:1308–1345  ·  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

1306 * @param otherSelectors the rest of the selectors that are not context selectors.
1307 */
1308function _combineHostContextSelectors(
1309 contextSelectors: string[],
1310 otherSelectors: string,
1311 pseudoPrefix = '',
1312): string {
1313 const hostMarker = _polyfillHostNoCombinator;
1314 _polyfillHostRe.lastIndex = 0; // reset the regex to ensure we get an accurate test
1315 const otherSelectorsHasHost = _polyfillHostRe.test(otherSelectors);
1316
1317 // If there are no context selectors then just output a host marker
1318 if (contextSelectors.length === 0) {
1319 return hostMarker + otherSelectors;
1320 }
1321
1322 const combined: string[] = [contextSelectors.pop() || ''];
1323 while (contextSelectors.length > 0) {
1324 const length = combined.length;
1325 const contextSelector = contextSelectors.pop();
1326 for (let i = 0; i < length; i++) {
1327 const previousSelectors = combined[i];
1328 // Add the new selector as a descendant of the previous selectors
1329 combined[length * 2 + i] = previousSelectors + ' ' + contextSelector;
1330 // Add the new selector as an ancestor of the previous selectors
1331 combined[length + i] = contextSelector + ' ' + previousSelectors;
1332 // Add the new selector to act on the same element as the previous selectors
1333 combined[i] = contextSelector + previousSelectors;
1334 }
1335 }
1336 // Finally connect the selector to the `hostMarker`s: either acting directly on the host
1337 // (A<hostMarker>) or as an ancestor (A <hostMarker>).
1338 return combined
1339 .map((s) =>
1340 otherSelectorsHasHost
1341 ? `${pseudoPrefix}${s}${otherSelectors}`
1342 : `${pseudoPrefix}${s}${hostMarker}${otherSelectors}, ${pseudoPrefix}${s} ${hostMarker}${otherSelectors}`,
1343 )
1344 .join(',');
1345}
1346
1347/**
1348 * 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