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

Method _splitOnTopLevelCommas

packages/compiler/src/shadow_css.ts:462–488  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

460 * @param returnOnClosingParen Whether to return when exiting the current level of parentheses nesting
461 */
462 private *_splitOnTopLevelCommas(text: string, returnOnClosingParen: boolean): Generator<string> {
463 const length = text.length;
464 let parens = 0;
465 let prev = 0;
466
467 for (let i = 0; i < length; i++) {
468 const charCode = text.charCodeAt(i);
469
470 if (charCode === chars.$LPAREN) {
471 parens++;
472 } else if (charCode === chars.$RPAREN) {
473 parens--;
474 if (parens < 0 && returnOnClosingParen) {
475 // Found an extra closing paren.
476 yield text.slice(prev, i);
477 return;
478 }
479 } else if (charCode === chars.$COMMA && parens === 0) {
480 // Found a top-level comma, yield the current chunk
481 yield text.slice(prev, i);
482 prev = i + 1;
483 }
484 }
485
486 // Yield the final chunk
487 yield text.slice(prev);
488 }
489
490 /*
491 * convert a rule like :host-context(.foo) > .bar { }

Calls

no outgoing calls

Tested by

no test coverage detected