mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Add 'parseOptionalJsdoc' helper (#24650)
This commit is contained in:
@@ -6365,17 +6365,14 @@ namespace ts {
|
||||
indent += text.length;
|
||||
}
|
||||
|
||||
let t = nextJSDocToken();
|
||||
while (t === SyntaxKind.WhitespaceTrivia) {
|
||||
t = nextJSDocToken();
|
||||
}
|
||||
if (t === SyntaxKind.NewLineTrivia) {
|
||||
nextJSDocToken();
|
||||
while (parseOptionalJsdoc(SyntaxKind.WhitespaceTrivia));
|
||||
if (parseOptionalJsdoc(SyntaxKind.NewLineTrivia)) {
|
||||
state = JSDocState.BeginningOfLine;
|
||||
indent = 0;
|
||||
t = nextJSDocToken();
|
||||
}
|
||||
loop: while (true) {
|
||||
switch (t) {
|
||||
switch (token()) {
|
||||
case SyntaxKind.AtToken:
|
||||
if (state === JSDocState.BeginningOfLine || state === JSDocState.SawAsterisk) {
|
||||
removeTrailingNewlines(comments);
|
||||
@@ -6435,12 +6432,11 @@ namespace ts {
|
||||
pushComment(scanner.getTokenText());
|
||||
break;
|
||||
}
|
||||
t = nextJSDocToken();
|
||||
nextJSDocToken();
|
||||
}
|
||||
removeLeadingNewlines(comments);
|
||||
removeTrailingNewlines(comments);
|
||||
result = createJSDocComment();
|
||||
|
||||
});
|
||||
|
||||
return result;
|
||||
@@ -6877,8 +6873,7 @@ namespace ts {
|
||||
jsdocSignature.parameters = append(jsdocSignature.parameters as MutableNodeArray<JSDocParameterTag>, child);
|
||||
}
|
||||
const returnTag = tryParse(() => {
|
||||
if (token() === SyntaxKind.AtToken) {
|
||||
nextJSDocToken();
|
||||
if (parseOptionalJsdoc(SyntaxKind.AtToken)) {
|
||||
const tag = parseTag(indent);
|
||||
if (tag && tag.kind === SyntaxKind.JSDocReturnTag) {
|
||||
return tag as JSDocReturnTag;
|
||||
@@ -6997,12 +6992,12 @@ namespace ts {
|
||||
let constraint: JSDocTypeExpression | undefined;
|
||||
if (token() === SyntaxKind.OpenBraceToken) {
|
||||
constraint = parseJSDocTypeExpression();
|
||||
skipWhitespace();
|
||||
}
|
||||
|
||||
const typeParameters = [];
|
||||
const typeParametersPos = getNodePos();
|
||||
while (true) {
|
||||
do {
|
||||
skipWhitespace();
|
||||
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
|
||||
if (!tokenIsIdentifierOrKeyword(token())) {
|
||||
parseErrorAtCurrentToken(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);
|
||||
@@ -7012,15 +7007,7 @@ namespace ts {
|
||||
skipWhitespace();
|
||||
finishNode(typeParameter);
|
||||
typeParameters.push(typeParameter);
|
||||
if (token() === SyntaxKind.CommaToken) {
|
||||
// need to look for more type parameters
|
||||
nextJSDocToken();
|
||||
skipWhitespace();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (parseOptionalJsdoc(SyntaxKind.CommaToken));
|
||||
|
||||
if (constraint) {
|
||||
first(typeParameters).constraint = constraint.type;
|
||||
@@ -7038,6 +7025,14 @@ namespace ts {
|
||||
return currentToken = scanner.scanJSDocToken();
|
||||
}
|
||||
|
||||
function parseOptionalJsdoc(t: JsDocSyntaxKind): boolean {
|
||||
if (token() === t) {
|
||||
nextJSDocToken();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseJSDocEntityName(): EntityName {
|
||||
let entity: EntityName = parseJSDocIdentifierName(/*createIfMissing*/ true);
|
||||
if (parseOptional(SyntaxKind.OpenBracketToken)) {
|
||||
|
||||
Reference in New Issue
Block a user