1import * as ts from 'typescript';
2import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree';
3declare const SyntaxKind: typeof ts.SyntaxKind;
4interface 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.BarEqualsToken]: '|=';
58    [SyntaxKind.CaretEqualsToken]: '^=';
59    [SyntaxKind.AtToken]: '@';
60    [SyntaxKind.InKeyword]: 'in';
61    [SyntaxKind.UniqueKeyword]: 'unique';
62    [SyntaxKind.KeyOfKeyword]: 'keyof';
63    [SyntaxKind.NewKeyword]: 'new';
64    [SyntaxKind.ImportKeyword]: 'import';
65    [SyntaxKind.ReadonlyKeyword]: 'readonly';
66    [SyntaxKind.QuestionQuestionToken]: '??';
67    [SyntaxKind.QuestionDotToken]: '?.';
68}
69/**
70 * Returns true if the given ts.Token is the assignment operator
71 * @param operator the operator token
72 * @returns is assignment
73 */
74export declare function isAssignmentOperator<T extends ts.SyntaxKind>(operator: ts.Token<T>): boolean;
75/**
76 * Returns true if the given ts.Token is a logical operator
77 * @param operator the operator token
78 * @returns is a logical operator
79 */
80export declare function isLogicalOperator<T extends ts.SyntaxKind>(operator: ts.Token<T>): boolean;
81/**
82 * Returns the string form of the given TSToken SyntaxKind
83 * @param kind the token's SyntaxKind
84 * @returns the token applicable token as a string
85 */
86export declare function getTextForTokenKind<T extends ts.SyntaxKind>(kind: T): T extends keyof TokenToText ? TokenToText[T] : string | undefined;
87/**
88 * Returns true if the given ts.Node is a valid ESTree class member
89 * @param node TypeScript AST node
90 * @returns is valid ESTree class member
91 */
92export declare function isESTreeClassMember(node: ts.Node): boolean;
93/**
94 * Checks if a ts.Node has a modifier
95 * @param modifierKind TypeScript SyntaxKind modifier
96 * @param node TypeScript AST node
97 * @returns has the modifier specified
98 */
99export declare function hasModifier(modifierKind: ts.KeywordSyntaxKind, node: ts.Node): boolean;
100/**
101 * Get last last modifier in ast
102 * @param node TypeScript AST node
103 * @returns returns last modifier if present or null
104 */
105export declare function getLastModifier(node: ts.Node): ts.Modifier | null;
106/**
107 * Returns true if the given ts.Token is a comma
108 * @param token the TypeScript token
109 * @returns is comma
110 */
111export declare function isComma(token: ts.Node): boolean;
112/**
113 * Returns true if the given ts.Node is a comment
114 * @param node the TypeScript node
115 * @returns is comment
116 */
117export declare function isComment(node: ts.Node): boolean;
118/**
119 * Returns true if the given ts.Node is a JSDoc comment
120 * @param node the TypeScript node
121 * @returns is JSDoc comment
122 */
123export declare function isJSDocComment(node: ts.Node): boolean;
124/**
125 * Returns the binary expression type of the given ts.Token
126 * @param operator the operator token
127 * @returns the binary expression type
128 */
129export declare function getBinaryExpressionType<T extends ts.SyntaxKind>(operator: ts.Token<T>): AST_NODE_TYPES.AssignmentExpression | AST_NODE_TYPES.LogicalExpression | AST_NODE_TYPES.BinaryExpression;
130/**
131 * Returns line and column data for the given positions,
132 * @param pos position to check
133 * @param ast the AST object
134 * @returns line and column
135 */
136export declare function getLineAndCharacterFor(pos: number, ast: ts.SourceFile): TSESTree.LineAndColumnData;
137/**
138 * Returns line and column data for the given start and end positions,
139 * for the given AST
140 * @param start start data
141 * @param end   end data
142 * @param ast   the AST object
143 * @returns the loc data
144 */
145export declare function getLocFor(start: number, end: number, ast: ts.SourceFile): TSESTree.SourceLocation;
146/**
147 * Check whatever node can contain directive
148 * @param node
149 * @returns returns true if node can contain directive
150 */
151export declare function canContainDirective(node: ts.SourceFile | ts.Block | ts.ModuleBlock): boolean;
152/**
153 * Returns range for the given ts.Node
154 * @param node the ts.Node or ts.Token
155 * @param ast the AST object
156 * @returns the range data
157 */
158export declare function getRange(node: ts.Node, ast: ts.SourceFile): [number, number];
159/**
160 * Returns true if a given ts.Node is a token
161 * @param node the ts.Node
162 * @returns is a token
163 */
164export declare function isToken(node: ts.Node): boolean;
165/**
166 * Returns true if a given ts.Node is a JSX token
167 * @param node ts.Node to be checked
168 * @returns is a JSX token
169 */
170export declare function isJSXToken(node: ts.Node): boolean;
171/**
172 * Returns the declaration kind of the given ts.Node
173 * @param node TypeScript AST node
174 * @returns declaration kind
175 */
176export declare function getDeclarationKind(node: ts.VariableDeclarationList): 'let' | 'const' | 'var';
177/**
178 * Gets a ts.Node's accessibility level
179 * @param node The ts.Node
180 * @returns accessibility "public", "protected", "private", or null
181 */
182export declare function getTSNodeAccessibility(node: ts.Node): 'public' | 'protected' | 'private' | null;
183/**
184 * Finds the next token based on the previous one and its parent
185 * Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren
186 * @param previousToken The previous TSToken
187 * @param parent The parent TSNode
188 * @param ast The TS AST
189 * @returns the next TSToken
190 */
191export declare function findNextToken(previousToken: ts.TextRange, parent: ts.Node, ast: ts.SourceFile): ts.Node | undefined;
192/**
193 * Find the first matching ancestor based on the given predicate function.
194 * @param node The current ts.Node
195 * @param predicate The predicate function to apply to each checked ancestor
196 * @returns a matching parent ts.Node
197 */
198export declare function findFirstMatchingAncestor(node: ts.Node, predicate: (node: ts.Node) => boolean): ts.Node | undefined;
199/**
200 * Returns true if a given ts.Node has a JSX token within its hierarchy
201 * @param node ts.Node to be checked
202 * @returns has JSX ancestor
203 */
204export declare function hasJSXAncestor(node: ts.Node): boolean;
205/**
206 * Unescape the text content of string literals, e.g. &amp; -> &
207 * @param text The escaped string literal text.
208 * @returns The unescaped string literal text.
209 */
210export declare function unescapeStringLiteralText(text: string): string;
211/**
212 * Returns true if a given ts.Node is a computed property
213 * @param node ts.Node to be checked
214 * @returns is Computed Property
215 */
216export declare function isComputedProperty(node: ts.Node): boolean;
217/**
218 * Returns true if a given ts.Node is optional (has QuestionToken)
219 * @param node ts.Node to be checked
220 * @returns is Optional
221 */
222export declare function isOptional(node: {
223    questionToken?: ts.QuestionToken;
224}): boolean;
225/**
226 * Returns true if the node is an optional chain node
227 */
228export declare function isOptionalChain(node: TSESTree.Node): node is TSESTree.OptionalCallExpression | TSESTree.OptionalMemberExpression;
229/**
230 * Returns true of the child of property access expression is an optional chain
231 */
232export declare function isChildOptionalChain(node: ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.CallExpression, object: TSESTree.LeftHandSideExpression): boolean;
233/**
234 * Returns the type of a given ts.Token
235 * @param token the ts.Token
236 * @returns the token type
237 */
238export declare function getTokenType(token: ts.Identifier | ts.Token<ts.SyntaxKind>): Exclude<AST_TOKEN_TYPES, AST_TOKEN_TYPES.Line | AST_TOKEN_TYPES.Block>;
239/**
240 * Extends and formats a given ts.Token, for a given AST
241 * @param token the ts.Token
242 * @param ast   the AST object
243 * @returns the converted Token
244 */
245export declare function convertToken(token: ts.Node, ast: ts.SourceFile): TSESTree.Token;
246/**
247 * Converts all tokens for the given AST
248 * @param ast the AST object
249 * @returns the converted Tokens
250 */
251export declare function convertTokens(ast: ts.SourceFile): TSESTree.Token[];
252export interface TSError {
253    index: number;
254    lineNumber: number;
255    column: number;
256    message: string;
257}
258/**
259 * @param ast     the AST object
260 * @param start      the index at which the error starts
261 * @param message the error message
262 * @returns converted error object
263 */
264export declare function createError(ast: ts.SourceFile, start: number, message: string): TSError;
265/**
266 * @param n the TSNode
267 * @param ast the TS AST
268 */
269export declare function nodeHasTokens(n: ts.Node, ast: ts.SourceFile): boolean;
270/**
271 * Like `forEach`, but suitable for use with numbers and strings (which may be falsy).
272 * @template T
273 * @template U
274 * @param array
275 * @param callback
276 */
277export declare function firstDefined<T, U>(array: readonly T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined;
278export {};
279//# sourceMappingURL=node-utils.d.ts.map