* 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)
| 762 | * the placeholders. |
| 763 | */ |
| 764 | function _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`. */ |
| 782 | function _restoreSelector(selector: string, placeholders: string[]): string { |
no test coverage detected
searching dependent graphs…