Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c0ca4a

Browse files
authored
refactor(typescript-estree): add missing type guards to node utils (typescript-eslint#3102)
1 parent 66dc285 commit 0c0ca4a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/typescript-estree/src/node-utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ export function getLastModifier(node: ts.Node): ts.Modifier | null {
165165
* @param token the TypeScript token
166166
* @returns is comma
167167
*/
168-
export function isComma(token: ts.Node): boolean {
168+
export function isComma(
169+
token: ts.Node,
170+
): token is ts.Token<ts.SyntaxKind.CommaToken> {
169171
return token.kind === SyntaxKind.CommaToken;
170172
}
171173

@@ -186,7 +188,7 @@ export function isComment(node: ts.Node): boolean {
186188
* @param node the TypeScript node
187189
* @returns is JSDoc comment
188190
*/
189-
export function isJSDocComment(node: ts.Node): boolean {
191+
export function isJSDocComment(node: ts.Node): node is ts.JSDoc {
190192
return node.kind === SyntaxKind.JSDocComment;
191193
}
192194

@@ -285,7 +287,7 @@ export function getRange(node: ts.Node, ast: ts.SourceFile): [number, number] {
285287
* @param node the ts.Node
286288
* @returns is a token
287289
*/
288-
export function isToken(node: ts.Node): boolean {
290+
export function isToken(node: ts.Node): node is ts.Token<ts.TokenSyntaxKind> {
289291
return (
290292
node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken
291293
);
@@ -434,7 +436,9 @@ export function unescapeStringLiteralText(text: string): string {
434436
* @param node ts.Node to be checked
435437
* @returns is Computed Property
436438
*/
437-
export function isComputedProperty(node: ts.Node): boolean {
439+
export function isComputedProperty(
440+
node: ts.Node,
441+
): node is ts.ComputedPropertyName {
438442
return node.kind === SyntaxKind.ComputedPropertyName;
439443
}
440444

@@ -471,15 +475,11 @@ export function isChildUnwrappableOptionalChain(
471475
| ts.NonNullExpression,
472476
child: TSESTree.Node,
473477
): boolean {
474-
if (
478+
return (
475479
isChainExpression(child) &&
476480
// (x?.y).z is semantically different, and as such .z is no longer optional
477481
node.expression.kind !== ts.SyntaxKind.ParenthesizedExpression
478-
) {
479-
return true;
480-
}
481-
482-
return false;
482+
);
483483
}
484484

485485
/**
@@ -586,7 +586,7 @@ export function getTokenType(
586586
* @returns the converted Token
587587
*/
588588
export function convertToken(
589-
token: ts.Node,
589+
token: ts.Token<ts.TokenSyntaxKind>,
590590
ast: ts.SourceFile,
591591
): TSESTree.Token {
592592
const start =

0 commit comments

Comments
 (0)