* Invokes a callback for each comment range following the provided position. * * Single-line comment ranges include the leading double-slash characters but not the ending * line break. Multi-line comment ranges include the leading slash-asterisk and trailing * asterisk-slash char
(reduce, text, pos, trailing, cb, state, initial)
| 10637 | * return value of the callback. |
| 10638 | */ |
| 10639 | function iterateCommentRanges(reduce, text, pos, trailing, cb, state, initial) { |
| 10640 | var pendingPos; |
| 10641 | var pendingEnd; |
| 10642 | var pendingKind; |
| 10643 | var pendingHasTrailingNewLine; |
| 10644 | var hasPendingCommentRange = false; |
| 10645 | var collecting = trailing; |
| 10646 | var accumulator = initial; |
| 10647 | if (pos === 0) { |
| 10648 | collecting = true; |
| 10649 | var shebang = getShebang(text); |
| 10650 | if (shebang) { |
| 10651 | pos = shebang.length; |
| 10652 | } |
| 10653 | } |
| 10654 | scan: while (pos >= 0 && pos < text.length) { |
| 10655 | var ch = text.charCodeAt(pos); |
| 10656 | switch (ch) { |
| 10657 | case 13 /* CharacterCodes.carriageReturn */: |
| 10658 | if (text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */) { |
| 10659 | pos++; |
| 10660 | } |
| 10661 | // falls through |
| 10662 | case 10 /* CharacterCodes.lineFeed */: |
| 10663 | pos++; |
| 10664 | if (trailing) { |
| 10665 | break scan; |
| 10666 | } |
| 10667 | collecting = true; |
| 10668 | if (hasPendingCommentRange) { |
| 10669 | pendingHasTrailingNewLine = true; |
| 10670 | } |
| 10671 | continue; |
| 10672 | case 9 /* CharacterCodes.tab */: |
| 10673 | case 11 /* CharacterCodes.verticalTab */: |
| 10674 | case 12 /* CharacterCodes.formFeed */: |
| 10675 | case 32 /* CharacterCodes.space */: |
| 10676 | pos++; |
| 10677 | continue; |
| 10678 | case 47 /* CharacterCodes.slash */: |
| 10679 | var nextChar = text.charCodeAt(pos + 1); |
| 10680 | var hasTrailingNewLine = false; |
| 10681 | if (nextChar === 47 /* CharacterCodes.slash */ || nextChar === 42 /* CharacterCodes.asterisk */) { |
| 10682 | var kind = nextChar === 47 /* CharacterCodes.slash */ ? 2 /* SyntaxKind.SingleLineCommentTrivia */ : 3 /* SyntaxKind.MultiLineCommentTrivia */; |
| 10683 | var startPos = pos; |
| 10684 | pos += 2; |
| 10685 | if (nextChar === 47 /* CharacterCodes.slash */) { |
| 10686 | while (pos < text.length) { |
| 10687 | if (isLineBreak(text.charCodeAt(pos))) { |
| 10688 | hasTrailingNewLine = true; |
| 10689 | break; |
| 10690 | } |
| 10691 | pos++; |
| 10692 | } |
| 10693 | } |
| 10694 | else { |
| 10695 | while (pos < text.length) { |
| 10696 | if (text.charCodeAt(pos) === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) { |
no test coverage detected
searching dependent graphs…