* Detached comment is a comment at the top of file or function body that is separated from * the next statement by space.
(text, lineMap, writer, writeComment, node, newLine, removeComments)
| 18732 | * the next statement by space. |
| 18733 | */ |
| 18734 | function emitDetachedComments(text, lineMap, writer, writeComment, node, newLine, removeComments) { |
| 18735 | var leadingComments; |
| 18736 | var currentDetachedCommentInfo; |
| 18737 | if (removeComments) { |
| 18738 | // removeComments is true, only reserve pinned comment at the top of file |
| 18739 | // For example: |
| 18740 | // /*! Pinned Comment */ |
| 18741 | // |
| 18742 | // var x = 10; |
| 18743 | if (node.pos === 0) { |
| 18744 | leadingComments = ts.filter(ts.getLeadingCommentRanges(text, node.pos), isPinnedCommentLocal); |
| 18745 | } |
| 18746 | } |
| 18747 | else { |
| 18748 | // removeComments is false, just get detached as normal and bypass the process to filter comment |
| 18749 | leadingComments = ts.getLeadingCommentRanges(text, node.pos); |
| 18750 | } |
| 18751 | if (leadingComments) { |
| 18752 | var detachedComments = []; |
| 18753 | var lastComment = void 0; |
| 18754 | for (var _i = 0, leadingComments_1 = leadingComments; _i < leadingComments_1.length; _i++) { |
| 18755 | var comment = leadingComments_1[_i]; |
| 18756 | if (lastComment) { |
| 18757 | var lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, lastComment.end); |
| 18758 | var commentLine = getLineOfLocalPositionFromLineMap(lineMap, comment.pos); |
| 18759 | if (commentLine >= lastCommentLine + 2) { |
| 18760 | // There was a blank line between the last comment and this comment. This |
| 18761 | // comment is not part of the copyright comments. Return what we have so |
| 18762 | // far. |
| 18763 | break; |
| 18764 | } |
| 18765 | } |
| 18766 | detachedComments.push(comment); |
| 18767 | lastComment = comment; |
| 18768 | } |
| 18769 | if (detachedComments.length) { |
| 18770 | // All comments look like they could have been part of the copyright header. Make |
| 18771 | // sure there is at least one blank line between it and the node. If not, it's not |
| 18772 | // a copyright header. |
| 18773 | var lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, ts.last(detachedComments).end); |
| 18774 | var nodeLine = getLineOfLocalPositionFromLineMap(lineMap, ts.skipTrivia(text, node.pos)); |
| 18775 | if (nodeLine >= lastCommentLine + 2) { |
| 18776 | // Valid detachedComments |
| 18777 | emitNewLineBeforeLeadingComments(lineMap, writer, node, leadingComments); |
| 18778 | emitComments(text, lineMap, writer, detachedComments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeComment); |
| 18779 | currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.last(detachedComments).end }; |
| 18780 | } |
| 18781 | } |
| 18782 | } |
| 18783 | return currentDetachedCommentInfo; |
| 18784 | function isPinnedCommentLocal(comment) { |
| 18785 | return isPinnedComment(text, comment.pos); |
| 18786 | } |
| 18787 | } |
| 18788 | ts.emitDetachedComments = emitDetachedComments; |
| 18789 | function writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine) { |
| 18790 | if (text.charCodeAt(commentPos + 1) === 42 /* CharacterCodes.asterisk */) { |
nothing calls this directly
no test coverage detected