MCPcopy Index your code
hub / github.com/angular/components / _splitAndEscapeSelector

Function _splitAndEscapeSelector

src/cdk/testing/component-harness.ts:764–779  ·  view source on GitHub ↗

* Splits up a compound selector into its parts and escapes any quoted content. The quoted content * has to be escaped, because it can contain commas which will throw throw us off when trying to * split it. * @param selector Selector to be split. * @returns The escaped string where any quoted con

(selector: string)

Source from the content-addressed store, hash-verified

762 * the placeholders.
763 */
764function _splitAndEscapeSelector(selector: string): [parts: string[], placeholders: string[]] {
765 const placeholders: string[] = [];
766
767 // Note that the regex doesn't account for nested quotes so something like `"ab'cd'e"` will be
768 // considered as two blocks. It's a bit of an edge case, but if we find that it's a problem,
769 // we can make it a bit smarter using a loop. Use this for now since it's more readable and
770 // compact. More complete implementation:
771 // https://github.com/angular/angular/blob/bd34bc9e89f18a/packages/compiler/src/shadow_css.ts#L655
772 const result = selector.replace(/(["'][^["']*["'])/g, (_, keep) => {
773 const replaceBy = `__cdkPlaceholder-${placeholders.length}__`;
774 placeholders.push(keep);
775 return replaceBy;
776 });
777
778 return [result.split(',').map(part => part.trim()), placeholders];
779}
780
781/** Restores a selector whose content was escaped in `_splitAndEscapeSelector`. */
782function _restoreSelector(selector: string, placeholders: string[]): string {

Callers 1

getSelectorMethod · 0.85

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…