Skip to content

chore(types): improve typing for getTokenType and convertBodyExpressions #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Converter {
private convertBodyExpressions(
nodes: ts.NodeArray<ts.Statement>,
parent: ts.SourceFile | ts.Block | ts.ModuleBlock,
): any[] {
): TSESTree.Statement[] {
let allowDirectives = canContainDirective(parent);

return (
Expand Down Expand Up @@ -400,7 +400,7 @@ export class Converter {
: null;
} else if (key === 'decorators') {
if (node.decorators && node.decorators.length) {
result.decorators = node.decorators.map((el: any) =>
result.decorators = node.decorators.map(el =>
this.convertChild(el),
);
}
Expand Down Expand Up @@ -1340,7 +1340,7 @@ export class Converter {
}

case SyntaxKind.Parameter: {
let parameter: any;
let parameter: TSESTree.RestElement | TSESTree.BindingName;
let result: TSESTree.RestElement | TSESTree.AssignmentPattern;

if (node.dotDotDotToken) {
Expand All @@ -1349,7 +1349,7 @@ export class Converter {
argument: this.convertChild(node.name),
});
} else if (node.initializer) {
parameter = this.convertChild(node.name);
parameter = this.convertChild(node.name) as TSESTree.BindingName;
result = this.createNode<TSESTree.AssignmentPattern>(node, {
type: AST_NODE_TYPES.AssignmentPattern,
left: parameter,
Expand Down Expand Up @@ -1584,7 +1584,7 @@ export class Converter {

case SyntaxKind.PrefixUnaryExpression:
case SyntaxKind.PostfixUnaryExpression: {
const operator = (getTextForTokenKind(node.operator) ?? '') as any;
const operator = getTextForTokenKind(node.operator) ?? '';
/**
* ESTree uses UpdateExpression for ++/--
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/typescript-estree/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ export function isOptional(node: {
* @param token the ts.Token
* @returns the token type
*/
// ts.Node types are ugly
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getTokenType(token: any): AST_TOKEN_TYPES {
export function getTokenType(
token: ts.Identifier | ts.Token<ts.SyntaxKind>,
): AST_TOKEN_TYPES {
// Need two checks for keywords since some are also identifiers
if (token.originalKeywordKind) {
if ('originalKeywordKind' in token && token.originalKeywordKind) {
switch (token.originalKeywordKind) {
case SyntaxKind.NullKeyword:
return AST_TOKEN_TYPES.Null;
Expand Down Expand Up @@ -572,7 +572,7 @@ export function convertToken(
loc: getLocFor(start, end, ast),
};

if (newToken.type === 'RegularExpression') {
if (newToken.type === AST_TOKEN_TYPES.RegularExpression) {
newToken.regex = {
pattern: value.slice(1, value.lastIndexOf('/')),
flags: value.slice(value.lastIndexOf('/') + 1),
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy