Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8636,14 +8636,14 @@ namespace Parser {
break;
case SyntaxKind.WhitespaceTrivia:
// only collect whitespace if we're already saving comments or have just crossed the comment indent margin
const whitespace = scanner.getTokenText();
const whitespaceLength = scanner.getTextPos() - scanner.getTokenPos();
if (state === JSDocState.SavingComments) {
comments.push(whitespace);
comments.push(scanner.getTokenText());
}
else if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent));
else if (margin !== undefined && indent + whitespaceLength > margin) {
comments.push(scanner.getTokenText().slice(margin - indent));
}
indent += whitespace.length;
indent += whitespaceLength;
break;
case SyntaxKind.EndOfFileToken:
break loop;
Expand Down Expand Up @@ -8888,12 +8888,12 @@ namespace Parser {
pushComment(scanner.getTokenText());
}
else {
const whitespace = scanner.getTokenText();
const whitespaceLength = scanner.getTextPos() - scanner.getTokenPos();
// if the whitespace crosses the margin, take only the whitespace that passes the margin
if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent));
if (margin !== undefined && indent + whitespaceLength > margin) {
comments.push(scanner.getTokenText().slice(margin - indent));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I would've said not to do the double-substring/slice - but at this point I'm skeptical that it will affect perf much.

By the way, what is this logic trying to model?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you write

/**
 * Some comments here
 *     Blockquote here
 *     And here
 * Back to original indentation
 */

The two blockquoted lines need to include 4 of the 5 spaces after the asterisk. Conversely, the first and last lines should skip the 1 space after the asterisk.

Needing to slice additional whitespace for the margin is uncommon, so putting the slice only in that branch should have improved performance noticeably. I'm not sure why it didn't.

}
indent += whitespace.length;
indent += whitespaceLength;
}
break;
case SyntaxKind.OpenBraceToken:
Expand Down