(selector: string)
| 10 | /(?<!\\)(?:\\\\)*([ >+~,]\s*)(?![^(]*\))(?![^[]+\]|\d)/g; |
| 11 | |
| 12 | export function globalifySelector(selector: string) { |
| 13 | const parts = selector.trim().split(combinatorPattern); |
| 14 | |
| 15 | const newSelector = []; |
| 16 | |
| 17 | for (let i = 0; i < parts.length; i++) { |
| 18 | const part = parts[i]; |
| 19 | |
| 20 | // if this is a separator or a :global |
| 21 | if (i % 2 !== 0 || part === '' || part.startsWith(':global')) { |
| 22 | newSelector.push(part); |
| 23 | continue; |
| 24 | } |
| 25 | |
| 26 | // :local() with scope |
| 27 | if (part.startsWith(':local(')) { |
| 28 | newSelector.push(part.replace(/:local\((.+?)\)/g, '$1')); |
| 29 | continue; |
| 30 | } |
| 31 | |
| 32 | // :local inlined in a selector |
| 33 | if (part.startsWith(':local')) { |
| 34 | // + 2 to ignore the :local and space combinator |
| 35 | const startIndex = i + 2; |
| 36 | let endIndex = parts.findIndex( |
| 37 | (p, idx) => idx > startIndex && p.startsWith(':global'), |
| 38 | ); |
| 39 | |
| 40 | endIndex = endIndex === -1 ? parts.length - 1 : endIndex; |
| 41 | |
| 42 | newSelector.push(...parts.slice(startIndex, endIndex + 1)); |
| 43 | |
| 44 | i = endIndex; |
| 45 | |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | newSelector.push(`:global(${part})`); |
| 50 | } |
| 51 | |
| 52 | return newSelector.join(''); |
| 53 | } |
no outgoing calls
no test coverage detected