UNPKG

5.59 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { TSError } from './node-utils';
3import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options';
4import { TSESTree, TSNode } from './ts-estree';
5interface ConverterOptions {
6 errorOnUnknownASTType: boolean;
7 useJSXTextNode: boolean;
8 shouldPreserveNodeMaps: boolean;
9}
10/**
11 * Extends and formats a given error object
12 * @param error the error object
13 * @returns converted error object
14 */
15export declare function convertError(error: any): TSError;
16export interface ASTMaps {
17 esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
18 tsNodeToESTreeNodeMap: ParserWeakMap<TSNode, TSESTree.Node>;
19}
20export declare class Converter {
21 private readonly ast;
22 private readonly options;
23 private readonly esTreeNodeToTSNodeMap;
24 private readonly tsNodeToESTreeNodeMap;
25 private allowPattern;
26 private inTypeMode;
27 /**
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
32 */
33 constructor(ast: ts.SourceFile, options: ConverterOptions);
34 getASTMaps(): ASTMaps;
35 convertProgram(): TSESTree.Program;
36 /**
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
43 */
44 private converter;
45 /**
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
50 */
51 private fixExports;
52 /**
53 * Register specific TypeScript node into map with first ESTree node provided
54 */
55 private registerTSNodeInNodeMap;
56 /**
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
61 */
62 private convertPattern;
63 /**
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
68 */
69 private convertChild;
70 /**
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
75 */
76 private convertType;
77 private createNode;
78 private convertBindingNameWithTypeAnnotation;
79 /**
80 * Converts a child into a type annotation. This creates an intermediary
81 * TypeAnnotation node to match what Flow does.
82 * @param child The TypeScript AST node to convert.
83 * @param parent parentNode
84 * @returns The type annotation node.
85 */
86 private convertTypeAnnotation;
87 /**
88 * Coverts body Nodes and add a directive field to StringLiterals
89 * @param nodes of ts.Node
90 * @param parent parentNode
91 * @returns Array of body statements
92 */
93 private convertBodyExpressions;
94 /**
95 * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
96 * @param typeArguments ts.NodeArray typeArguments
97 * @param node parent used to create this node
98 * @returns TypeParameterInstantiation node
99 */
100 private convertTypeArgumentsToTypeParameters;
101 /**
102 * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
103 * @param typeParameters ts.Node typeParameters
104 * @returns TypeParameterDeclaration node
105 */
106 private convertTSTypeParametersToTypeParametersDeclaration;
107 /**
108 * Converts an array of ts.Node parameters into an array of ESTreeNode params
109 * @param parameters An array of ts.Node params to be converted
110 * @returns an array of converted ESTreeNode params
111 */
112 private convertParameters;
113 private convertChainExpression;
114 /**
115 * For nodes that are copied directly from the TypeScript AST into
116 * ESTree mostly as-is. The only difference is the addition of a type
117 * property instead of a kind property. Recursively copies all children.
118 */
119 private deeplyCopy;
120 private convertJSXIdentifier;
121 private convertJSXNamespaceOrIdentifier;
122 /**
123 * Converts a TypeScript JSX node.tagName into an ESTree node.name
124 * @param node the tagName object from a JSX ts.Node
125 * @param parent
126 * @returns the converted ESTree name object
127 */
128 private convertJSXTagName;
129 private convertMethodSignature;
130 /**
131 * Applies the given TS modifiers to the given result object.
132 * @param result
133 * @param modifiers original ts.Nodes from the node.modifiers array
134 * @returns the current result object will be mutated
135 * @deprecated This method adds not standardized `modifiers` property in nodes
136 */
137 private applyModifiersToResult;
138 /**
139 * Uses the provided range location to adjust the location data of the given Node
140 * @param result The node that will have its location data mutated
141 * @param childRange The child node range used to expand location
142 */
143 private fixParentLocation;
144 /**
145 * Converts a TypeScript node into an ESTree node.
146 * The core of the conversion logic:
147 * Identify and convert each relevant TypeScript SyntaxKind
148 * @param node the child ts.Node
149 * @param parent parentNode
150 * @returns the converted ESTree node
151 */
152 private convertNode;
153}
154export {};
155//# sourceMappingURL=convert.d.ts.map
\No newline at end of file