Skip to content

Commit 46f4bd4

Browse files
committed
Allow keywords in jsdoc comments parsing
1 parent 350f62f commit 46f4bd4

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

src/compiler/parser.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ namespace ts {
886886

887887
/** Invokes the provided callback then unconditionally restores the parser to the state it
888888
* was in immediately prior to invoking the callback. The result of invoking the callback
889-
* is returned from this function.
889+
* is returned from this function.
890890
*/
891891
function lookAhead<T>(callback: () => T): T {
892892
return speculationHelper(callback, /*isLookAhead*/ true);
@@ -4988,7 +4988,7 @@ namespace ts {
49884988

49894989
if (token === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) {
49904990
// We need to ensure that any subsequent modifiers appear on the same line
4991-
// so that when 'const' is a standalone declaration, we don't issue an error.
4991+
// so that when 'const' is a standalone declaration, we don't issue an error.
49924992
if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) {
49934993
break;
49944994
}
@@ -5251,7 +5251,7 @@ namespace ts {
52515251
node.decorators = decorators;
52525252
setModifiers(node, modifiers);
52535253
if (token === SyntaxKind.GlobalKeyword) {
5254-
// parse 'global' as name of global scope augmentation
5254+
// parse 'global' as name of global scope augmentation
52555255
node.name = parseIdentifier();
52565256
node.flags |= NodeFlags.GlobalAugmentation;
52575257
}
@@ -6087,7 +6087,7 @@ namespace ts {
60876087
atToken.end = scanner.getTextPos();
60886088
nextJSDocToken();
60896089

6090-
const tagName = parseJSDocIdentifier();
6090+
const tagName = parseJSDocIdentifierName();
60916091
if (!tagName) {
60926092
return;
60936093
}
@@ -6150,7 +6150,7 @@ namespace ts {
61506150
let isBracketed: boolean;
61516151
// Looking for something like '[foo]' or 'foo'
61526152
if (parseOptionalToken(SyntaxKind.OpenBracketToken)) {
6153-
name = parseJSDocIdentifier();
6153+
name = parseJSDocIdentifierName();
61546154
isBracketed = true;
61556155

61566156
// May have an optional default, e.g. '[foo = 42]'
@@ -6160,8 +6160,8 @@ namespace ts {
61606160

61616161
parseExpected(SyntaxKind.CloseBracketToken);
61626162
}
6163-
else if (token === SyntaxKind.Identifier || isTSOnlyKeyword(token)) {
6164-
name = parseJSDocIdentifier();
6163+
else if (tokenIsIdentifierOrKeyword(token)) {
6164+
name = parseJSDocIdentifierName();
61656165
}
61666166

61676167
if (!name) {
@@ -6225,7 +6225,7 @@ namespace ts {
62256225
typeParameters.pos = scanner.getStartPos();
62266226

62276227
while (true) {
6228-
const name = parseJSDocIdentifier();
6228+
const name = parseJSDocIdentifierName();
62296229
if (!name) {
62306230
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
62316231
return undefined;
@@ -6258,8 +6258,12 @@ namespace ts {
62586258
return token = scanner.scanJSDocToken();
62596259
}
62606260

6261-
function parseJSDocIdentifier(): Identifier {
6262-
if (token !== SyntaxKind.Identifier && !isTSOnlyKeyword(token)) {
6261+
function parseJSDocIdentifierName(): Identifier {
6262+
return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token));
6263+
}
6264+
6265+
function createJSDocIdentifier(isIdentifier: boolean): Identifier {
6266+
if (!isIdentifier) {
62636267
parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
62646268
return undefined;
62656269
}

src/compiler/utilities.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,27 +1667,6 @@ namespace ts {
16671667
return SyntaxKind.FirstKeyword <= token && token <= SyntaxKind.LastKeyword;
16681668
}
16691669

1670-
// Some keywords are TypeScript only, so they should not be parsed as considered as
1671-
// keywords in JavaScript
1672-
export function isJSKeyword(token: SyntaxKind): boolean {
1673-
switch (token) {
1674-
case SyntaxKind.TypeKeyword:
1675-
case SyntaxKind.AsKeyword:
1676-
case SyntaxKind.AnyKeyword:
1677-
case SyntaxKind.DeclareKeyword:
1678-
case SyntaxKind.IsKeyword:
1679-
case SyntaxKind.ReadonlyKeyword:
1680-
case SyntaxKind.FromKeyword:
1681-
return false;
1682-
default:
1683-
return isKeyword(token);
1684-
}
1685-
}
1686-
1687-
export function isTSOnlyKeyword(token: SyntaxKind): boolean {
1688-
return isKeyword(token) && !isJSKeyword(token);
1689-
}
1690-
16911670
export function isTrivia(token: SyntaxKind) {
16921671
return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken;
16931672
}

0 commit comments

Comments
 (0)