* Generator function that splits a string on top-level commas (commas that are not inside parentheses). * Yields each part of the string between top-level commas. Terminates if an extra closing paren is found. * * @param text The string to split * @param returnOnClosingParen Whether to r
(text: string, returnOnClosingParen: boolean)
| 459 | * @param returnOnClosingParen Whether to return when exiting the current level of parentheses nesting |
| 460 | */ |
| 461 | private *_splitOnTopLevelCommas(text: string, returnOnClosingParen: boolean): Generator<string> { |
| 462 | const length = text.length; |
| 463 | let parens = 0; |
| 464 | let prev = 0; |
| 465 | |
| 466 | for (let i = 0; i < length; i++) { |
| 467 | const charCode = text.charCodeAt(i); |
| 468 | |
| 469 | if (charCode === chars.$LPAREN) { |
| 470 | parens++; |
| 471 | } else if (charCode === chars.$RPAREN) { |
| 472 | parens--; |
| 473 | if (parens < 0 && returnOnClosingParen) { |
| 474 | // Found an extra closing paren. |
| 475 | yield text.slice(prev, i); |
| 476 | return; |
| 477 | } |
| 478 | } else if (charCode === chars.$COMMA && parens === 0) { |
| 479 | // Found a top-level comma, yield the current chunk |
| 480 | yield text.slice(prev, i); |
| 481 | prev = i + 1; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | // Yield the final chunk |
| 486 | yield text.slice(prev); |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * convert a rule like :host-context(.foo) > .bar { } |
no outgoing calls
no test coverage detected