Skip to content

Commit 275a4bd

Browse files
committed
Use enum for parser state instead of 2 booleans
Plus cleanup some lint
1 parent 2b96246 commit 275a4bd

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/compiler/parser.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6151,6 +6151,12 @@ namespace ts {
61516151
return comment;
61526152
}
61536153

6154+
const enum TagState {
6155+
BeginningOfLine,
6156+
SawAsterisk,
6157+
SavingComments
6158+
}
6159+
61546160
export function parseJSDocCommentWorker(start: number, length: number): JSDoc {
61556161
const content = sourceText;
61566162
start = start || 0;
@@ -6359,8 +6365,7 @@ namespace ts {
63596365

63606366
function parseTagComments(indent: number) {
63616367
const comments: string[] = [];
6362-
let savingComments = false;
6363-
let seenAsterisk = true;
6368+
let state = TagState.SawAsterisk;
63646369
let done = false;
63656370
let margin: number | undefined;
63666371
let text: string;
@@ -6375,9 +6380,8 @@ namespace ts {
63756380
text = scanner.getTokenText();
63766381
switch (token()) {
63776382
case SyntaxKind.NewLineTrivia:
6378-
if (seenAsterisk) {
6379-
savingComments = false;
6380-
seenAsterisk = false;
6383+
if (state >= TagState.SawAsterisk) {
6384+
state = TagState.BeginningOfLine;
63816385
comments.push(text);
63826386
}
63836387
indent = 0;
@@ -6386,7 +6390,7 @@ namespace ts {
63866390
done = true;
63876391
break;
63886392
case SyntaxKind.WhitespaceTrivia:
6389-
if (savingComments && seenAsterisk) {
6393+
if (state === TagState.SavingComments) {
63906394
pushComment(text);
63916395
}
63926396
else {
@@ -6398,18 +6402,16 @@ namespace ts {
63986402
}
63996403
break;
64006404
case SyntaxKind.AsteriskToken:
6401-
if (!seenAsterisk) {
6405+
if (state === TagState.BeginningOfLine) {
64026406
// leading asterisks start recording on the *next* (non-whitespace) token
6403-
savingComments = false;
6407+
state = TagState.SawAsterisk;
64046408
indent += text.length;
6409+
break;
64056410
}
6406-
// FALLTHROUGH to gather comments
6411+
// FALLTHROUGH otherwise to record the * as a comment
64076412
default:
6408-
if (seenAsterisk) {
6409-
savingComments = true; // leading identifiers start recording as well
6410-
pushComment(text);
6411-
}
6412-
seenAsterisk = true;
6413+
state = TagState.SavingComments; // leading identifiers start recording as well
6414+
pushComment(text);
64136415
break;
64146416
}
64156417
if (!done) {

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ namespace ts {
13801380

13811381
function getJSDocTags(node: Node, checkParentVariableStatement: boolean): JSDocTag[] {
13821382
return getJSDocs(node, checkParentVariableStatement, docs => {
1383-
let result: JSDocTag[] = [];
1383+
const result: JSDocTag[] = [];
13841384
for (const doc of docs) {
13851385
if (doc.tags) {
13861386
result.push(...doc.tags);

0 commit comments

Comments
 (0)