Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / typescript-estree / dist / node-utils.d.ts
1 import * as ts from 'typescript';
2 import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree';
3 declare const SyntaxKind: typeof ts.SyntaxKind;
4 interface TokenToText {
5     [SyntaxKind.OpenBraceToken]: '{';
6     [SyntaxKind.CloseBraceToken]: '}';
7     [SyntaxKind.OpenParenToken]: '(';
8     [SyntaxKind.CloseParenToken]: ')';
9     [SyntaxKind.OpenBracketToken]: '[';
10     [SyntaxKind.CloseBracketToken]: ']';
11     [SyntaxKind.DotToken]: '.';
12     [SyntaxKind.DotDotDotToken]: '...';
13     [SyntaxKind.SemicolonToken]: ';';
14     [SyntaxKind.CommaToken]: ',';
15     [SyntaxKind.LessThanToken]: '<';
16     [SyntaxKind.GreaterThanToken]: '>';
17     [SyntaxKind.LessThanEqualsToken]: '<=';
18     [SyntaxKind.GreaterThanEqualsToken]: '>=';
19     [SyntaxKind.EqualsEqualsToken]: '==';
20     [SyntaxKind.ExclamationEqualsToken]: '!=';
21     [SyntaxKind.EqualsEqualsEqualsToken]: '===';
22     [SyntaxKind.InstanceOfKeyword]: 'instanceof';
23     [SyntaxKind.ExclamationEqualsEqualsToken]: '!==';
24     [SyntaxKind.EqualsGreaterThanToken]: '=>';
25     [SyntaxKind.PlusToken]: '+';
26     [SyntaxKind.MinusToken]: '-';
27     [SyntaxKind.AsteriskToken]: '*';
28     [SyntaxKind.AsteriskAsteriskToken]: '**';
29     [SyntaxKind.SlashToken]: '/';
30     [SyntaxKind.PercentToken]: '%';
31     [SyntaxKind.PlusPlusToken]: '++';
32     [SyntaxKind.MinusMinusToken]: '--';
33     [SyntaxKind.LessThanLessThanToken]: '<<';
34     [SyntaxKind.LessThanSlashToken]: '</';
35     [SyntaxKind.GreaterThanGreaterThanToken]: '>>';
36     [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>';
37     [SyntaxKind.AmpersandToken]: '&';
38     [SyntaxKind.BarToken]: '|';
39     [SyntaxKind.CaretToken]: '^';
40     [SyntaxKind.ExclamationToken]: '!';
41     [SyntaxKind.TildeToken]: '~';
42     [SyntaxKind.AmpersandAmpersandToken]: '&&';
43     [SyntaxKind.BarBarToken]: '||';
44     [SyntaxKind.QuestionToken]: '?';
45     [SyntaxKind.ColonToken]: ':';
46     [SyntaxKind.EqualsToken]: '=';
47     [SyntaxKind.PlusEqualsToken]: '+=';
48     [SyntaxKind.MinusEqualsToken]: '-=';
49     [SyntaxKind.AsteriskEqualsToken]: '*=';
50     [SyntaxKind.AsteriskAsteriskEqualsToken]: '**=';
51     [SyntaxKind.SlashEqualsToken]: '/=';
52     [SyntaxKind.PercentEqualsToken]: '%=';
53     [SyntaxKind.LessThanLessThanEqualsToken]: '<<=';
54     [SyntaxKind.GreaterThanGreaterThanEqualsToken]: '>>=';
55     [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>=';
56     [SyntaxKind.AmpersandEqualsToken]: '&=';
57     [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&=';
58     [SyntaxKind.BarEqualsToken]: '|=';
59     [SyntaxKind.BarBarEqualsToken]: '||=';
60     [SyntaxKind.CaretEqualsToken]: '^=';
61     [SyntaxKind.QuestionQuestionEqualsToken]: '??=';
62     [SyntaxKind.AtToken]: '@';
63     [SyntaxKind.InKeyword]: 'in';
64     [SyntaxKind.UniqueKeyword]: 'unique';
65     [SyntaxKind.KeyOfKeyword]: 'keyof';
66     [SyntaxKind.NewKeyword]: 'new';
67     [SyntaxKind.ImportKeyword]: 'import';
68     [SyntaxKind.ReadonlyKeyword]: 'readonly';
69     [SyntaxKind.QuestionQuestionToken]: '??';
70     [SyntaxKind.QuestionDotToken]: '?.';
71 }
72 /**
73  * Returns true if the given ts.Token is the assignment operator
74  * @param operator the operator token
75  * @returns is assignment
76  */
77 export declare function isAssignmentOperator<T extends ts.SyntaxKind>(operator: ts.Token<T>): boolean;
78 /**
79  * Returns true if the given ts.Token is a logical operator
80  * @param operator the operator token
81  * @returns is a logical operator
82  */
83 export declare function isLogicalOperator<T extends ts.SyntaxKind>(operator: ts.Token<T>): boolean;
84 /**
85  * Returns the string form of the given TSToken SyntaxKind
86  * @param kind the token's SyntaxKind
87  * @returns the token applicable token as a string
88  */
89 export declare function getTextForTokenKind<T extends ts.SyntaxKind>(kind: T): T extends keyof TokenToText ? TokenToText[T] : string | undefined;
90 /**
91  * Returns true if the given ts.Node is a valid ESTree class member
92  * @param node TypeScript AST node
93  * @returns is valid ESTree class member
94  */
95 export declare function isESTreeClassMember(node: ts.Node): boolean;
96 /**
97  * Checks if a ts.Node has a modifier
98  * @param modifierKind TypeScript SyntaxKind modifier
99  * @param node TypeScript AST node
100  * @returns has the modifier specified
101  */
102 export declare function hasModifier(modifierKind: ts.KeywordSyntaxKind, node: ts.Node): boolean;
103 /**
104  * Get last last modifier in ast
105  * @param node TypeScript AST node
106  * @returns returns last modifier if present or null
107  */
108 export declare function getLastModifier(node: ts.Node): ts.Modifier | null;
109 /**
110  * Returns true if the given ts.Token is a comma
111  * @param token the TypeScript token
112  * @returns is comma
113  */
114 export declare function isComma(token: ts.Node): boolean;
115 /**
116  * Returns true if the given ts.Node is a comment
117  * @param node the TypeScript node
118  * @returns is comment
119  */
120 export declare function isComment(node: ts.Node): boolean;
121 /**
122  * Returns true if the given ts.Node is a JSDoc comment
123  * @param node the TypeScript node
124  * @returns is JSDoc comment
125  */
126 export declare function isJSDocComment(node: ts.Node): boolean;
127 /**
128  * Returns the binary expression type of the given ts.Token
129  * @param operator the operator token
130  * @returns the binary expression type
131  */
132 export declare function getBinaryExpressionType<T extends ts.SyntaxKind>(operator: ts.Token<T>): AST_NODE_TYPES.AssignmentExpression | AST_NODE_TYPES.LogicalExpression | AST_NODE_TYPES.BinaryExpression;
133 /**
134  * Returns line and column data for the given positions,
135  * @param pos position to check
136  * @param ast the AST object
137  * @returns line and column
138  */
139 export declare function getLineAndCharacterFor(pos: number, ast: ts.SourceFile): TSESTree.LineAndColumnData;
140 /**
141  * Returns line and column data for the given start and end positions,
142  * for the given AST
143  * @param start start data
144  * @param end   end data
145  * @param ast   the AST object
146  * @returns the loc data
147  */
148 export declare function getLocFor(start: number, end: number, ast: ts.SourceFile): TSESTree.SourceLocation;
149 /**
150  * Check whatever node can contain directive
151  * @param node
152  * @returns returns true if node can contain directive
153  */
154 export declare function canContainDirective(node: ts.SourceFile | ts.Block | ts.ModuleBlock): boolean;
155 /**
156  * Returns range for the given ts.Node
157  * @param node the ts.Node or ts.Token
158  * @param ast the AST object
159  * @returns the range data
160  */
161 export declare function getRange(node: ts.Node, ast: ts.SourceFile): [number, number];
162 /**
163  * Returns true if a given ts.Node is a token
164  * @param node the ts.Node
165  * @returns is a token
166  */
167 export declare function isToken(node: ts.Node): boolean;
168 /**
169  * Returns true if a given ts.Node is a JSX token
170  * @param node ts.Node to be checked
171  * @returns is a JSX token
172  */
173 export declare function isJSXToken(node: ts.Node): boolean;
174 /**
175  * Returns the declaration kind of the given ts.Node
176  * @param node TypeScript AST node
177  * @returns declaration kind
178  */
179 export declare function getDeclarationKind(node: ts.VariableDeclarationList): 'let' | 'const' | 'var';
180 /**
181  * Gets a ts.Node's accessibility level
182  * @param node The ts.Node
183  * @returns accessibility "public", "protected", "private", or null
184  */
185 export declare function getTSNodeAccessibility(node: ts.Node): 'public' | 'protected' | 'private' | null;
186 /**
187  * Finds the next token based on the previous one and its parent
188  * Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren
189  * @param previousToken The previous TSToken
190  * @param parent The parent TSNode
191  * @param ast The TS AST
192  * @returns the next TSToken
193  */
194 export declare function findNextToken(previousToken: ts.TextRange, parent: ts.Node, ast: ts.SourceFile): ts.Node | undefined;
195 /**
196  * Find the first matching ancestor based on the given predicate function.
197  * @param node The current ts.Node
198  * @param predicate The predicate function to apply to each checked ancestor
199  * @returns a matching parent ts.Node
200  */
201 export declare function findFirstMatchingAncestor(node: ts.Node, predicate: (node: ts.Node) => boolean): ts.Node | undefined;
202 /**
203  * Returns true if a given ts.Node has a JSX token within its hierarchy
204  * @param node ts.Node to be checked
205  * @returns has JSX ancestor
206  */
207 export declare function hasJSXAncestor(node: ts.Node): boolean;
208 /**
209  * Unescape the text content of string literals, e.g. &amp; -> &
210  * @param text The escaped string literal text.
211  * @returns The unescaped string literal text.
212  */
213 export declare function unescapeStringLiteralText(text: string): string;
214 /**
215  * Returns true if a given ts.Node is a computed property
216  * @param node ts.Node to be checked
217  * @returns is Computed Property
218  */
219 export declare function isComputedProperty(node: ts.Node): boolean;
220 /**
221  * Returns true if a given ts.Node is optional (has QuestionToken)
222  * @param node ts.Node to be checked
223  * @returns is Optional
224  */
225 export declare function isOptional(node: {
226     questionToken?: ts.QuestionToken;
227 }): boolean;
228 /**
229  * Returns true if the node is an optional chain node
230  */
231 export declare function isOptionalChain(node: TSESTree.Node): node is TSESTree.OptionalCallExpression | TSESTree.OptionalMemberExpression;
232 /**
233  * Returns true of the child of property access expression is an optional chain
234  */
235 export declare function isChildOptionalChain(node: ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.CallExpression, object: TSESTree.LeftHandSideExpression): boolean;
236 /**
237  * Returns the type of a given ts.Token
238  * @param token the ts.Token
239  * @returns the token type
240  */
241 export declare function getTokenType(token: ts.Identifier | ts.Token<ts.SyntaxKind>): Exclude<AST_TOKEN_TYPES, AST_TOKEN_TYPES.Line | AST_TOKEN_TYPES.Block>;
242 /**
243  * Extends and formats a given ts.Token, for a given AST
244  * @param token the ts.Token
245  * @param ast   the AST object
246  * @returns the converted Token
247  */
248 export declare function convertToken(token: ts.Node, ast: ts.SourceFile): TSESTree.Token;
249 /**
250  * Converts all tokens for the given AST
251  * @param ast the AST object
252  * @returns the converted Tokens
253  */
254 export declare function convertTokens(ast: ts.SourceFile): TSESTree.Token[];
255 export interface TSError {
256     index: number;
257     lineNumber: number;
258     column: number;
259     message: string;
260 }
261 /**
262  * @param ast     the AST object
263  * @param start      the index at which the error starts
264  * @param message the error message
265  * @returns converted error object
266  */
267 export declare function createError(ast: ts.SourceFile, start: number, message: string): TSError;
268 /**
269  * @param n the TSNode
270  * @param ast the TS AST
271  */
272 export declare function nodeHasTokens(n: ts.Node, ast: ts.SourceFile): boolean;
273 /**
274  * Like `forEach`, but suitable for use with numbers and strings (which may be falsy).
275  * @template T
276  * @template U
277  * @param array
278  * @param callback
279  */
280 export declare function firstDefined<T, U>(array: readonly T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined;
281 export {};
282 //# sourceMappingURL=node-utils.d.ts.map