Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / typescript-estree / dist / ast-converter.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.astConverter = void 0;
4 const convert_1 = require("./convert");
5 const convert_comments_1 = require("./convert-comments");
6 const node_utils_1 = require("./node-utils");
7 const simple_traverse_1 = require("./simple-traverse");
8 function astConverter(ast, extra, shouldPreserveNodeMaps) {
9     /**
10      * The TypeScript compiler produced fundamental parse errors when parsing the
11      * source.
12      */
13     // internal typescript api...
14     // eslint-disable-next-line @typescript-eslint/no-explicit-any
15     const parseDiagnostics = ast.parseDiagnostics;
16     if (parseDiagnostics.length) {
17         throw convert_1.convertError(parseDiagnostics[0]);
18     }
19     /**
20      * Recursively convert the TypeScript AST into an ESTree-compatible AST
21      */
22     const instance = new convert_1.Converter(ast, {
23         errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
24         useJSXTextNode: extra.useJSXTextNode || false,
25         shouldPreserveNodeMaps,
26     });
27     const estree = instance.convertProgram();
28     /**
29      * Optionally remove range and loc if specified
30      */
31     if (!extra.range || !extra.loc) {
32         simple_traverse_1.simpleTraverse(estree, {
33             enter: node => {
34                 if (!extra.range) {
35                     // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
36                     // @ts-expect-error
37                     delete node.range;
38                 }
39                 if (!extra.loc) {
40                     // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
41                     // @ts-expect-error
42                     delete node.loc;
43                 }
44             },
45         });
46     }
47     /**
48      * Optionally convert and include all tokens in the AST
49      */
50     if (extra.tokens) {
51         estree.tokens = node_utils_1.convertTokens(ast);
52     }
53     /**
54      * Optionally convert and include all comments in the AST
55      */
56     if (extra.comment) {
57         estree.comments = convert_comments_1.convertComments(ast, extra.code);
58     }
59     const astMaps = instance.getASTMaps();
60     return { estree, astMaps };
61 }
62 exports.astConverter = astConverter;
63 //# sourceMappingURL=ast-converter.js.map