1 import * as ts from 'typescript';
2 import { TSError } from './node-utils';
3 import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options';
4 import { TSESTree, TSNode } from './ts-estree';
5 interface ConverterOptions {
6 errorOnUnknownASTType: boolean;
7 useJSXTextNode: boolean;
8 shouldPreserveNodeMaps: boolean;
11 * Extends and formats a given error object
12 * @param error the error object
13 * @returns converted error object
15 export declare function convertError(error: any): TSError;
16 export interface ASTMaps {
17 esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
18 tsNodeToESTreeNodeMap: ParserWeakMap<TSNode, TSESTree.Node>;
20 export declare class Converter {
22 private readonly options;
23 private readonly esTreeNodeToTSNodeMap;
24 private readonly tsNodeToESTreeNodeMap;
28 * Converts a TypeScript node into an ESTree node
29 * @param ast the full TypeScript AST
30 * @param options additional options for the conversion
31 * @returns the converted ESTreeNode
33 constructor(ast: ts.SourceFile, options: ConverterOptions);
34 getASTMaps(): ASTMaps;
35 convertProgram(): TSESTree.Program;
37 * Converts a TypeScript node into an ESTree node.
38 * @param node the child ts.Node
39 * @param parent parentNode
40 * @param inTypeMode flag to determine if we are in typeMode
41 * @param allowPattern flag to determine if patterns are allowed
42 * @returns the converted ESTree node
46 * Fixes the exports of the given ts.Node
47 * @param node the ts.Node
48 * @param result result
49 * @returns the ESTreeNode with fixed exports
53 * Register specific TypeScript node into map with first ESTree node provided
55 private registerTSNodeInNodeMap;
57 * Converts a TypeScript node into an ESTree node.
58 * @param child the child ts.Node
59 * @param parent parentNode
60 * @returns the converted ESTree node
62 private convertPattern;
64 * Converts a TypeScript node into an ESTree node.
65 * @param child the child ts.Node
66 * @param parent parentNode
67 * @returns the converted ESTree node
71 * Converts a TypeScript node into an ESTree node.
72 * @param child the child ts.Node
73 * @param parent parentNode
74 * @returns the converted ESTree node
79 * Converts a child into a type annotation. This creates an intermediary
80 * TypeAnnotation node to match what Flow does.
81 * @param child The TypeScript AST node to convert.
82 * @param parent parentNode
83 * @returns The type annotation node.
85 private convertTypeAnnotation;
87 * Coverts body Nodes and add a directive field to StringLiterals
88 * @param nodes of ts.Node
89 * @param parent parentNode
90 * @returns Array of body statements
92 private convertBodyExpressions;
94 * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
95 * @param typeArguments ts.NodeArray typeArguments
96 * @param node parent used to create this node
97 * @returns TypeParameterInstantiation node
99 private convertTypeArgumentsToTypeParameters;
101 * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
102 * @param typeParameters ts.Node typeParameters
103 * @returns TypeParameterDeclaration node
105 private convertTSTypeParametersToTypeParametersDeclaration;
107 * Converts an array of ts.Node parameters into an array of ESTreeNode params
108 * @param parameters An array of ts.Node params to be converted
109 * @returns an array of converted ESTreeNode params
111 private convertParameters;
113 * For nodes that are copied directly from the TypeScript AST into
114 * ESTree mostly as-is. The only difference is the addition of a type
115 * property instead of a kind property. Recursively copies all children.
119 * Converts a TypeScript JSX node.tagName into an ESTree node.name
120 * @param node the tagName object from a JSX ts.Node
122 * @returns the converted ESTree name object
124 private convertJSXTagName;
126 * Applies the given TS modifiers to the given result object.
128 * @param modifiers original ts.Nodes from the node.modifiers array
129 * @returns the current result object will be mutated
130 * @deprecated This method adds not standardized `modifiers` property in nodes
132 private applyModifiersToResult;
134 * Uses the provided range location to adjust the location data of the given Node
135 * @param result The node that will have its location data mutated
136 * @param childRange The child node range used to expand location
138 private fixParentLocation;
140 * Converts a TypeScript node into an ESTree node.
141 * The core of the conversion logic:
142 * Identify and convert each relevant TypeScript SyntaxKind
143 * @param node the child ts.Node
144 * @param parent parentNode
145 * @returns the converted ESTree node
150 //# sourceMappingURL=convert.d.ts.map