737a98d93b9a364c79cb3bdf0621a0ebaff2c9f6
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / typescript-estree / dist / convert.js
1 "use strict";
2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3     if (k2 === undefined) k2 = k;
4     Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 }) : (function(o, m, k, k2) {
6     if (k2 === undefined) k2 = k;
7     o[k2] = m[k];
8 }));
9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10     Object.defineProperty(o, "default", { enumerable: true, value: v });
11 }) : function(o, v) {
12     o["default"] = v;
13 });
14 var __importStar = (this && this.__importStar) || function (mod) {
15     if (mod && mod.__esModule) return mod;
16     var result = {};
17     if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18     __setModuleDefault(result, mod);
19     return result;
20 };
21 Object.defineProperty(exports, "__esModule", { value: true });
22 exports.Converter = exports.convertError = void 0;
23 // There's lots of funny stuff due to the typing of ts.Node
24 /* eslint-disable @typescript-eslint/no-explicit-any */
25 const ts = __importStar(require("typescript"));
26 const node_utils_1 = require("./node-utils");
27 const ts_estree_1 = require("./ts-estree");
28 const SyntaxKind = ts.SyntaxKind;
29 /**
30  * Extends and formats a given error object
31  * @param error the error object
32  * @returns converted error object
33  */
34 function convertError(error) {
35     return node_utils_1.createError(error.file, error.start, error.message || error.messageText);
36 }
37 exports.convertError = convertError;
38 class Converter {
39     /**
40      * Converts a TypeScript node into an ESTree node
41      * @param ast the full TypeScript AST
42      * @param options additional options for the conversion
43      * @returns the converted ESTreeNode
44      */
45     constructor(ast, options) {
46         this.esTreeNodeToTSNodeMap = new WeakMap();
47         this.tsNodeToESTreeNodeMap = new WeakMap();
48         this.allowPattern = false;
49         this.inTypeMode = false;
50         this.ast = ast;
51         this.options = Object.assign({}, options);
52     }
53     getASTMaps() {
54         return {
55             esTreeNodeToTSNodeMap: this.esTreeNodeToTSNodeMap,
56             tsNodeToESTreeNodeMap: this.tsNodeToESTreeNodeMap,
57         };
58     }
59     convertProgram() {
60         return this.converter(this.ast);
61     }
62     /**
63      * Converts a TypeScript node into an ESTree node.
64      * @param node the child ts.Node
65      * @param parent parentNode
66      * @param inTypeMode flag to determine if we are in typeMode
67      * @param allowPattern flag to determine if patterns are allowed
68      * @returns the converted ESTree node
69      */
70     converter(node, parent, inTypeMode, allowPattern) {
71         /**
72          * Exit early for null and undefined
73          */
74         if (!node) {
75             return null;
76         }
77         const typeMode = this.inTypeMode;
78         const pattern = this.allowPattern;
79         if (inTypeMode !== undefined) {
80             this.inTypeMode = inTypeMode;
81         }
82         if (allowPattern !== undefined) {
83             this.allowPattern = allowPattern;
84         }
85         const result = this.convertNode(node, (parent !== null && parent !== void 0 ? parent : node.parent));
86         this.registerTSNodeInNodeMap(node, result);
87         this.inTypeMode = typeMode;
88         this.allowPattern = pattern;
89         return result;
90     }
91     /**
92      * Fixes the exports of the given ts.Node
93      * @param node the ts.Node
94      * @param result result
95      * @returns the ESTreeNode with fixed exports
96      */
97     fixExports(node, result) {
98         // check for exports
99         if (node.modifiers && node.modifiers[0].kind === SyntaxKind.ExportKeyword) {
100             /**
101              * Make sure that original node is registered instead of export
102              */
103             this.registerTSNodeInNodeMap(node, result);
104             const exportKeyword = node.modifiers[0];
105             const nextModifier = node.modifiers[1];
106             const declarationIsDefault = nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword;
107             const varToken = declarationIsDefault
108                 ? node_utils_1.findNextToken(nextModifier, this.ast, this.ast)
109                 : node_utils_1.findNextToken(exportKeyword, this.ast, this.ast);
110             result.range[0] = varToken.getStart(this.ast);
111             result.loc = node_utils_1.getLocFor(result.range[0], result.range[1], this.ast);
112             if (declarationIsDefault) {
113                 return this.createNode(node, {
114                     type: ts_estree_1.AST_NODE_TYPES.ExportDefaultDeclaration,
115                     declaration: result,
116                     range: [exportKeyword.getStart(this.ast), result.range[1]],
117                     exportKind: 'value',
118                 });
119             }
120             else {
121                 const isType = result.type === ts_estree_1.AST_NODE_TYPES.TSInterfaceDeclaration ||
122                     result.type === ts_estree_1.AST_NODE_TYPES.TSTypeAliasDeclaration;
123                 const isDeclare = result.declare === true;
124                 return this.createNode(node, {
125                     type: ts_estree_1.AST_NODE_TYPES.ExportNamedDeclaration,
126                     declaration: result,
127                     specifiers: [],
128                     source: null,
129                     exportKind: isType || isDeclare ? 'type' : 'value',
130                     range: [exportKeyword.getStart(this.ast), result.range[1]],
131                 });
132             }
133         }
134         return result;
135     }
136     /**
137      * Register specific TypeScript node into map with first ESTree node provided
138      */
139     registerTSNodeInNodeMap(node, result) {
140         if (result && this.options.shouldPreserveNodeMaps) {
141             if (!this.tsNodeToESTreeNodeMap.has(node)) {
142                 this.tsNodeToESTreeNodeMap.set(node, result);
143             }
144         }
145     }
146     /**
147      * Converts a TypeScript node into an ESTree node.
148      * @param child the child ts.Node
149      * @param parent parentNode
150      * @returns the converted ESTree node
151      */
152     convertPattern(child, parent) {
153         return this.converter(child, parent, this.inTypeMode, true);
154     }
155     /**
156      * Converts a TypeScript node into an ESTree node.
157      * @param child the child ts.Node
158      * @param parent parentNode
159      * @returns the converted ESTree node
160      */
161     convertChild(child, parent) {
162         return this.converter(child, parent, this.inTypeMode, false);
163     }
164     /**
165      * Converts a TypeScript node into an ESTree node.
166      * @param child the child ts.Node
167      * @param parent parentNode
168      * @returns the converted ESTree node
169      */
170     convertType(child, parent) {
171         return this.converter(child, parent, true, false);
172     }
173     createNode(node, data) {
174         const result = data;
175         if (!result.range) {
176             result.range = node_utils_1.getRange(
177             // this is completely valid, but TS hates it
178             node, this.ast);
179         }
180         if (!result.loc) {
181             result.loc = node_utils_1.getLocFor(result.range[0], result.range[1], this.ast);
182         }
183         if (result && this.options.shouldPreserveNodeMaps) {
184             this.esTreeNodeToTSNodeMap.set(result, node);
185         }
186         return result;
187     }
188     /**
189      * Converts a child into a type annotation. This creates an intermediary
190      * TypeAnnotation node to match what Flow does.
191      * @param child The TypeScript AST node to convert.
192      * @param parent parentNode
193      * @returns The type annotation node.
194      */
195     convertTypeAnnotation(child, parent) {
196         // in FunctionType and ConstructorType typeAnnotation has 2 characters `=>` and in other places is just colon
197         const offset = parent.kind === SyntaxKind.FunctionType ||
198             parent.kind === SyntaxKind.ConstructorType
199             ? 2
200             : 1;
201         const annotationStartCol = child.getFullStart() - offset;
202         const loc = node_utils_1.getLocFor(annotationStartCol, child.end, this.ast);
203         return {
204             type: ts_estree_1.AST_NODE_TYPES.TSTypeAnnotation,
205             loc,
206             range: [annotationStartCol, child.end],
207             typeAnnotation: this.convertType(child),
208         };
209     }
210     /**
211      * Coverts body Nodes and add a directive field to StringLiterals
212      * @param nodes of ts.Node
213      * @param parent parentNode
214      * @returns Array of body statements
215      */
216     convertBodyExpressions(nodes, parent) {
217         let allowDirectives = node_utils_1.canContainDirective(parent);
218         return (nodes
219             .map(statement => {
220             const child = this.convertChild(statement);
221             if (allowDirectives) {
222                 if ((child === null || child === void 0 ? void 0 : child.expression) &&
223                     ts.isExpressionStatement(statement) &&
224                     ts.isStringLiteral(statement.expression)) {
225                     const raw = child.expression.raw;
226                     child.directive = raw.slice(1, -1);
227                     return child; // child can be null, but it's filtered below
228                 }
229                 else {
230                     allowDirectives = false;
231                 }
232             }
233             return child; // child can be null, but it's filtered below
234         })
235             // filter out unknown nodes for now
236             .filter(statement => statement));
237     }
238     /**
239      * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
240      * @param typeArguments ts.NodeArray typeArguments
241      * @param node parent used to create this node
242      * @returns TypeParameterInstantiation node
243      */
244     convertTypeArgumentsToTypeParameters(typeArguments, node) {
245         const greaterThanToken = node_utils_1.findNextToken(typeArguments, this.ast, this.ast);
246         return this.createNode(node, {
247             type: ts_estree_1.AST_NODE_TYPES.TSTypeParameterInstantiation,
248             range: [typeArguments.pos - 1, greaterThanToken.end],
249             params: typeArguments.map(typeArgument => this.convertType(typeArgument)),
250         });
251     }
252     /**
253      * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
254      * @param typeParameters ts.Node typeParameters
255      * @returns TypeParameterDeclaration node
256      */
257     convertTSTypeParametersToTypeParametersDeclaration(typeParameters) {
258         const greaterThanToken = node_utils_1.findNextToken(typeParameters, this.ast, this.ast);
259         return {
260             type: ts_estree_1.AST_NODE_TYPES.TSTypeParameterDeclaration,
261             range: [typeParameters.pos - 1, greaterThanToken.end],
262             loc: node_utils_1.getLocFor(typeParameters.pos - 1, greaterThanToken.end, this.ast),
263             params: typeParameters.map(typeParameter => this.convertType(typeParameter)),
264         };
265     }
266     /**
267      * Converts an array of ts.Node parameters into an array of ESTreeNode params
268      * @param parameters An array of ts.Node params to be converted
269      * @returns an array of converted ESTreeNode params
270      */
271     convertParameters(parameters) {
272         if (!parameters || !parameters.length) {
273             return [];
274         }
275         return parameters.map(param => {
276             var _a;
277             const convertedParam = this.convertChild(param);
278             if ((_a = param.decorators) === null || _a === void 0 ? void 0 : _a.length) {
279                 convertedParam.decorators = param.decorators.map(el => this.convertChild(el));
280             }
281             return convertedParam;
282         });
283     }
284     /**
285      * For nodes that are copied directly from the TypeScript AST into
286      * ESTree mostly as-is. The only difference is the addition of a type
287      * property instead of a kind property. Recursively copies all children.
288      */
289     deeplyCopy(node) {
290         if (node.kind === ts.SyntaxKind.JSDocFunctionType) {
291             throw node_utils_1.createError(this.ast, node.pos, 'JSDoc types can only be used inside documentation comments.');
292         }
293         const customType = `TS${SyntaxKind[node.kind]}`;
294         /**
295          * If the "errorOnUnknownASTType" option is set to true, throw an error,
296          * otherwise fallback to just including the unknown type as-is.
297          */
298         if (this.options.errorOnUnknownASTType && !ts_estree_1.AST_NODE_TYPES[customType]) {
299             throw new Error(`Unknown AST_NODE_TYPE: "${customType}"`);
300         }
301         const result = this.createNode(node, {
302             type: customType,
303         });
304         if ('type' in node) {
305             result.typeAnnotation =
306                 node.type && 'kind' in node.type && ts.isTypeNode(node.type)
307                     ? this.convertTypeAnnotation(node.type, node)
308                     : null;
309         }
310         if ('typeArguments' in node) {
311             result.typeParameters =
312                 node.typeArguments && 'pos' in node.typeArguments
313                     ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
314                     : null;
315         }
316         if ('typeParameters' in node) {
317             result.typeParameters =
318                 node.typeParameters && 'pos' in node.typeParameters
319                     ? this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters)
320                     : null;
321         }
322         if ('decorators' in node && node.decorators && node.decorators.length) {
323             result.decorators = node.decorators.map(el => this.convertChild(el));
324         }
325         Object.entries(node)
326             .filter(([key]) => !/^(?:_children|kind|parent|pos|end|flags|modifierFlagsCache|jsDoc|type|typeArguments|typeParameters|decorators)$/.test(key))
327             .forEach(([key, value]) => {
328             if (Array.isArray(value)) {
329                 result[key] = value.map(el => this.convertChild(el));
330             }
331             else if (value && typeof value === 'object' && value.kind) {
332                 // need to check node[key].kind to ensure we don't try to convert a symbol
333                 result[key] = this.convertChild(value);
334             }
335             else {
336                 result[key] = value;
337             }
338         });
339         return result;
340     }
341     /**
342      * Converts a TypeScript JSX node.tagName into an ESTree node.name
343      * @param node the tagName object from a JSX ts.Node
344      * @param parent
345      * @returns the converted ESTree name object
346      */
347     convertJSXTagName(node, parent) {
348         let result;
349         switch (node.kind) {
350             case SyntaxKind.PropertyAccessExpression:
351                 if (node.name.kind === SyntaxKind.PrivateIdentifier) {
352                     // This is one of the few times where TS explicitly errors, and doesn't even gracefully handle the syntax.
353                     // So we shouldn't ever get into this state to begin with.
354                     throw new Error('Non-private identifier expected.');
355                 }
356                 result = this.createNode(node, {
357                     type: ts_estree_1.AST_NODE_TYPES.JSXMemberExpression,
358                     object: this.convertJSXTagName(node.expression, parent),
359                     property: this.convertJSXTagName(node.name, parent),
360                 });
361                 break;
362             case SyntaxKind.ThisKeyword:
363                 result = this.createNode(node, {
364                     type: ts_estree_1.AST_NODE_TYPES.JSXIdentifier,
365                     name: 'this',
366                 });
367                 break;
368             case SyntaxKind.Identifier:
369             default:
370                 result = this.createNode(node, {
371                     type: ts_estree_1.AST_NODE_TYPES.JSXIdentifier,
372                     name: node.text,
373                 });
374                 break;
375         }
376         this.registerTSNodeInNodeMap(node, result);
377         return result;
378     }
379     /**
380      * Applies the given TS modifiers to the given result object.
381      * @param result
382      * @param modifiers original ts.Nodes from the node.modifiers array
383      * @returns the current result object will be mutated
384      * @deprecated This method adds not standardized `modifiers` property in nodes
385      */
386     applyModifiersToResult(result, modifiers) {
387         if (!modifiers || !modifiers.length) {
388             return;
389         }
390         /**
391          * Some modifiers are explicitly handled by applying them as
392          * boolean values on the result node. As well as adding them
393          * to the result, we remove them from the array, so that they
394          * are not handled twice.
395          */
396         const handledModifierIndices = {};
397         for (let i = 0; i < modifiers.length; i++) {
398             const modifier = modifiers[i];
399             switch (modifier.kind) {
400                 /**
401                  * Ignore ExportKeyword and DefaultKeyword, they are handled
402                  * via the fixExports utility function
403                  */
404                 case SyntaxKind.ExportKeyword:
405                 case SyntaxKind.DefaultKeyword:
406                     handledModifierIndices[i] = true;
407                     break;
408                 case SyntaxKind.ConstKeyword:
409                     result.const = true;
410                     handledModifierIndices[i] = true;
411                     break;
412                 case SyntaxKind.DeclareKeyword:
413                     result.declare = true;
414                     handledModifierIndices[i] = true;
415                     break;
416                 default:
417             }
418         }
419         /**
420          * If there are still valid modifiers available which have
421          * not been explicitly handled above, we just convert and
422          * add the modifiers array to the result node.
423          */
424         const remainingModifiers = modifiers.filter((_, i) => !handledModifierIndices[i]);
425         if (!remainingModifiers || !remainingModifiers.length) {
426             return;
427         }
428         result.modifiers = remainingModifiers.map(el => this.convertChild(el));
429     }
430     /**
431      * Uses the provided range location to adjust the location data of the given Node
432      * @param result The node that will have its location data mutated
433      * @param childRange The child node range used to expand location
434      */
435     fixParentLocation(result, childRange) {
436         if (childRange[0] < result.range[0]) {
437             result.range[0] = childRange[0];
438             result.loc.start = node_utils_1.getLineAndCharacterFor(result.range[0], this.ast);
439         }
440         if (childRange[1] > result.range[1]) {
441             result.range[1] = childRange[1];
442             result.loc.end = node_utils_1.getLineAndCharacterFor(result.range[1], this.ast);
443         }
444     }
445     /**
446      * Converts a TypeScript node into an ESTree node.
447      * The core of the conversion logic:
448      * Identify and convert each relevant TypeScript SyntaxKind
449      * @param node the child ts.Node
450      * @param parent parentNode
451      * @returns the converted ESTree node
452      */
453     convertNode(node, parent) {
454         var _a, _b, _c, _d, _e, _f, _g, _h, _j;
455         switch (node.kind) {
456             case SyntaxKind.SourceFile: {
457                 return this.createNode(node, {
458                     type: ts_estree_1.AST_NODE_TYPES.Program,
459                     body: this.convertBodyExpressions(node.statements, node),
460                     sourceType: node.externalModuleIndicator ? 'module' : 'script',
461                     range: [node.getStart(this.ast), node.endOfFileToken.end],
462                 });
463             }
464             case SyntaxKind.Block: {
465                 return this.createNode(node, {
466                     type: ts_estree_1.AST_NODE_TYPES.BlockStatement,
467                     body: this.convertBodyExpressions(node.statements, node),
468                 });
469             }
470             case SyntaxKind.Identifier: {
471                 return this.createNode(node, {
472                     type: ts_estree_1.AST_NODE_TYPES.Identifier,
473                     name: node.text,
474                 });
475             }
476             case SyntaxKind.WithStatement:
477                 return this.createNode(node, {
478                     type: ts_estree_1.AST_NODE_TYPES.WithStatement,
479                     object: this.convertChild(node.expression),
480                     body: this.convertChild(node.statement),
481                 });
482             // Control Flow
483             case SyntaxKind.ReturnStatement:
484                 return this.createNode(node, {
485                     type: ts_estree_1.AST_NODE_TYPES.ReturnStatement,
486                     argument: this.convertChild(node.expression),
487                 });
488             case SyntaxKind.LabeledStatement:
489                 return this.createNode(node, {
490                     type: ts_estree_1.AST_NODE_TYPES.LabeledStatement,
491                     label: this.convertChild(node.label),
492                     body: this.convertChild(node.statement),
493                 });
494             case SyntaxKind.ContinueStatement:
495                 return this.createNode(node, {
496                     type: ts_estree_1.AST_NODE_TYPES.ContinueStatement,
497                     label: this.convertChild(node.label),
498                 });
499             case SyntaxKind.BreakStatement:
500                 return this.createNode(node, {
501                     type: ts_estree_1.AST_NODE_TYPES.BreakStatement,
502                     label: this.convertChild(node.label),
503                 });
504             // Choice
505             case SyntaxKind.IfStatement:
506                 return this.createNode(node, {
507                     type: ts_estree_1.AST_NODE_TYPES.IfStatement,
508                     test: this.convertChild(node.expression),
509                     consequent: this.convertChild(node.thenStatement),
510                     alternate: this.convertChild(node.elseStatement),
511                 });
512             case SyntaxKind.SwitchStatement:
513                 return this.createNode(node, {
514                     type: ts_estree_1.AST_NODE_TYPES.SwitchStatement,
515                     discriminant: this.convertChild(node.expression),
516                     cases: node.caseBlock.clauses.map(el => this.convertChild(el)),
517                 });
518             case SyntaxKind.CaseClause:
519             case SyntaxKind.DefaultClause:
520                 return this.createNode(node, {
521                     type: ts_estree_1.AST_NODE_TYPES.SwitchCase,
522                     // expression is present in case only
523                     test: node.kind === SyntaxKind.CaseClause
524                         ? this.convertChild(node.expression)
525                         : null,
526                     consequent: node.statements.map(el => this.convertChild(el)),
527                 });
528             // Exceptions
529             case SyntaxKind.ThrowStatement:
530                 return this.createNode(node, {
531                     type: ts_estree_1.AST_NODE_TYPES.ThrowStatement,
532                     argument: this.convertChild(node.expression),
533                 });
534             case SyntaxKind.TryStatement:
535                 return this.createNode(node, {
536                     type: ts_estree_1.AST_NODE_TYPES.TryStatement,
537                     block: this.convertChild(node.tryBlock),
538                     handler: this.convertChild(node.catchClause),
539                     finalizer: this.convertChild(node.finallyBlock),
540                 });
541             case SyntaxKind.CatchClause:
542                 return this.createNode(node, {
543                     type: ts_estree_1.AST_NODE_TYPES.CatchClause,
544                     param: node.variableDeclaration
545                         ? this.convertChild(node.variableDeclaration.name)
546                         : null,
547                     body: this.convertChild(node.block),
548                 });
549             // Loops
550             case SyntaxKind.WhileStatement:
551                 return this.createNode(node, {
552                     type: ts_estree_1.AST_NODE_TYPES.WhileStatement,
553                     test: this.convertChild(node.expression),
554                     body: this.convertChild(node.statement),
555                 });
556             /**
557              * Unlike other parsers, TypeScript calls a "DoWhileStatement"
558              * a "DoStatement"
559              */
560             case SyntaxKind.DoStatement:
561                 return this.createNode(node, {
562                     type: ts_estree_1.AST_NODE_TYPES.DoWhileStatement,
563                     test: this.convertChild(node.expression),
564                     body: this.convertChild(node.statement),
565                 });
566             case SyntaxKind.ForStatement:
567                 return this.createNode(node, {
568                     type: ts_estree_1.AST_NODE_TYPES.ForStatement,
569                     init: this.convertChild(node.initializer),
570                     test: this.convertChild(node.condition),
571                     update: this.convertChild(node.incrementor),
572                     body: this.convertChild(node.statement),
573                 });
574             case SyntaxKind.ForInStatement:
575                 return this.createNode(node, {
576                     type: ts_estree_1.AST_NODE_TYPES.ForInStatement,
577                     left: this.convertPattern(node.initializer),
578                     right: this.convertChild(node.expression),
579                     body: this.convertChild(node.statement),
580                 });
581             case SyntaxKind.ForOfStatement:
582                 return this.createNode(node, {
583                     type: ts_estree_1.AST_NODE_TYPES.ForOfStatement,
584                     left: this.convertPattern(node.initializer),
585                     right: this.convertChild(node.expression),
586                     body: this.convertChild(node.statement),
587                     await: Boolean(node.awaitModifier &&
588                         node.awaitModifier.kind === SyntaxKind.AwaitKeyword),
589                 });
590             // Declarations
591             case SyntaxKind.FunctionDeclaration: {
592                 const isDeclare = node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node);
593                 const result = this.createNode(node, {
594                     type: isDeclare || !node.body
595                         ? ts_estree_1.AST_NODE_TYPES.TSDeclareFunction
596                         : ts_estree_1.AST_NODE_TYPES.FunctionDeclaration,
597                     id: this.convertChild(node.name),
598                     generator: !!node.asteriskToken,
599                     expression: false,
600                     async: node_utils_1.hasModifier(SyntaxKind.AsyncKeyword, node),
601                     params: this.convertParameters(node.parameters),
602                     body: this.convertChild(node.body) || undefined,
603                 });
604                 // Process returnType
605                 if (node.type) {
606                     result.returnType = this.convertTypeAnnotation(node.type, node);
607                 }
608                 if (isDeclare) {
609                     result.declare = true;
610                 }
611                 // Process typeParameters
612                 if (node.typeParameters) {
613                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
614                 }
615                 /**
616                  * Semantically, decorators are not allowed on function declarations,
617                  * but the TypeScript compiler will parse them and produce a valid AST,
618                  * so we handle them here too.
619                  */
620                 if (node.decorators) {
621                     result.decorators = node.decorators.map(el => this.convertChild(el));
622                 }
623                 // check for exports
624                 return this.fixExports(node, result);
625             }
626             case SyntaxKind.VariableDeclaration: {
627                 const result = this.createNode(node, {
628                     type: ts_estree_1.AST_NODE_TYPES.VariableDeclarator,
629                     id: this.convertPattern(node.name),
630                     init: this.convertChild(node.initializer),
631                 });
632                 if (node.exclamationToken) {
633                     result.definite = true;
634                 }
635                 if (node.type) {
636                     result.id.typeAnnotation = this.convertTypeAnnotation(node.type, node);
637                     this.fixParentLocation(result.id, result.id.typeAnnotation.range);
638                 }
639                 return result;
640             }
641             case SyntaxKind.VariableStatement: {
642                 const result = this.createNode(node, {
643                     type: ts_estree_1.AST_NODE_TYPES.VariableDeclaration,
644                     declarations: node.declarationList.declarations.map(el => this.convertChild(el)),
645                     kind: node_utils_1.getDeclarationKind(node.declarationList),
646                 });
647                 /**
648                  * Semantically, decorators are not allowed on variable declarations,
649                  * but the TypeScript compiler will parse them and produce a valid AST,
650                  * so we handle them here too.
651                  */
652                 if (node.decorators) {
653                     result.decorators = node.decorators.map(el => this.convertChild(el));
654                 }
655                 if (node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node)) {
656                     result.declare = true;
657                 }
658                 // check for exports
659                 return this.fixExports(node, result);
660             }
661             // mostly for for-of, for-in
662             case SyntaxKind.VariableDeclarationList:
663                 return this.createNode(node, {
664                     type: ts_estree_1.AST_NODE_TYPES.VariableDeclaration,
665                     declarations: node.declarations.map(el => this.convertChild(el)),
666                     kind: node_utils_1.getDeclarationKind(node),
667                 });
668             // Expressions
669             case SyntaxKind.ExpressionStatement:
670                 return this.createNode(node, {
671                     type: ts_estree_1.AST_NODE_TYPES.ExpressionStatement,
672                     expression: this.convertChild(node.expression),
673                 });
674             case SyntaxKind.ThisKeyword:
675                 return this.createNode(node, {
676                     type: ts_estree_1.AST_NODE_TYPES.ThisExpression,
677                 });
678             case SyntaxKind.ArrayLiteralExpression: {
679                 // TypeScript uses ArrayLiteralExpression in destructuring assignment, too
680                 if (this.allowPattern) {
681                     return this.createNode(node, {
682                         type: ts_estree_1.AST_NODE_TYPES.ArrayPattern,
683                         elements: node.elements.map(el => this.convertPattern(el)),
684                     });
685                 }
686                 else {
687                     return this.createNode(node, {
688                         type: ts_estree_1.AST_NODE_TYPES.ArrayExpression,
689                         elements: node.elements.map(el => this.convertChild(el)),
690                     });
691                 }
692             }
693             case SyntaxKind.ObjectLiteralExpression: {
694                 // TypeScript uses ObjectLiteralExpression in destructuring assignment, too
695                 if (this.allowPattern) {
696                     return this.createNode(node, {
697                         type: ts_estree_1.AST_NODE_TYPES.ObjectPattern,
698                         properties: node.properties.map(el => this.convertPattern(el)),
699                     });
700                 }
701                 else {
702                     return this.createNode(node, {
703                         type: ts_estree_1.AST_NODE_TYPES.ObjectExpression,
704                         properties: node.properties.map(el => this.convertChild(el)),
705                     });
706                 }
707             }
708             case SyntaxKind.PropertyAssignment:
709                 return this.createNode(node, {
710                     type: ts_estree_1.AST_NODE_TYPES.Property,
711                     key: this.convertChild(node.name),
712                     value: this.converter(node.initializer, node, this.inTypeMode, this.allowPattern),
713                     computed: node_utils_1.isComputedProperty(node.name),
714                     method: false,
715                     shorthand: false,
716                     kind: 'init',
717                 });
718             case SyntaxKind.ShorthandPropertyAssignment: {
719                 if (node.objectAssignmentInitializer) {
720                     return this.createNode(node, {
721                         type: ts_estree_1.AST_NODE_TYPES.Property,
722                         key: this.convertChild(node.name),
723                         value: this.createNode(node, {
724                             type: ts_estree_1.AST_NODE_TYPES.AssignmentPattern,
725                             left: this.convertPattern(node.name),
726                             right: this.convertChild(node.objectAssignmentInitializer),
727                         }),
728                         computed: false,
729                         method: false,
730                         shorthand: true,
731                         kind: 'init',
732                     });
733                 }
734                 else {
735                     return this.createNode(node, {
736                         type: ts_estree_1.AST_NODE_TYPES.Property,
737                         key: this.convertChild(node.name),
738                         value: this.convertChild(node.name),
739                         computed: false,
740                         method: false,
741                         shorthand: true,
742                         kind: 'init',
743                     });
744                 }
745             }
746             case SyntaxKind.ComputedPropertyName:
747                 return this.convertChild(node.expression);
748             case SyntaxKind.PropertyDeclaration: {
749                 const isAbstract = node_utils_1.hasModifier(SyntaxKind.AbstractKeyword, node);
750                 const result = this.createNode(node, {
751                     type: isAbstract
752                         ? ts_estree_1.AST_NODE_TYPES.TSAbstractClassProperty
753                         : ts_estree_1.AST_NODE_TYPES.ClassProperty,
754                     key: this.convertChild(node.name),
755                     value: this.convertChild(node.initializer),
756                     computed: node_utils_1.isComputedProperty(node.name),
757                     static: node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node),
758                     readonly: node_utils_1.hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
759                     declare: node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node),
760                 });
761                 if (node.type) {
762                     result.typeAnnotation = this.convertTypeAnnotation(node.type, node);
763                 }
764                 if (node.decorators) {
765                     result.decorators = node.decorators.map(el => this.convertChild(el));
766                 }
767                 const accessibility = node_utils_1.getTSNodeAccessibility(node);
768                 if (accessibility) {
769                     result.accessibility = accessibility;
770                 }
771                 if ((node.name.kind === SyntaxKind.Identifier ||
772                     node.name.kind === SyntaxKind.ComputedPropertyName) &&
773                     node.questionToken) {
774                     result.optional = true;
775                 }
776                 if (node.exclamationToken) {
777                     result.definite = true;
778                 }
779                 if (result.key.type === ts_estree_1.AST_NODE_TYPES.Literal && node.questionToken) {
780                     result.optional = true;
781                 }
782                 return result;
783             }
784             case SyntaxKind.GetAccessor:
785             case SyntaxKind.SetAccessor:
786             case SyntaxKind.MethodDeclaration: {
787                 const method = this.createNode(node, {
788                     type: !node.body
789                         ? ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression
790                         : ts_estree_1.AST_NODE_TYPES.FunctionExpression,
791                     id: null,
792                     generator: !!node.asteriskToken,
793                     expression: false,
794                     async: node_utils_1.hasModifier(SyntaxKind.AsyncKeyword, node),
795                     body: this.convertChild(node.body),
796                     range: [node.parameters.pos - 1, node.end],
797                     params: [],
798                 });
799                 if (node.type) {
800                     method.returnType = this.convertTypeAnnotation(node.type, node);
801                 }
802                 // Process typeParameters
803                 if (node.typeParameters) {
804                     method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
805                     this.fixParentLocation(method, method.typeParameters.range);
806                 }
807                 let result;
808                 if (parent.kind === SyntaxKind.ObjectLiteralExpression) {
809                     method.params = node.parameters.map(el => this.convertChild(el));
810                     result = this.createNode(node, {
811                         type: ts_estree_1.AST_NODE_TYPES.Property,
812                         key: this.convertChild(node.name),
813                         value: method,
814                         computed: node_utils_1.isComputedProperty(node.name),
815                         method: node.kind === SyntaxKind.MethodDeclaration,
816                         shorthand: false,
817                         kind: 'init',
818                     });
819                 }
820                 else {
821                     // class
822                     /**
823                      * Unlike in object literal methods, class method params can have decorators
824                      */
825                     method.params = this.convertParameters(node.parameters);
826                     /**
827                      * TypeScript class methods can be defined as "abstract"
828                      */
829                     const methodDefinitionType = node_utils_1.hasModifier(SyntaxKind.AbstractKeyword, node)
830                         ? ts_estree_1.AST_NODE_TYPES.TSAbstractMethodDefinition
831                         : ts_estree_1.AST_NODE_TYPES.MethodDefinition;
832                     result = this.createNode(node, {
833                         type: methodDefinitionType,
834                         key: this.convertChild(node.name),
835                         value: method,
836                         computed: node_utils_1.isComputedProperty(node.name),
837                         static: node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node),
838                         kind: 'method',
839                     });
840                     if (node.decorators) {
841                         result.decorators = node.decorators.map(el => this.convertChild(el));
842                     }
843                     const accessibility = node_utils_1.getTSNodeAccessibility(node);
844                     if (accessibility) {
845                         result.accessibility = accessibility;
846                     }
847                 }
848                 if (node.questionToken) {
849                     result.optional = true;
850                 }
851                 if (node.kind === SyntaxKind.GetAccessor) {
852                     result.kind = 'get';
853                 }
854                 else if (node.kind === SyntaxKind.SetAccessor) {
855                     result.kind = 'set';
856                 }
857                 else if (!result.static &&
858                     node.name.kind === SyntaxKind.StringLiteral &&
859                     node.name.text === 'constructor' &&
860                     result.type !== ts_estree_1.AST_NODE_TYPES.Property) {
861                     result.kind = 'constructor';
862                 }
863                 return result;
864             }
865             // TypeScript uses this even for static methods named "constructor"
866             case SyntaxKind.Constructor: {
867                 const lastModifier = node_utils_1.getLastModifier(node);
868                 const constructorToken = (lastModifier && node_utils_1.findNextToken(lastModifier, node, this.ast)) ||
869                     node.getFirstToken();
870                 const constructor = this.createNode(node, {
871                     type: !node.body
872                         ? ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression
873                         : ts_estree_1.AST_NODE_TYPES.FunctionExpression,
874                     id: null,
875                     params: this.convertParameters(node.parameters),
876                     generator: false,
877                     expression: false,
878                     async: false,
879                     body: this.convertChild(node.body),
880                     range: [node.parameters.pos - 1, node.end],
881                 });
882                 // Process typeParameters
883                 if (node.typeParameters) {
884                     constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
885                     this.fixParentLocation(constructor, constructor.typeParameters.range);
886                 }
887                 // Process returnType
888                 if (node.type) {
889                     constructor.returnType = this.convertTypeAnnotation(node.type, node);
890                 }
891                 const constructorKey = this.createNode(node, {
892                     type: ts_estree_1.AST_NODE_TYPES.Identifier,
893                     name: 'constructor',
894                     range: [constructorToken.getStart(this.ast), constructorToken.end],
895                 });
896                 const isStatic = node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node);
897                 const result = this.createNode(node, {
898                     type: node_utils_1.hasModifier(SyntaxKind.AbstractKeyword, node)
899                         ? ts_estree_1.AST_NODE_TYPES.TSAbstractMethodDefinition
900                         : ts_estree_1.AST_NODE_TYPES.MethodDefinition,
901                     key: constructorKey,
902                     value: constructor,
903                     computed: false,
904                     static: isStatic,
905                     kind: isStatic ? 'method' : 'constructor',
906                 });
907                 const accessibility = node_utils_1.getTSNodeAccessibility(node);
908                 if (accessibility) {
909                     result.accessibility = accessibility;
910                 }
911                 return result;
912             }
913             case SyntaxKind.FunctionExpression: {
914                 const result = this.createNode(node, {
915                     type: ts_estree_1.AST_NODE_TYPES.FunctionExpression,
916                     id: this.convertChild(node.name),
917                     generator: !!node.asteriskToken,
918                     params: this.convertParameters(node.parameters),
919                     body: this.convertChild(node.body),
920                     async: node_utils_1.hasModifier(SyntaxKind.AsyncKeyword, node),
921                     expression: false,
922                 });
923                 // Process returnType
924                 if (node.type) {
925                     result.returnType = this.convertTypeAnnotation(node.type, node);
926                 }
927                 // Process typeParameters
928                 if (node.typeParameters) {
929                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
930                 }
931                 return result;
932             }
933             case SyntaxKind.SuperKeyword:
934                 return this.createNode(node, {
935                     type: ts_estree_1.AST_NODE_TYPES.Super,
936                 });
937             case SyntaxKind.ArrayBindingPattern:
938                 return this.createNode(node, {
939                     type: ts_estree_1.AST_NODE_TYPES.ArrayPattern,
940                     elements: node.elements.map(el => this.convertPattern(el)),
941                 });
942             // occurs with missing array elements like [,]
943             case SyntaxKind.OmittedExpression:
944                 return null;
945             case SyntaxKind.ObjectBindingPattern:
946                 return this.createNode(node, {
947                     type: ts_estree_1.AST_NODE_TYPES.ObjectPattern,
948                     properties: node.elements.map(el => this.convertPattern(el)),
949                 });
950             case SyntaxKind.BindingElement: {
951                 if (parent.kind === SyntaxKind.ArrayBindingPattern) {
952                     const arrayItem = this.convertChild(node.name, parent);
953                     if (node.initializer) {
954                         return this.createNode(node, {
955                             type: ts_estree_1.AST_NODE_TYPES.AssignmentPattern,
956                             left: arrayItem,
957                             right: this.convertChild(node.initializer),
958                         });
959                     }
960                     else if (node.dotDotDotToken) {
961                         return this.createNode(node, {
962                             type: ts_estree_1.AST_NODE_TYPES.RestElement,
963                             argument: arrayItem,
964                         });
965                     }
966                     else {
967                         return arrayItem;
968                     }
969                 }
970                 else {
971                     let result;
972                     if (node.dotDotDotToken) {
973                         result = this.createNode(node, {
974                             type: ts_estree_1.AST_NODE_TYPES.RestElement,
975                             argument: this.convertChild((_a = node.propertyName) !== null && _a !== void 0 ? _a : node.name),
976                         });
977                     }
978                     else {
979                         result = this.createNode(node, {
980                             type: ts_estree_1.AST_NODE_TYPES.Property,
981                             key: this.convertChild((_b = node.propertyName) !== null && _b !== void 0 ? _b : node.name),
982                             value: this.convertChild(node.name),
983                             computed: Boolean(node.propertyName &&
984                                 node.propertyName.kind === SyntaxKind.ComputedPropertyName),
985                             method: false,
986                             shorthand: !node.propertyName,
987                             kind: 'init',
988                         });
989                     }
990                     if (node.initializer) {
991                         result.value = this.createNode(node, {
992                             type: ts_estree_1.AST_NODE_TYPES.AssignmentPattern,
993                             left: this.convertChild(node.name),
994                             right: this.convertChild(node.initializer),
995                             range: [node.name.getStart(this.ast), node.initializer.end],
996                         });
997                     }
998                     return result;
999                 }
1000             }
1001             case SyntaxKind.ArrowFunction: {
1002                 const result = this.createNode(node, {
1003                     type: ts_estree_1.AST_NODE_TYPES.ArrowFunctionExpression,
1004                     generator: false,
1005                     id: null,
1006                     params: this.convertParameters(node.parameters),
1007                     body: this.convertChild(node.body),
1008                     async: node_utils_1.hasModifier(SyntaxKind.AsyncKeyword, node),
1009                     expression: node.body.kind !== SyntaxKind.Block,
1010                 });
1011                 // Process returnType
1012                 if (node.type) {
1013                     result.returnType = this.convertTypeAnnotation(node.type, node);
1014                 }
1015                 // Process typeParameters
1016                 if (node.typeParameters) {
1017                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1018                 }
1019                 return result;
1020             }
1021             case SyntaxKind.YieldExpression:
1022                 return this.createNode(node, {
1023                     type: ts_estree_1.AST_NODE_TYPES.YieldExpression,
1024                     delegate: !!node.asteriskToken,
1025                     argument: this.convertChild(node.expression),
1026                 });
1027             case SyntaxKind.AwaitExpression:
1028                 return this.createNode(node, {
1029                     type: ts_estree_1.AST_NODE_TYPES.AwaitExpression,
1030                     argument: this.convertChild(node.expression),
1031                 });
1032             // Template Literals
1033             case SyntaxKind.NoSubstitutionTemplateLiteral:
1034                 return this.createNode(node, {
1035                     type: ts_estree_1.AST_NODE_TYPES.TemplateLiteral,
1036                     quasis: [
1037                         this.createNode(node, {
1038                             type: ts_estree_1.AST_NODE_TYPES.TemplateElement,
1039                             value: {
1040                                 raw: this.ast.text.slice(node.getStart(this.ast) + 1, node.end - 1),
1041                                 cooked: node.text,
1042                             },
1043                             tail: true,
1044                         }),
1045                     ],
1046                     expressions: [],
1047                 });
1048             case SyntaxKind.TemplateExpression: {
1049                 const result = this.createNode(node, {
1050                     type: ts_estree_1.AST_NODE_TYPES.TemplateLiteral,
1051                     quasis: [this.convertChild(node.head)],
1052                     expressions: [],
1053                 });
1054                 node.templateSpans.forEach(templateSpan => {
1055                     result.expressions.push(this.convertChild(templateSpan.expression));
1056                     result.quasis.push(this.convertChild(templateSpan.literal));
1057                 });
1058                 return result;
1059             }
1060             case SyntaxKind.TaggedTemplateExpression:
1061                 return this.createNode(node, {
1062                     type: ts_estree_1.AST_NODE_TYPES.TaggedTemplateExpression,
1063                     typeParameters: node.typeArguments
1064                         ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
1065                         : undefined,
1066                     tag: this.convertChild(node.tag),
1067                     quasi: this.convertChild(node.template),
1068                 });
1069             case SyntaxKind.TemplateHead:
1070             case SyntaxKind.TemplateMiddle:
1071             case SyntaxKind.TemplateTail: {
1072                 const tail = node.kind === SyntaxKind.TemplateTail;
1073                 return this.createNode(node, {
1074                     type: ts_estree_1.AST_NODE_TYPES.TemplateElement,
1075                     value: {
1076                         raw: this.ast.text.slice(node.getStart(this.ast) + 1, node.end - (tail ? 1 : 2)),
1077                         cooked: node.text,
1078                     },
1079                     tail,
1080                 });
1081             }
1082             // Patterns
1083             case SyntaxKind.SpreadAssignment:
1084             case SyntaxKind.SpreadElement: {
1085                 if (this.allowPattern) {
1086                     return this.createNode(node, {
1087                         type: ts_estree_1.AST_NODE_TYPES.RestElement,
1088                         argument: this.convertPattern(node.expression),
1089                     });
1090                 }
1091                 else {
1092                     return this.createNode(node, {
1093                         type: ts_estree_1.AST_NODE_TYPES.SpreadElement,
1094                         argument: this.convertChild(node.expression),
1095                     });
1096                 }
1097             }
1098             case SyntaxKind.Parameter: {
1099                 let parameter;
1100                 let result;
1101                 if (node.dotDotDotToken) {
1102                     parameter = result = this.createNode(node, {
1103                         type: ts_estree_1.AST_NODE_TYPES.RestElement,
1104                         argument: this.convertChild(node.name),
1105                     });
1106                 }
1107                 else if (node.initializer) {
1108                     parameter = this.convertChild(node.name);
1109                     result = this.createNode(node, {
1110                         type: ts_estree_1.AST_NODE_TYPES.AssignmentPattern,
1111                         left: parameter,
1112                         right: this.convertChild(node.initializer),
1113                     });
1114                     if (node.modifiers) {
1115                         // AssignmentPattern should not contain modifiers in range
1116                         result.range[0] = parameter.range[0];
1117                         result.loc = node_utils_1.getLocFor(result.range[0], result.range[1], this.ast);
1118                     }
1119                 }
1120                 else {
1121                     parameter = result = this.convertChild(node.name, parent);
1122                 }
1123                 if (node.type) {
1124                     parameter.typeAnnotation = this.convertTypeAnnotation(node.type, node);
1125                     this.fixParentLocation(parameter, parameter.typeAnnotation.range);
1126                 }
1127                 if (node.questionToken) {
1128                     if (node.questionToken.end > parameter.range[1]) {
1129                         parameter.range[1] = node.questionToken.end;
1130                         parameter.loc.end = node_utils_1.getLineAndCharacterFor(parameter.range[1], this.ast);
1131                     }
1132                     parameter.optional = true;
1133                 }
1134                 if (node.modifiers) {
1135                     return this.createNode(node, {
1136                         type: ts_estree_1.AST_NODE_TYPES.TSParameterProperty,
1137                         accessibility: (_c = node_utils_1.getTSNodeAccessibility(node)) !== null && _c !== void 0 ? _c : undefined,
1138                         readonly: node_utils_1.hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
1139                         static: node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
1140                         export: node_utils_1.hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
1141                         parameter: result,
1142                     });
1143                 }
1144                 return result;
1145             }
1146             // Classes
1147             case SyntaxKind.ClassDeclaration:
1148             case SyntaxKind.ClassExpression: {
1149                 const heritageClauses = (_d = node.heritageClauses) !== null && _d !== void 0 ? _d : [];
1150                 const classNodeType = node.kind === SyntaxKind.ClassDeclaration
1151                     ? ts_estree_1.AST_NODE_TYPES.ClassDeclaration
1152                     : ts_estree_1.AST_NODE_TYPES.ClassExpression;
1153                 const superClass = heritageClauses.find(clause => clause.token === SyntaxKind.ExtendsKeyword);
1154                 const implementsClause = heritageClauses.find(clause => clause.token === SyntaxKind.ImplementsKeyword);
1155                 const result = this.createNode(node, {
1156                     type: classNodeType,
1157                     id: this.convertChild(node.name),
1158                     body: this.createNode(node, {
1159                         type: ts_estree_1.AST_NODE_TYPES.ClassBody,
1160                         body: [],
1161                         range: [node.members.pos - 1, node.end],
1162                     }),
1163                     superClass: (superClass === null || superClass === void 0 ? void 0 : superClass.types[0]) ? this.convertChild(superClass.types[0].expression)
1164                         : null,
1165                 });
1166                 if (superClass) {
1167                     if (superClass.types.length > 1) {
1168                         throw node_utils_1.createError(this.ast, superClass.types[1].pos, 'Classes can only extend a single class.');
1169                     }
1170                     if ((_e = superClass.types[0]) === null || _e === void 0 ? void 0 : _e.typeArguments) {
1171                         result.superTypeParameters = this.convertTypeArgumentsToTypeParameters(superClass.types[0].typeArguments, superClass.types[0]);
1172                     }
1173                 }
1174                 if (node.typeParameters) {
1175                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1176                 }
1177                 if (implementsClause) {
1178                     result.implements = implementsClause.types.map(el => this.convertChild(el));
1179                 }
1180                 /**
1181                  * TypeScript class declarations can be defined as "abstract"
1182                  */
1183                 if (node_utils_1.hasModifier(SyntaxKind.AbstractKeyword, node)) {
1184                     result.abstract = true;
1185                 }
1186                 if (node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node)) {
1187                     result.declare = true;
1188                 }
1189                 if (node.decorators) {
1190                     result.decorators = node.decorators.map(el => this.convertChild(el));
1191                 }
1192                 const filteredMembers = node.members.filter(node_utils_1.isESTreeClassMember);
1193                 if (filteredMembers.length) {
1194                     result.body.body = filteredMembers.map(el => this.convertChild(el));
1195                 }
1196                 // check for exports
1197                 return this.fixExports(node, result);
1198             }
1199             // Modules
1200             case SyntaxKind.ModuleBlock:
1201                 return this.createNode(node, {
1202                     type: ts_estree_1.AST_NODE_TYPES.TSModuleBlock,
1203                     body: this.convertBodyExpressions(node.statements, node),
1204                 });
1205             case SyntaxKind.ImportDeclaration: {
1206                 const result = this.createNode(node, {
1207                     type: ts_estree_1.AST_NODE_TYPES.ImportDeclaration,
1208                     source: this.convertChild(node.moduleSpecifier),
1209                     specifiers: [],
1210                     importKind: 'value',
1211                 });
1212                 if (node.importClause) {
1213                     if (node.importClause.isTypeOnly) {
1214                         result.importKind = 'type';
1215                     }
1216                     if (node.importClause.name) {
1217                         result.specifiers.push(this.convertChild(node.importClause));
1218                     }
1219                     if (node.importClause.namedBindings) {
1220                         switch (node.importClause.namedBindings.kind) {
1221                             case SyntaxKind.NamespaceImport:
1222                                 result.specifiers.push(this.convertChild(node.importClause.namedBindings));
1223                                 break;
1224                             case SyntaxKind.NamedImports:
1225                                 result.specifiers = result.specifiers.concat(node.importClause.namedBindings.elements.map(el => this.convertChild(el)));
1226                                 break;
1227                         }
1228                     }
1229                 }
1230                 return result;
1231             }
1232             case SyntaxKind.NamespaceImport:
1233                 return this.createNode(node, {
1234                     type: ts_estree_1.AST_NODE_TYPES.ImportNamespaceSpecifier,
1235                     local: this.convertChild(node.name),
1236                 });
1237             case SyntaxKind.ImportSpecifier:
1238                 return this.createNode(node, {
1239                     type: ts_estree_1.AST_NODE_TYPES.ImportSpecifier,
1240                     local: this.convertChild(node.name),
1241                     imported: this.convertChild((_f = node.propertyName) !== null && _f !== void 0 ? _f : node.name),
1242                 });
1243             case SyntaxKind.ImportClause:
1244                 return this.createNode(node, {
1245                     type: ts_estree_1.AST_NODE_TYPES.ImportDefaultSpecifier,
1246                     local: this.convertChild(node.name),
1247                     range: [node.getStart(this.ast), node.name.end],
1248                 });
1249             case SyntaxKind.ExportDeclaration:
1250                 if (((_g = node.exportClause) === null || _g === void 0 ? void 0 : _g.kind) === SyntaxKind.NamedExports) {
1251                     return this.createNode(node, {
1252                         type: ts_estree_1.AST_NODE_TYPES.ExportNamedDeclaration,
1253                         source: this.convertChild(node.moduleSpecifier),
1254                         specifiers: node.exportClause.elements.map(el => this.convertChild(el)),
1255                         exportKind: node.isTypeOnly ? 'type' : 'value',
1256                         declaration: null,
1257                     });
1258                 }
1259                 else {
1260                     return this.createNode(node, {
1261                         type: ts_estree_1.AST_NODE_TYPES.ExportAllDeclaration,
1262                         source: this.convertChild(node.moduleSpecifier),
1263                         exportKind: node.isTypeOnly ? 'type' : 'value',
1264                         exported: 
1265                         // note - for compat with 3.7.x, where node.exportClause is always undefined and
1266                         //        SyntaxKind.NamespaceExport does not exist yet (i.e. is undefined), this
1267                         //        cannot be shortened to an optional chain, or else you end up with
1268                         //        undefined === undefined, and the true path will hard error at runtime
1269                         node.exportClause &&
1270                             node.exportClause.kind === SyntaxKind.NamespaceExport
1271                             ? this.convertChild(node.exportClause.name)
1272                             : null,
1273                     });
1274                 }
1275             case SyntaxKind.ExportSpecifier:
1276                 return this.createNode(node, {
1277                     type: ts_estree_1.AST_NODE_TYPES.ExportSpecifier,
1278                     local: this.convertChild((_h = node.propertyName) !== null && _h !== void 0 ? _h : node.name),
1279                     exported: this.convertChild(node.name),
1280                 });
1281             case SyntaxKind.ExportAssignment:
1282                 if (node.isExportEquals) {
1283                     return this.createNode(node, {
1284                         type: ts_estree_1.AST_NODE_TYPES.TSExportAssignment,
1285                         expression: this.convertChild(node.expression),
1286                     });
1287                 }
1288                 else {
1289                     return this.createNode(node, {
1290                         type: ts_estree_1.AST_NODE_TYPES.ExportDefaultDeclaration,
1291                         declaration: this.convertChild(node.expression),
1292                         exportKind: 'value',
1293                     });
1294                 }
1295             // Unary Operations
1296             case SyntaxKind.PrefixUnaryExpression:
1297             case SyntaxKind.PostfixUnaryExpression: {
1298                 const operator = node_utils_1.getTextForTokenKind(node.operator);
1299                 /**
1300                  * ESTree uses UpdateExpression for ++/--
1301                  */
1302                 if (operator === '++' || operator === '--') {
1303                     return this.createNode(node, {
1304                         type: ts_estree_1.AST_NODE_TYPES.UpdateExpression,
1305                         operator,
1306                         prefix: node.kind === SyntaxKind.PrefixUnaryExpression,
1307                         argument: this.convertChild(node.operand),
1308                     });
1309                 }
1310                 else {
1311                     return this.createNode(node, {
1312                         type: ts_estree_1.AST_NODE_TYPES.UnaryExpression,
1313                         operator,
1314                         prefix: node.kind === SyntaxKind.PrefixUnaryExpression,
1315                         argument: this.convertChild(node.operand),
1316                     });
1317                 }
1318             }
1319             case SyntaxKind.DeleteExpression:
1320                 return this.createNode(node, {
1321                     type: ts_estree_1.AST_NODE_TYPES.UnaryExpression,
1322                     operator: 'delete',
1323                     prefix: true,
1324                     argument: this.convertChild(node.expression),
1325                 });
1326             case SyntaxKind.VoidExpression:
1327                 return this.createNode(node, {
1328                     type: ts_estree_1.AST_NODE_TYPES.UnaryExpression,
1329                     operator: 'void',
1330                     prefix: true,
1331                     argument: this.convertChild(node.expression),
1332                 });
1333             case SyntaxKind.TypeOfExpression:
1334                 return this.createNode(node, {
1335                     type: ts_estree_1.AST_NODE_TYPES.UnaryExpression,
1336                     operator: 'typeof',
1337                     prefix: true,
1338                     argument: this.convertChild(node.expression),
1339                 });
1340             case SyntaxKind.TypeOperator:
1341                 return this.createNode(node, {
1342                     type: ts_estree_1.AST_NODE_TYPES.TSTypeOperator,
1343                     operator: node_utils_1.getTextForTokenKind(node.operator),
1344                     typeAnnotation: this.convertChild(node.type),
1345                 });
1346             // Binary Operations
1347             case SyntaxKind.BinaryExpression: {
1348                 // TypeScript uses BinaryExpression for sequences as well
1349                 if (node_utils_1.isComma(node.operatorToken)) {
1350                     const result = this.createNode(node, {
1351                         type: ts_estree_1.AST_NODE_TYPES.SequenceExpression,
1352                         expressions: [],
1353                     });
1354                     const left = this.convertChild(node.left);
1355                     if (left.type === ts_estree_1.AST_NODE_TYPES.SequenceExpression &&
1356                         node.left.kind !== SyntaxKind.ParenthesizedExpression) {
1357                         result.expressions = result.expressions.concat(left.expressions);
1358                     }
1359                     else {
1360                         result.expressions.push(left);
1361                     }
1362                     result.expressions.push(this.convertChild(node.right));
1363                     return result;
1364                 }
1365                 else {
1366                     const type = node_utils_1.getBinaryExpressionType(node.operatorToken);
1367                     if (this.allowPattern &&
1368                         type === ts_estree_1.AST_NODE_TYPES.AssignmentExpression) {
1369                         return this.createNode(node, {
1370                             type: ts_estree_1.AST_NODE_TYPES.AssignmentPattern,
1371                             left: this.convertPattern(node.left, node),
1372                             right: this.convertChild(node.right),
1373                         });
1374                     }
1375                     return this.createNode(node, {
1376                         type,
1377                         operator: node_utils_1.getTextForTokenKind(node.operatorToken.kind),
1378                         left: this.converter(node.left, node, this.inTypeMode, type === ts_estree_1.AST_NODE_TYPES.AssignmentExpression),
1379                         right: this.convertChild(node.right),
1380                     });
1381                 }
1382             }
1383             case SyntaxKind.PropertyAccessExpression: {
1384                 const object = this.convertChild(node.expression);
1385                 const property = this.convertChild(node.name);
1386                 const computed = false;
1387                 const isLocallyOptional = node.questionDotToken !== undefined;
1388                 // the optional expression should propagate up the member expression tree
1389                 const isChildOptional = node_utils_1.isChildOptionalChain(node, object);
1390                 if (isLocallyOptional || isChildOptional) {
1391                     return this.createNode(node, {
1392                         type: ts_estree_1.AST_NODE_TYPES.OptionalMemberExpression,
1393                         object,
1394                         property,
1395                         computed,
1396                         optional: isLocallyOptional,
1397                     });
1398                 }
1399                 else {
1400                     return this.createNode(node, {
1401                         type: ts_estree_1.AST_NODE_TYPES.MemberExpression,
1402                         object,
1403                         property,
1404                         computed,
1405                         optional: false,
1406                     });
1407                 }
1408             }
1409             case SyntaxKind.ElementAccessExpression: {
1410                 const object = this.convertChild(node.expression);
1411                 const property = this.convertChild(node.argumentExpression);
1412                 const computed = true;
1413                 const isLocallyOptional = node.questionDotToken !== undefined;
1414                 // the optional expression should propagate up the member expression tree
1415                 const isChildOptional = node_utils_1.isChildOptionalChain(node, object);
1416                 if (isLocallyOptional || isChildOptional) {
1417                     return this.createNode(node, {
1418                         type: ts_estree_1.AST_NODE_TYPES.OptionalMemberExpression,
1419                         object,
1420                         property,
1421                         computed,
1422                         optional: isLocallyOptional,
1423                     });
1424                 }
1425                 else {
1426                     return this.createNode(node, {
1427                         type: ts_estree_1.AST_NODE_TYPES.MemberExpression,
1428                         object,
1429                         property,
1430                         computed,
1431                         optional: false,
1432                     });
1433                 }
1434             }
1435             case SyntaxKind.CallExpression: {
1436                 if (node.expression.kind === SyntaxKind.ImportKeyword) {
1437                     if (node.arguments.length !== 1) {
1438                         throw node_utils_1.createError(this.ast, node.arguments.pos, 'Dynamic import must have one specifier as an argument.');
1439                     }
1440                     return this.createNode(node, {
1441                         type: ts_estree_1.AST_NODE_TYPES.ImportExpression,
1442                         source: this.convertChild(node.arguments[0]),
1443                     });
1444                 }
1445                 const callee = this.convertChild(node.expression);
1446                 const args = node.arguments.map(el => this.convertChild(el));
1447                 let result;
1448                 const isLocallyOptional = node.questionDotToken !== undefined;
1449                 // the optional expression should propagate up the member expression tree
1450                 const isChildOptional = node_utils_1.isChildOptionalChain(node, callee);
1451                 if (isLocallyOptional || isChildOptional) {
1452                     result = this.createNode(node, {
1453                         type: ts_estree_1.AST_NODE_TYPES.OptionalCallExpression,
1454                         callee,
1455                         arguments: args,
1456                         optional: isLocallyOptional,
1457                     });
1458                 }
1459                 else {
1460                     result = this.createNode(node, {
1461                         type: ts_estree_1.AST_NODE_TYPES.CallExpression,
1462                         callee,
1463                         arguments: args,
1464                         optional: false,
1465                     });
1466                 }
1467                 if (node.typeArguments) {
1468                     result.typeParameters = this.convertTypeArgumentsToTypeParameters(node.typeArguments, node);
1469                 }
1470                 return result;
1471             }
1472             case SyntaxKind.NewExpression: {
1473                 // NOTE - NewExpression cannot have an optional chain in it
1474                 const result = this.createNode(node, {
1475                     type: ts_estree_1.AST_NODE_TYPES.NewExpression,
1476                     callee: this.convertChild(node.expression),
1477                     arguments: node.arguments
1478                         ? node.arguments.map(el => this.convertChild(el))
1479                         : [],
1480                 });
1481                 if (node.typeArguments) {
1482                     result.typeParameters = this.convertTypeArgumentsToTypeParameters(node.typeArguments, node);
1483                 }
1484                 return result;
1485             }
1486             case SyntaxKind.ConditionalExpression:
1487                 return this.createNode(node, {
1488                     type: ts_estree_1.AST_NODE_TYPES.ConditionalExpression,
1489                     test: this.convertChild(node.condition),
1490                     consequent: this.convertChild(node.whenTrue),
1491                     alternate: this.convertChild(node.whenFalse),
1492                 });
1493             case SyntaxKind.MetaProperty: {
1494                 return this.createNode(node, {
1495                     type: ts_estree_1.AST_NODE_TYPES.MetaProperty,
1496                     meta: this.createNode(
1497                     // TODO: do we really want to convert it to Token?
1498                     node.getFirstToken(), {
1499                         type: ts_estree_1.AST_NODE_TYPES.Identifier,
1500                         name: node_utils_1.getTextForTokenKind(node.keywordToken),
1501                     }),
1502                     property: this.convertChild(node.name),
1503                 });
1504             }
1505             case SyntaxKind.Decorator: {
1506                 return this.createNode(node, {
1507                     type: ts_estree_1.AST_NODE_TYPES.Decorator,
1508                     expression: this.convertChild(node.expression),
1509                 });
1510             }
1511             // Literals
1512             case SyntaxKind.StringLiteral: {
1513                 const result = this.createNode(node, {
1514                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1515                     raw: '',
1516                     value: '',
1517                 });
1518                 result.raw = this.ast.text.slice(result.range[0], result.range[1]);
1519                 if ('name' in parent && parent.name === node) {
1520                     result.value = node.text;
1521                 }
1522                 else {
1523                     result.value = node_utils_1.unescapeStringLiteralText(node.text);
1524                 }
1525                 return result;
1526             }
1527             case SyntaxKind.NumericLiteral: {
1528                 return this.createNode(node, {
1529                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1530                     value: Number(node.text),
1531                     raw: node.getText(),
1532                 });
1533             }
1534             case SyntaxKind.BigIntLiteral: {
1535                 const range = node_utils_1.getRange(node, this.ast);
1536                 const rawValue = this.ast.text.slice(range[0], range[1]);
1537                 const bigint = rawValue
1538                     // remove suffix `n`
1539                     .slice(0, -1)
1540                     // `BigInt` doesn't accept numeric separator
1541                     // and `bigint` property should not include numeric separator
1542                     .replace(/_/g, '');
1543                 const value = typeof BigInt !== 'undefined' ? BigInt(bigint) : null;
1544                 return this.createNode(node, {
1545                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1546                     raw: rawValue,
1547                     value: value,
1548                     bigint: value === null ? bigint : String(value),
1549                     range,
1550                 });
1551             }
1552             case SyntaxKind.RegularExpressionLiteral: {
1553                 const pattern = node.text.slice(1, node.text.lastIndexOf('/'));
1554                 const flags = node.text.slice(node.text.lastIndexOf('/') + 1);
1555                 let regex = null;
1556                 try {
1557                     regex = new RegExp(pattern, flags);
1558                 }
1559                 catch (exception) {
1560                     regex = null;
1561                 }
1562                 return this.createNode(node, {
1563                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1564                     value: regex,
1565                     raw: node.text,
1566                     regex: {
1567                         pattern,
1568                         flags,
1569                     },
1570                 });
1571             }
1572             case SyntaxKind.TrueKeyword:
1573                 return this.createNode(node, {
1574                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1575                     value: true,
1576                     raw: 'true',
1577                 });
1578             case SyntaxKind.FalseKeyword:
1579                 return this.createNode(node, {
1580                     type: ts_estree_1.AST_NODE_TYPES.Literal,
1581                     value: false,
1582                     raw: 'false',
1583                 });
1584             case SyntaxKind.NullKeyword: {
1585                 if (this.inTypeMode) {
1586                     return this.createNode(node, {
1587                         type: ts_estree_1.AST_NODE_TYPES.TSNullKeyword,
1588                     });
1589                 }
1590                 else {
1591                     return this.createNode(node, {
1592                         type: ts_estree_1.AST_NODE_TYPES.Literal,
1593                         value: null,
1594                         raw: 'null',
1595                     });
1596                 }
1597             }
1598             case SyntaxKind.EmptyStatement:
1599                 return this.createNode(node, {
1600                     type: ts_estree_1.AST_NODE_TYPES.EmptyStatement,
1601                 });
1602             case SyntaxKind.DebuggerStatement:
1603                 return this.createNode(node, {
1604                     type: ts_estree_1.AST_NODE_TYPES.DebuggerStatement,
1605                 });
1606             // JSX
1607             case SyntaxKind.JsxElement:
1608                 return this.createNode(node, {
1609                     type: ts_estree_1.AST_NODE_TYPES.JSXElement,
1610                     openingElement: this.convertChild(node.openingElement),
1611                     closingElement: this.convertChild(node.closingElement),
1612                     children: node.children.map(el => this.convertChild(el)),
1613                 });
1614             case SyntaxKind.JsxFragment:
1615                 return this.createNode(node, {
1616                     type: ts_estree_1.AST_NODE_TYPES.JSXFragment,
1617                     openingFragment: this.convertChild(node.openingFragment),
1618                     closingFragment: this.convertChild(node.closingFragment),
1619                     children: node.children.map(el => this.convertChild(el)),
1620                 });
1621             case SyntaxKind.JsxSelfClosingElement: {
1622                 return this.createNode(node, {
1623                     type: ts_estree_1.AST_NODE_TYPES.JSXElement,
1624                     /**
1625                      * Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement,
1626                      * TypeScript does not seem to have the idea of openingElement when tag is self-closing
1627                      */
1628                     openingElement: this.createNode(node, {
1629                         type: ts_estree_1.AST_NODE_TYPES.JSXOpeningElement,
1630                         typeParameters: node.typeArguments
1631                             ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
1632                             : undefined,
1633                         selfClosing: true,
1634                         name: this.convertJSXTagName(node.tagName, node),
1635                         attributes: node.attributes.properties.map(el => this.convertChild(el)),
1636                         range: node_utils_1.getRange(node, this.ast),
1637                     }),
1638                     closingElement: null,
1639                     children: [],
1640                 });
1641             }
1642             case SyntaxKind.JsxOpeningElement:
1643                 return this.createNode(node, {
1644                     type: ts_estree_1.AST_NODE_TYPES.JSXOpeningElement,
1645                     typeParameters: node.typeArguments
1646                         ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
1647                         : undefined,
1648                     selfClosing: false,
1649                     name: this.convertJSXTagName(node.tagName, node),
1650                     attributes: node.attributes.properties.map(el => this.convertChild(el)),
1651                 });
1652             case SyntaxKind.JsxClosingElement:
1653                 return this.createNode(node, {
1654                     type: ts_estree_1.AST_NODE_TYPES.JSXClosingElement,
1655                     name: this.convertJSXTagName(node.tagName, node),
1656                 });
1657             case SyntaxKind.JsxOpeningFragment:
1658                 return this.createNode(node, {
1659                     type: ts_estree_1.AST_NODE_TYPES.JSXOpeningFragment,
1660                 });
1661             case SyntaxKind.JsxClosingFragment:
1662                 return this.createNode(node, {
1663                     type: ts_estree_1.AST_NODE_TYPES.JSXClosingFragment,
1664                 });
1665             case SyntaxKind.JsxExpression: {
1666                 const expression = node.expression
1667                     ? this.convertChild(node.expression)
1668                     : this.createNode(node, {
1669                         type: ts_estree_1.AST_NODE_TYPES.JSXEmptyExpression,
1670                         range: [node.getStart(this.ast) + 1, node.getEnd() - 1],
1671                     });
1672                 if (node.dotDotDotToken) {
1673                     return this.createNode(node, {
1674                         type: ts_estree_1.AST_NODE_TYPES.JSXSpreadChild,
1675                         expression,
1676                     });
1677                 }
1678                 else {
1679                     return this.createNode(node, {
1680                         type: ts_estree_1.AST_NODE_TYPES.JSXExpressionContainer,
1681                         expression,
1682                     });
1683                 }
1684             }
1685             case SyntaxKind.JsxAttribute: {
1686                 const attributeName = this.convertChild(node.name);
1687                 attributeName.type = ts_estree_1.AST_NODE_TYPES.JSXIdentifier;
1688                 return this.createNode(node, {
1689                     type: ts_estree_1.AST_NODE_TYPES.JSXAttribute,
1690                     name: attributeName,
1691                     value: this.convertChild(node.initializer),
1692                 });
1693             }
1694             /**
1695              * The JSX AST changed the node type for string literals
1696              * inside a JSX Element from `Literal` to `JSXText`. We
1697              * provide a flag to support both types until `Literal`
1698              * node type is deprecated in ESLint v5.
1699              */
1700             case SyntaxKind.JsxText: {
1701                 const start = node.getFullStart();
1702                 const end = node.getEnd();
1703                 if (this.options.useJSXTextNode) {
1704                     return this.createNode(node, {
1705                         type: ts_estree_1.AST_NODE_TYPES.JSXText,
1706                         value: this.ast.text.slice(start, end),
1707                         raw: this.ast.text.slice(start, end),
1708                         range: [start, end],
1709                     });
1710                 }
1711                 else {
1712                     return this.createNode(node, {
1713                         type: ts_estree_1.AST_NODE_TYPES.Literal,
1714                         value: this.ast.text.slice(start, end),
1715                         raw: this.ast.text.slice(start, end),
1716                         range: [start, end],
1717                     });
1718                 }
1719             }
1720             case SyntaxKind.JsxSpreadAttribute:
1721                 return this.createNode(node, {
1722                     type: ts_estree_1.AST_NODE_TYPES.JSXSpreadAttribute,
1723                     argument: this.convertChild(node.expression),
1724                 });
1725             case SyntaxKind.QualifiedName: {
1726                 return this.createNode(node, {
1727                     type: ts_estree_1.AST_NODE_TYPES.TSQualifiedName,
1728                     left: this.convertChild(node.left),
1729                     right: this.convertChild(node.right),
1730                 });
1731             }
1732             // TypeScript specific
1733             case SyntaxKind.TypeReference: {
1734                 return this.createNode(node, {
1735                     type: ts_estree_1.AST_NODE_TYPES.TSTypeReference,
1736                     typeName: this.convertType(node.typeName),
1737                     typeParameters: node.typeArguments
1738                         ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
1739                         : undefined,
1740                 });
1741             }
1742             case SyntaxKind.TypeParameter: {
1743                 return this.createNode(node, {
1744                     type: ts_estree_1.AST_NODE_TYPES.TSTypeParameter,
1745                     name: this.convertType(node.name),
1746                     constraint: node.constraint
1747                         ? this.convertType(node.constraint)
1748                         : undefined,
1749                     default: node.default ? this.convertType(node.default) : undefined,
1750                 });
1751             }
1752             case SyntaxKind.ThisType:
1753                 return this.createNode(node, {
1754                     type: ts_estree_1.AST_NODE_TYPES.TSThisType,
1755                 });
1756             case SyntaxKind.AnyKeyword:
1757             case SyntaxKind.BigIntKeyword:
1758             case SyntaxKind.BooleanKeyword:
1759             case SyntaxKind.NeverKeyword:
1760             case SyntaxKind.NumberKeyword:
1761             case SyntaxKind.ObjectKeyword:
1762             case SyntaxKind.StringKeyword:
1763             case SyntaxKind.SymbolKeyword:
1764             case SyntaxKind.UnknownKeyword:
1765             case SyntaxKind.VoidKeyword:
1766             case SyntaxKind.UndefinedKeyword: {
1767                 return this.createNode(node, {
1768                     type: ts_estree_1.AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}`],
1769                 });
1770             }
1771             case SyntaxKind.NonNullExpression: {
1772                 return this.createNode(node, {
1773                     type: ts_estree_1.AST_NODE_TYPES.TSNonNullExpression,
1774                     expression: this.convertChild(node.expression),
1775                 });
1776             }
1777             case SyntaxKind.TypeLiteral: {
1778                 return this.createNode(node, {
1779                     type: ts_estree_1.AST_NODE_TYPES.TSTypeLiteral,
1780                     members: node.members.map(el => this.convertChild(el)),
1781                 });
1782             }
1783             case SyntaxKind.ArrayType: {
1784                 return this.createNode(node, {
1785                     type: ts_estree_1.AST_NODE_TYPES.TSArrayType,
1786                     elementType: this.convertType(node.elementType),
1787                 });
1788             }
1789             case SyntaxKind.IndexedAccessType: {
1790                 return this.createNode(node, {
1791                     type: ts_estree_1.AST_NODE_TYPES.TSIndexedAccessType,
1792                     objectType: this.convertType(node.objectType),
1793                     indexType: this.convertType(node.indexType),
1794                 });
1795             }
1796             case SyntaxKind.ConditionalType: {
1797                 return this.createNode(node, {
1798                     type: ts_estree_1.AST_NODE_TYPES.TSConditionalType,
1799                     checkType: this.convertType(node.checkType),
1800                     extendsType: this.convertType(node.extendsType),
1801                     trueType: this.convertType(node.trueType),
1802                     falseType: this.convertType(node.falseType),
1803                 });
1804             }
1805             case SyntaxKind.TypeQuery: {
1806                 return this.createNode(node, {
1807                     type: ts_estree_1.AST_NODE_TYPES.TSTypeQuery,
1808                     exprName: this.convertType(node.exprName),
1809                 });
1810             }
1811             case SyntaxKind.MappedType: {
1812                 const result = this.createNode(node, {
1813                     type: ts_estree_1.AST_NODE_TYPES.TSMappedType,
1814                     typeParameter: this.convertType(node.typeParameter),
1815                 });
1816                 if (node.readonlyToken) {
1817                     if (node.readonlyToken.kind === SyntaxKind.ReadonlyKeyword) {
1818                         result.readonly = true;
1819                     }
1820                     else {
1821                         result.readonly = node_utils_1.getTextForTokenKind(node.readonlyToken.kind);
1822                     }
1823                 }
1824                 if (node.questionToken) {
1825                     if (node.questionToken.kind === SyntaxKind.QuestionToken) {
1826                         result.optional = true;
1827                     }
1828                     else {
1829                         result.optional = node_utils_1.getTextForTokenKind(node.questionToken.kind);
1830                     }
1831                 }
1832                 if (node.type) {
1833                     result.typeAnnotation = this.convertType(node.type);
1834                 }
1835                 return result;
1836             }
1837             case SyntaxKind.ParenthesizedExpression:
1838                 return this.convertChild(node.expression, parent);
1839             case SyntaxKind.TypeAliasDeclaration: {
1840                 const result = this.createNode(node, {
1841                     type: ts_estree_1.AST_NODE_TYPES.TSTypeAliasDeclaration,
1842                     id: this.convertChild(node.name),
1843                     typeAnnotation: this.convertType(node.type),
1844                 });
1845                 if (node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node)) {
1846                     result.declare = true;
1847                 }
1848                 // Process typeParameters
1849                 if (node.typeParameters) {
1850                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1851                 }
1852                 // check for exports
1853                 return this.fixExports(node, result);
1854             }
1855             case SyntaxKind.MethodSignature: {
1856                 const result = this.createNode(node, {
1857                     type: ts_estree_1.AST_NODE_TYPES.TSMethodSignature,
1858                     computed: node_utils_1.isComputedProperty(node.name),
1859                     key: this.convertChild(node.name),
1860                     params: this.convertParameters(node.parameters),
1861                 });
1862                 if (node_utils_1.isOptional(node)) {
1863                     result.optional = true;
1864                 }
1865                 if (node.type) {
1866                     result.returnType = this.convertTypeAnnotation(node.type, node);
1867                 }
1868                 if (node_utils_1.hasModifier(SyntaxKind.ReadonlyKeyword, node)) {
1869                     result.readonly = true;
1870                 }
1871                 if (node.typeParameters) {
1872                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1873                 }
1874                 const accessibility = node_utils_1.getTSNodeAccessibility(node);
1875                 if (accessibility) {
1876                     result.accessibility = accessibility;
1877                 }
1878                 if (node_utils_1.hasModifier(SyntaxKind.ExportKeyword, node)) {
1879                     result.export = true;
1880                 }
1881                 if (node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node)) {
1882                     result.static = true;
1883                 }
1884                 return result;
1885             }
1886             case SyntaxKind.PropertySignature: {
1887                 const result = this.createNode(node, {
1888                     type: ts_estree_1.AST_NODE_TYPES.TSPropertySignature,
1889                     optional: node_utils_1.isOptional(node) || undefined,
1890                     computed: node_utils_1.isComputedProperty(node.name),
1891                     key: this.convertChild(node.name),
1892                     typeAnnotation: node.type
1893                         ? this.convertTypeAnnotation(node.type, node)
1894                         : undefined,
1895                     initializer: this.convertChild(node.initializer) || undefined,
1896                     readonly: node_utils_1.hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
1897                     static: node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
1898                     export: node_utils_1.hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
1899                 });
1900                 const accessibility = node_utils_1.getTSNodeAccessibility(node);
1901                 if (accessibility) {
1902                     result.accessibility = accessibility;
1903                 }
1904                 return result;
1905             }
1906             case SyntaxKind.IndexSignature: {
1907                 const result = this.createNode(node, {
1908                     type: ts_estree_1.AST_NODE_TYPES.TSIndexSignature,
1909                     parameters: node.parameters.map(el => this.convertChild(el)),
1910                 });
1911                 if (node.type) {
1912                     result.typeAnnotation = this.convertTypeAnnotation(node.type, node);
1913                 }
1914                 if (node_utils_1.hasModifier(SyntaxKind.ReadonlyKeyword, node)) {
1915                     result.readonly = true;
1916                 }
1917                 const accessibility = node_utils_1.getTSNodeAccessibility(node);
1918                 if (accessibility) {
1919                     result.accessibility = accessibility;
1920                 }
1921                 if (node_utils_1.hasModifier(SyntaxKind.ExportKeyword, node)) {
1922                     result.export = true;
1923                 }
1924                 if (node_utils_1.hasModifier(SyntaxKind.StaticKeyword, node)) {
1925                     result.static = true;
1926                 }
1927                 return result;
1928             }
1929             case SyntaxKind.ConstructorType:
1930             case SyntaxKind.FunctionType:
1931             case SyntaxKind.ConstructSignature:
1932             case SyntaxKind.CallSignature: {
1933                 let type;
1934                 switch (node.kind) {
1935                     case SyntaxKind.ConstructSignature:
1936                         type = ts_estree_1.AST_NODE_TYPES.TSConstructSignatureDeclaration;
1937                         break;
1938                     case SyntaxKind.CallSignature:
1939                         type = ts_estree_1.AST_NODE_TYPES.TSCallSignatureDeclaration;
1940                         break;
1941                     case SyntaxKind.FunctionType:
1942                         type = ts_estree_1.AST_NODE_TYPES.TSFunctionType;
1943                         break;
1944                     case SyntaxKind.ConstructorType:
1945                     default:
1946                         type = ts_estree_1.AST_NODE_TYPES.TSConstructorType;
1947                         break;
1948                 }
1949                 const result = this.createNode(node, {
1950                     type: type,
1951                     params: this.convertParameters(node.parameters),
1952                 });
1953                 if (node.type) {
1954                     result.returnType = this.convertTypeAnnotation(node.type, node);
1955                 }
1956                 if (node.typeParameters) {
1957                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1958                 }
1959                 return result;
1960             }
1961             case SyntaxKind.ExpressionWithTypeArguments: {
1962                 const result = this.createNode(node, {
1963                     type: parent && parent.kind === SyntaxKind.InterfaceDeclaration
1964                         ? ts_estree_1.AST_NODE_TYPES.TSInterfaceHeritage
1965                         : ts_estree_1.AST_NODE_TYPES.TSClassImplements,
1966                     expression: this.convertChild(node.expression),
1967                 });
1968                 if (node.typeArguments) {
1969                     result.typeParameters = this.convertTypeArgumentsToTypeParameters(node.typeArguments, node);
1970                 }
1971                 return result;
1972             }
1973             case SyntaxKind.InterfaceDeclaration: {
1974                 const interfaceHeritageClauses = (_j = node.heritageClauses) !== null && _j !== void 0 ? _j : [];
1975                 const result = this.createNode(node, {
1976                     type: ts_estree_1.AST_NODE_TYPES.TSInterfaceDeclaration,
1977                     body: this.createNode(node, {
1978                         type: ts_estree_1.AST_NODE_TYPES.TSInterfaceBody,
1979                         body: node.members.map(member => this.convertChild(member)),
1980                         range: [node.members.pos - 1, node.end],
1981                     }),
1982                     id: this.convertChild(node.name),
1983                 });
1984                 if (node.typeParameters) {
1985                     result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
1986                 }
1987                 if (interfaceHeritageClauses.length > 0) {
1988                     const interfaceExtends = [];
1989                     const interfaceImplements = [];
1990                     for (const heritageClause of interfaceHeritageClauses) {
1991                         if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
1992                             for (const n of heritageClause.types) {
1993                                 interfaceExtends.push(this.convertChild(n, node));
1994                             }
1995                         }
1996                         else {
1997                             for (const n of heritageClause.types) {
1998                                 interfaceImplements.push(this.convertChild(n, node));
1999                             }
2000                         }
2001                     }
2002                     if (interfaceExtends.length) {
2003                         result.extends = interfaceExtends;
2004                     }
2005                     if (interfaceImplements.length) {
2006                         result.implements = interfaceImplements;
2007                     }
2008                 }
2009                 /**
2010                  * Semantically, decorators are not allowed on interface declarations,
2011                  * but the TypeScript compiler will parse them and produce a valid AST,
2012                  * so we handle them here too.
2013                  */
2014                 if (node.decorators) {
2015                     result.decorators = node.decorators.map(el => this.convertChild(el));
2016                 }
2017                 if (node_utils_1.hasModifier(SyntaxKind.AbstractKeyword, node)) {
2018                     result.abstract = true;
2019                 }
2020                 if (node_utils_1.hasModifier(SyntaxKind.DeclareKeyword, node)) {
2021                     result.declare = true;
2022                 }
2023                 // check for exports
2024                 return this.fixExports(node, result);
2025             }
2026             case SyntaxKind.TypePredicate: {
2027                 const result = this.createNode(node, {
2028                     type: ts_estree_1.AST_NODE_TYPES.TSTypePredicate,
2029                     asserts: node.assertsModifier !== undefined,
2030                     parameterName: this.convertChild(node.parameterName),
2031                     typeAnnotation: null,
2032                 });
2033                 /**
2034                  * Specific fix for type-guard location data
2035                  */
2036                 if (node.type) {
2037                     result.typeAnnotation = this.convertTypeAnnotation(node.type, node);
2038                     result.typeAnnotation.loc = result.typeAnnotation.typeAnnotation.loc;
2039                     result.typeAnnotation.range =
2040                         result.typeAnnotation.typeAnnotation.range;
2041                 }
2042                 return result;
2043             }
2044             case SyntaxKind.ImportType:
2045                 return this.createNode(node, {
2046                     type: ts_estree_1.AST_NODE_TYPES.TSImportType,
2047                     isTypeOf: !!node.isTypeOf,
2048                     parameter: this.convertChild(node.argument),
2049                     qualifier: this.convertChild(node.qualifier),
2050                     typeParameters: node.typeArguments
2051                         ? this.convertTypeArgumentsToTypeParameters(node.typeArguments, node)
2052                         : null,
2053                 });
2054             case SyntaxKind.EnumDeclaration: {
2055                 const result = this.createNode(node, {
2056                     type: ts_estree_1.AST_NODE_TYPES.TSEnumDeclaration,
2057                     id: this.convertChild(node.name),
2058                     members: node.members.map(el => this.convertChild(el)),
2059                 });
2060                 // apply modifiers first...
2061                 this.applyModifiersToResult(result, node.modifiers);
2062                 /**
2063                  * Semantically, decorators are not allowed on enum declarations,
2064                  * but the TypeScript compiler will parse them and produce a valid AST,
2065                  * so we handle them here too.
2066                  */
2067                 if (node.decorators) {
2068                     result.decorators = node.decorators.map(el => this.convertChild(el));
2069                 }
2070                 // ...then check for exports
2071                 return this.fixExports(node, result);
2072             }
2073             case SyntaxKind.EnumMember: {
2074                 const result = this.createNode(node, {
2075                     type: ts_estree_1.AST_NODE_TYPES.TSEnumMember,
2076                     id: this.convertChild(node.name),
2077                 });
2078                 if (node.initializer) {
2079                     result.initializer = this.convertChild(node.initializer);
2080                 }
2081                 if (node.name.kind === ts.SyntaxKind.ComputedPropertyName) {
2082                     result.computed = true;
2083                 }
2084                 return result;
2085             }
2086             case SyntaxKind.ModuleDeclaration: {
2087                 const result = this.createNode(node, {
2088                     type: ts_estree_1.AST_NODE_TYPES.TSModuleDeclaration,
2089                     id: this.convertChild(node.name),
2090                 });
2091                 if (node.body) {
2092                     result.body = this.convertChild(node.body);
2093                 }
2094                 // apply modifiers first...
2095                 this.applyModifiersToResult(result, node.modifiers);
2096                 if (node.flags & ts.NodeFlags.GlobalAugmentation) {
2097                     result.global = true;
2098                 }
2099                 // ...then check for exports
2100                 return this.fixExports(node, result);
2101             }
2102             // TypeScript specific types
2103             case SyntaxKind.OptionalType: {
2104                 return this.createNode(node, {
2105                     type: ts_estree_1.AST_NODE_TYPES.TSOptionalType,
2106                     typeAnnotation: this.convertType(node.type),
2107                 });
2108             }
2109             case SyntaxKind.ParenthesizedType: {
2110                 return this.createNode(node, {
2111                     type: ts_estree_1.AST_NODE_TYPES.TSParenthesizedType,
2112                     typeAnnotation: this.convertType(node.type),
2113                 });
2114             }
2115             case SyntaxKind.TupleType: {
2116                 // In TS 4.0, the `elementTypes` property was changed to `elements`.
2117                 // To support both at compile time, we cast to access the newer version
2118                 // if the former does not exist.
2119                 const elementTypes = node.elementTypes
2120                     ? node.elementTypes.map(el => this.convertType(el))
2121                     : node.elements.map((el) => this.convertType(el));
2122                 return this.createNode(node, {
2123                     type: ts_estree_1.AST_NODE_TYPES.TSTupleType,
2124                     elementTypes,
2125                 });
2126             }
2127             case SyntaxKind.UnionType: {
2128                 return this.createNode(node, {
2129                     type: ts_estree_1.AST_NODE_TYPES.TSUnionType,
2130                     types: node.types.map(el => this.convertType(el)),
2131                 });
2132             }
2133             case SyntaxKind.IntersectionType: {
2134                 return this.createNode(node, {
2135                     type: ts_estree_1.AST_NODE_TYPES.TSIntersectionType,
2136                     types: node.types.map(el => this.convertType(el)),
2137                 });
2138             }
2139             case SyntaxKind.RestType: {
2140                 return this.createNode(node, {
2141                     type: ts_estree_1.AST_NODE_TYPES.TSRestType,
2142                     typeAnnotation: this.convertType(node.type),
2143                 });
2144             }
2145             case SyntaxKind.AsExpression: {
2146                 return this.createNode(node, {
2147                     type: ts_estree_1.AST_NODE_TYPES.TSAsExpression,
2148                     expression: this.convertChild(node.expression),
2149                     typeAnnotation: this.convertType(node.type),
2150                 });
2151             }
2152             case SyntaxKind.InferType: {
2153                 return this.createNode(node, {
2154                     type: ts_estree_1.AST_NODE_TYPES.TSInferType,
2155                     typeParameter: this.convertType(node.typeParameter),
2156                 });
2157             }
2158             case SyntaxKind.LiteralType: {
2159                 return this.createNode(node, {
2160                     type: ts_estree_1.AST_NODE_TYPES.TSLiteralType,
2161                     literal: this.convertType(node.literal),
2162                 });
2163             }
2164             case SyntaxKind.TypeAssertionExpression: {
2165                 return this.createNode(node, {
2166                     type: ts_estree_1.AST_NODE_TYPES.TSTypeAssertion,
2167                     typeAnnotation: this.convertType(node.type),
2168                     expression: this.convertChild(node.expression),
2169                 });
2170             }
2171             case SyntaxKind.ImportEqualsDeclaration: {
2172                 return this.createNode(node, {
2173                     type: ts_estree_1.AST_NODE_TYPES.TSImportEqualsDeclaration,
2174                     id: this.convertChild(node.name),
2175                     moduleReference: this.convertChild(node.moduleReference),
2176                     isExport: node_utils_1.hasModifier(SyntaxKind.ExportKeyword, node),
2177                 });
2178             }
2179             case SyntaxKind.ExternalModuleReference: {
2180                 return this.createNode(node, {
2181                     type: ts_estree_1.AST_NODE_TYPES.TSExternalModuleReference,
2182                     expression: this.convertChild(node.expression),
2183                 });
2184             }
2185             case SyntaxKind.NamespaceExportDeclaration: {
2186                 return this.createNode(node, {
2187                     type: ts_estree_1.AST_NODE_TYPES.TSNamespaceExportDeclaration,
2188                     id: this.convertChild(node.name),
2189                 });
2190             }
2191             case SyntaxKind.AbstractKeyword: {
2192                 return this.createNode(node, {
2193                     type: ts_estree_1.AST_NODE_TYPES.TSAbstractKeyword,
2194                 });
2195             }
2196             default:
2197                 return this.deeplyCopy(node);
2198         }
2199     }
2200 }
2201 exports.Converter = Converter;
2202 //# sourceMappingURL=convert.js.map