Skip to content

Commit 2ab197b

Browse files
committed
JSDoc: Start SavingComments 1 more case in the parser
When whitespace crosses an earlier indent margin, that is, when a line is indented further than a previous one, we have to slice that whitespace, but we also know that subsequent text will be comment text, so can switch to SavingComments.
1 parent b9da7f0 commit 2ab197b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/compiler/parser.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8886,7 +8886,7 @@ namespace Parser {
88868886
if (state !== JSDocState.SavingBackticks) {
88878887
state = JSDocState.SavingComments; // leading identifiers start recording as well
88888888
}
8889-
pushComment(scanner.getTokenValue()); // getTokenValue gets the already-sliced identifier text (TODO: the scanner only pre-slices Identifiers, nothing else)
8889+
pushComment(scanner.getTokenValue());
88908890
break;
88918891
case SyntaxKind.NewLineTrivia:
88928892
state = JSDocState.BeginningOfLine;
@@ -8901,13 +8901,15 @@ namespace Parser {
89018901
// Done
89028902
break loop;
89038903
case SyntaxKind.WhitespaceTrivia:
8904+
// TODO: This could simplify somewhat if the scanner could also parse leading whitespace-asterisk sequences
89048905
Debug.assert(state !== JSDocState.SavingComments && state !== JSDocState.SavingBackticks, "whitespace shouldn't come from the scanner while saving comment text")
89058906
const whitespace = scanner.getTokenText();
89068907
// if the whitespace crosses the margin, take only the whitespace that passes the margin
89078908
if (margin !== undefined && indent + whitespace.length > margin) {
89088909
comments.push(whitespace.slice(margin - indent));
8910+
state = JSDocState.SavingComments;
89098911
}
8910-
indent += whitespace.length; // TODO: What happens if we start saving comments here? We don't support margins like | <margin here> * text text | do we?
8912+
indent += whitespace.length;
89118913
break;
89128914
case SyntaxKind.OpenBraceToken:
89138915
state = JSDocState.SavingComments;

0 commit comments

Comments
 (0)