From 275a4bd4f3df74441b9cd56ac212fd37fb35f3b6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 1 Sep 2016 10:05:56 -0700 Subject: [PATCH] Use enum for parser state instead of 2 booleans Plus cleanup some lint --- src/compiler/parser.ts | 30 ++++++++++++++++-------------- src/compiler/utilities.ts | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 342b711a5a6..445af2243df 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6151,6 +6151,12 @@ namespace ts { return comment; } + const enum TagState { + BeginningOfLine, + SawAsterisk, + SavingComments + } + export function parseJSDocCommentWorker(start: number, length: number): JSDoc { const content = sourceText; start = start || 0; @@ -6359,8 +6365,7 @@ namespace ts { function parseTagComments(indent: number) { const comments: string[] = []; - let savingComments = false; - let seenAsterisk = true; + let state = TagState.SawAsterisk; let done = false; let margin: number | undefined; let text: string; @@ -6375,9 +6380,8 @@ namespace ts { text = scanner.getTokenText(); switch (token()) { case SyntaxKind.NewLineTrivia: - if (seenAsterisk) { - savingComments = false; - seenAsterisk = false; + if (state >= TagState.SawAsterisk) { + state = TagState.BeginningOfLine; comments.push(text); } indent = 0; @@ -6386,7 +6390,7 @@ namespace ts { done = true; break; case SyntaxKind.WhitespaceTrivia: - if (savingComments && seenAsterisk) { + if (state === TagState.SavingComments) { pushComment(text); } else { @@ -6398,18 +6402,16 @@ namespace ts { } break; case SyntaxKind.AsteriskToken: - if (!seenAsterisk) { + if (state === TagState.BeginningOfLine) { // leading asterisks start recording on the *next* (non-whitespace) token - savingComments = false; + state = TagState.SawAsterisk; indent += text.length; + break; } - // FALLTHROUGH to gather comments + // FALLTHROUGH otherwise to record the * as a comment default: - if (seenAsterisk) { - savingComments = true; // leading identifiers start recording as well - pushComment(text); - } - seenAsterisk = true; + state = TagState.SavingComments; // leading identifiers start recording as well + pushComment(text); break; } if (!done) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 52683f0e74b..5e556278866 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1380,7 +1380,7 @@ namespace ts { function getJSDocTags(node: Node, checkParentVariableStatement: boolean): JSDocTag[] { return getJSDocs(node, checkParentVariableStatement, docs => { - let result: JSDocTag[] = []; + const result: JSDocTag[] = []; for (const doc of docs) { if (doc.tags) { result.push(...doc.tags);