UNPKG

16.5 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { NodeWrap } from './convert-ast';
3export declare function getChildOfKind<T extends ts.SyntaxKind>(node: ts.Node, kind: T, sourceFile?: ts.SourceFile): ts.Token<T> | undefined;
4export declare function isTokenKind(kind: ts.SyntaxKind): boolean;
5export declare function isNodeKind(kind: ts.SyntaxKind): boolean;
6export declare function isAssignmentKind(kind: ts.SyntaxKind): boolean;
7export declare function isTypeNodeKind(kind: ts.SyntaxKind): boolean;
8export declare function isJsDocKind(kind: ts.SyntaxKind): boolean;
9export declare function isKeywordKind(kind: ts.SyntaxKind): boolean;
10export declare function isThisParameter(parameter: ts.ParameterDeclaration): boolean;
11export declare function getModifier(node: ts.Node, kind: ts.Modifier['kind']): ts.Modifier | undefined;
12export declare function hasModifier(modifiers: ts.ModifiersArray | undefined, ...kinds: Array<ts.Modifier['kind']>): boolean;
13export declare function isParameterProperty(node: ts.ParameterDeclaration): boolean;
14export declare function hasAccessModifier(node: ts.ClassElement | ts.ParameterDeclaration): boolean;
15export declare const isNodeFlagSet: (node: ts.Node, flag: ts.NodeFlags) => boolean;
16export declare const isTypeFlagSet: (type: ts.Type, flag: ts.TypeFlags) => boolean;
17export declare const isSymbolFlagSet: (symbol: ts.Symbol, flag: ts.SymbolFlags) => boolean;
18export declare function isObjectFlagSet(objectType: ts.ObjectType, flag: ts.ObjectFlags): boolean;
19export declare function isModifierFlagSet(node: ts.Node, flag: ts.ModifierFlags): boolean;
20export declare function getPreviousStatement(statement: ts.Statement): ts.Statement | undefined;
21export declare function getNextStatement(statement: ts.Statement): ts.Statement | undefined;
22/** Returns the token before the start of `node` or `undefined` if there is none. */
23export declare function getPreviousToken(node: ts.Node, sourceFile?: ts.SourceFile): ts.Node | undefined;
24/** Returns the next token that begins after the end of `node`. Returns `undefined` for SourceFile and EndOfFileToken */
25export declare function getNextToken(node: ts.Node, sourceFile?: ts.SourceFile): ts.Node | undefined;
26/** Returns the token at or following the specified position or undefined if none is found inside `parent`. */
27export declare function getTokenAtPosition(parent: ts.Node, pos: number, sourceFile?: ts.SourceFile, allowJsDoc?: boolean): ts.Node | undefined;
28/**
29 * Return the comment at the specified position.
30 * You can pass an optional `parent` to avoid some work finding the corresponding token starting at `sourceFile`.
31 * If the `parent` parameter is passed, `pos` must be between `parent.pos` and `parent.end`.
32*/
33export declare function getCommentAtPosition(sourceFile: ts.SourceFile, pos: number, parent?: ts.Node): ts.CommentRange | undefined;
34/**
35 * Returns whether the specified position is inside a comment.
36 * You can pass an optional `parent` to avoid some work finding the corresponding token starting at `sourceFile`.
37 * If the `parent` parameter is passed, `pos` must be between `parent.pos` and `parent.end`.
38 */
39export declare function isPositionInComment(sourceFile: ts.SourceFile, pos: number, parent?: ts.Node): boolean;
40export declare function commentText(sourceText: string, comment: ts.CommentRange): string;
41/** Returns the deepest AST Node at `pos`. Returns undefined if `pos` is outside of the range of `node` */
42export declare function getAstNodeAtPosition(node: ts.Node, pos: number): ts.Node | undefined;
43/**
44 * Returns the NodeWrap of deepest AST node that contains `pos` between its `pos` and `end`.
45 * Only returns undefined if pos is outside of `wrap`
46 */
47export declare function getWrappedNodeAtPosition(wrap: NodeWrap, pos: number): NodeWrap | undefined;
48export declare function getPropertyName(propertyName: ts.PropertyName): string | undefined;
49export declare function forEachDestructuringIdentifier<T>(pattern: ts.BindingPattern, fn: (element: ts.BindingElement & {
50 name: ts.Identifier;
51}) => T): T | undefined;
52export declare function forEachDeclaredVariable<T>(declarationList: ts.VariableDeclarationList, cb: (element: (ts.VariableDeclaration | ts.BindingElement) & {
53 name: ts.Identifier;
54}) => T): T | undefined;
55export declare enum VariableDeclarationKind {
56 Var = 0,
57 Let = 1,
58 Const = 2
59}
60export declare function getVariableDeclarationKind(declarationList: ts.VariableDeclarationList): VariableDeclarationKind;
61export declare function isBlockScopedVariableDeclarationList(declarationList: ts.VariableDeclarationList): boolean;
62export declare function isBlockScopedVariableDeclaration(declaration: ts.VariableDeclaration): boolean;
63export declare function isBlockScopedDeclarationStatement(statement: ts.Statement): statement is ts.DeclarationStatement;
64export declare function isInSingleStatementContext(statement: ts.Statement): boolean;
65export declare enum ScopeBoundary {
66 None = 0,
67 Function = 1,
68 Block = 2,
69 Type = 4,
70 ConditionalType = 8
71}
72export declare enum ScopeBoundarySelector {
73 Function = 1,
74 Block = 3,
75 Type = 7,
76 InferType = 8
77}
78export declare function isScopeBoundary(node: ts.Node): ScopeBoundary;
79export declare function isTypeScopeBoundary(node: ts.Node): ScopeBoundary;
80export declare function isFunctionScopeBoundary(node: ts.Node): ScopeBoundary;
81export declare function isBlockScopeBoundary(node: ts.Node): ScopeBoundary;
82/** Returns true for scope boundaries that have their own `this` reference instead of inheriting it from the containing scope */
83export declare function hasOwnThisReference(node: ts.Node): boolean;
84export declare function isFunctionWithBody(node: ts.Node): node is ts.FunctionLikeDeclaration & {
85 body: {};
86};
87/**
88 * Iterate over all tokens of `node`
89 *
90 * @param node The node whose tokens should be visited
91 * @param cb Is called for every token contained in `node`
92 */
93export declare function forEachToken(node: ts.Node, cb: (node: ts.Node) => void, sourceFile?: ts.SourceFile): void;
94export declare type ForEachTokenCallback = (fullText: string, kind: ts.SyntaxKind, range: ts.TextRange, parent: ts.Node) => void;
95/**
96 * Iterate over all tokens and trivia of `node`
97 *
98 * @description JsDoc comments are treated like regular comments
99 *
100 * @param node The node whose tokens should be visited
101 * @param cb Is called for every token contained in `node` and trivia before the token
102 */
103export declare function forEachTokenWithTrivia(node: ts.Node, cb: ForEachTokenCallback, sourceFile?: ts.SourceFile): void;
104export declare type ForEachCommentCallback = (fullText: string, comment: ts.CommentRange) => void;
105/** Iterate over all comments owned by `node` or its children */
106export declare function forEachComment(node: ts.Node, cb: ForEachCommentCallback, sourceFile?: ts.SourceFile): void;
107export interface LineRange extends ts.TextRange {
108 contentLength: number;
109}
110export declare function getLineRanges(sourceFile: ts.SourceFile): LineRange[];
111/** Get the line break style used in sourceFile. This function only looks at the first line break. If there is none, \n is assumed. */
112export declare function getLineBreakStyle(sourceFile: ts.SourceFile): "\n" | "\r\n";
113/**
114 * Determines whether the given text parses as a standalone identifier.
115 * This is not a guarantee that it works in every context. The property name in PropertyAccessExpressions for example allows reserved words.
116 * Depending on the context it could be parsed as contextual keyword or TypeScript keyword.
117 */
118export declare function isValidIdentifier(text: string, languageVersion?: ts.ScriptTarget): boolean;
119/**
120 * Determines whether the given text can be used to access a property with a PropertyAccessExpression while preserving the property's name.
121 */
122export declare function isValidPropertyAccess(text: string, languageVersion?: ts.ScriptTarget): boolean;
123/**
124 * Determines whether the given text can be used as unquoted name of a property declaration while preserving the property's name.
125 */
126export declare function isValidPropertyName(text: string, languageVersion?: ts.ScriptTarget): boolean;
127/**
128 * Determines whether the given text can be parsed as a numeric literal.
129 */
130export declare function isValidNumericLiteral(text: string, languageVersion?: ts.ScriptTarget): boolean;
131/**
132 * Determines whether the given text can be used as JSX tag or attribute name while preserving the exact name.
133 */
134export declare function isValidJsxIdentifier(text: string, languageVersion?: ts.ScriptTarget): boolean;
135export declare function isNumericPropertyName(name: string | ts.__String): boolean;
136export declare function isSameLine(sourceFile: ts.SourceFile, pos1: number, pos2: number): boolean;
137export declare enum SideEffectOptions {
138 None = 0,
139 TaggedTemplate = 1,
140 Constructor = 2,
141 JsxElement = 4
142}
143export declare function hasSideEffects(node: ts.Expression, options?: SideEffectOptions): boolean;
144/** Returns the VariableDeclaration or ParameterDeclaration that contains the BindingElement */
145export declare function getDeclarationOfBindingElement(node: ts.BindingElement): ts.VariableDeclaration | ts.ParameterDeclaration;
146export declare function isExpressionValueUsed(node: ts.Expression): boolean;
147export declare enum AccessKind {
148 None = 0,
149 Read = 1,
150 Write = 2,
151 Delete = 4,
152 ReadWrite = 3,
153 Modification = 6
154}
155export declare function getAccessKind(node: ts.Node): AccessKind;
156export declare function isReassignmentTarget(node: ts.Expression): boolean;
157export declare function canHaveJsDoc(node: ts.Node): node is ts.HasJSDoc;
158/** Gets the JSDoc of a node. For performance reasons this function should only be called when `canHaveJsDoc` returns true. */
159export declare function getJsDoc(node: ts.Node, sourceFile?: ts.SourceFile): ts.JSDoc[];
160/**
161 * Parses the JsDoc of any node. This function is made for nodes that don't get their JsDoc parsed by the TypeScript parser.
162 *
163 * @param considerTrailingComments When set to `true` this function uses the trailing comments if the node starts on the same line
164 * as the previous node ends.
165 */
166export declare function parseJsDocOfNode(node: ts.Node, considerTrailingComments?: boolean, sourceFile?: ts.SourceFile): ts.JSDoc[];
167export declare enum ImportKind {
168 ImportDeclaration = 1,
169 ImportEquals = 2,
170 ExportFrom = 4,
171 DynamicImport = 8,
172 Require = 16,
173 ImportType = 32,
174 All = 63,
175 AllImports = 59,
176 AllStaticImports = 3,
177 AllImportExpressions = 24,
178 AllRequireLike = 18
179}
180export declare function findImports(sourceFile: ts.SourceFile, kinds: ImportKind, ignoreFileName?: boolean): (ts.StringLiteral | ts.NoSubstitutionTemplateLiteral)[];
181export declare type ImportLike = ts.ImportDeclaration | ts.ImportEqualsDeclaration & {
182 moduleReference: ts.ExternalModuleReference;
183} | ts.ExportDeclaration & {
184 moduleSpecifier: {};
185} | ts.CallExpression & {
186 expression: ts.Token<ts.SyntaxKind.ImportKeyword> | ts.Identifier & {
187 text: 'require';
188 };
189 arguments: [ts.Expression, ...ts.Expression[]];
190} | ts.ImportTypeNode;
191export declare function findImportLikeNodes(sourceFile: ts.SourceFile, kinds: ImportKind, ignoreFileName?: boolean): ImportLike[];
192/**
193 * Ambient context means the statement itself has the `declare` keyword
194 * or is inside a `declare namespace`, `delcare module` or `declare global`.
195 */
196export declare function isStatementInAmbientContext(node: ts.Statement): boolean;
197/** Includes `declare namespace`, `declare module` and `declare global` and namespace nested in one of the aforementioned. */
198export declare function isAmbientModuleBlock(node: ts.Node): node is ts.ModuleBlock;
199export declare function getIIFE(func: ts.FunctionExpression | ts.ArrowFunction): ts.CallExpression | undefined;
200export declare type StrictCompilerOption = 'noImplicitAny' | 'noImplicitThis' | 'strictNullChecks' | 'strictFunctionTypes' | 'strictPropertyInitialization' | 'alwaysStrict' | 'strictBindCallApply';
201export declare function isStrictCompilerOptionEnabled(options: ts.CompilerOptions, option: StrictCompilerOption): boolean;
202export declare type BooleanCompilerOptions = {
203 [K in keyof ts.CompilerOptions]: NonNullable<ts.CompilerOptions[K]> extends boolean ? K : never;
204} extends {
205 [_ in keyof ts.CompilerOptions]: infer U;
206} ? U : never;
207/**
208 * Checks if a given compiler option is enabled.
209 * It handles dependencies of options, e.g. `declaration` is implicitly enabled by `composite` or `strictNullChecks` is enabled by `strict`.
210 * However, it does not check dependencies that are already checked and reported as errors, e.g. `checkJs` without `allowJs`.
211 * This function only handles boolean flags.
212 */
213export declare function isCompilerOptionEnabled(options: ts.CompilerOptions, option: BooleanCompilerOptions | 'stripInternal'): boolean;
214/**
215 * Has nothing to do with `isAmbientModuleBlock`.
216 *
217 * @returns `true` if it's a global augmentation or has a string name.
218 */
219export declare function isAmbientModule(node: ts.ModuleDeclaration): boolean;
220/**
221 * @deprecated use `getTsCheckDirective` instead since `// @ts-nocheck` is no longer restricted to JS files.
222 * @returns the last `// @ts-check` or `// @ts-nocheck` directive in the given file.
223 */
224export declare function getCheckJsDirective(source: string): ts.CheckJsDirective | undefined;
225/** @returns the last `// @ts-check` or `// @ts-nocheck` directive in the given file. */
226export declare function getTsCheckDirective(source: string): ts.CheckJsDirective | undefined;
227export declare function isConstAssertion(node: ts.AssertionExpression): boolean;
228/** Detects whether an expression is affected by an enclosing 'as const' assertion and therefore treated literally. */
229export declare function isInConstContext(node: ts.Expression): boolean;
230/** Returns true for `Object.defineProperty(o, 'prop', {value, writable: false})` and `Object.defineProperty(o, 'prop', {get: () => 1})`*/
231export declare function isReadonlyAssignmentDeclaration(node: ts.CallExpression, checker: ts.TypeChecker): boolean;
232/** Determines whether a call to `Object.defineProperty` is statically analyzable. */
233export declare function isBindableObjectDefinePropertyCall(node: ts.CallExpression): boolean;
234export interface WellKnownSymbolLiteral extends ts.PropertyAccessExpression {
235 expression: ts.Identifier & {
236 text: 'Symbol';
237 escapedText: 'symbol';
238 };
239}
240export declare function isWellKnownSymbolLiterally(node: ts.Expression): node is WellKnownSymbolLiteral;
241export interface PropertyName {
242 displayName: string;
243 symbolName: ts.__String;
244}
245/** @deprecated typescript 4.3 removed the concept of literal well known symbols. Use `getPropertyNameFromType` instead. */
246export declare function getPropertyNameOfWellKnownSymbol(node: WellKnownSymbolLiteral): PropertyName;
247export interface LateBoundPropertyNames {
248 /** Whether all constituents are literal names. */
249 known: boolean;
250 names: PropertyName[];
251}
252export declare function getLateBoundPropertyNames(node: ts.Expression, checker: ts.TypeChecker): LateBoundPropertyNames;
253export declare function getLateBoundPropertyNamesOfPropertyName(node: ts.PropertyName, checker: ts.TypeChecker): LateBoundPropertyNames;
254/** Most declarations demand there to be only one statically known name, e.g. class members with computed name. */
255export declare function getSingleLateBoundPropertyNameOfPropertyName(node: ts.PropertyName, checker: ts.TypeChecker): PropertyName | undefined;
256export declare function unwrapParentheses(node: ts.Expression): ts.Expression;
257export declare function formatPseudoBigInt(v: ts.PseudoBigInt): `${string}n` | `-${string}n`;
258/**
259 * Determines whether the given `SwitchStatement`'s `case` clauses cover every possible value of the switched expression.
260 * The logic is the same as TypeScript's control flow analysis.
261 * This does **not** check whether all `case` clauses do a certain action like assign a variable or return a value.
262 * This function ignores the `default` clause if present.
263 */
264export declare function hasExhaustiveCaseClauses(node: ts.SwitchStatement, checker: ts.TypeChecker): boolean;
265export declare function getBaseOfClassLikeExpression(node: ts.ClassLikeDeclaration): ts.ExpressionWithTypeArguments | undefined;
266
\No newline at end of file