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, parseSettings, shouldPreserveNodeMaps) {
|
9 | |
10 |
|
11 |
|
12 |
|
13 | const { parseDiagnostics } = ast;
|
14 | if (parseDiagnostics.length) {
|
15 | throw (0, convert_1.convertError)(parseDiagnostics[0]);
|
16 | }
|
17 | |
18 |
|
19 |
|
20 | const instance = new convert_1.Converter(ast, {
|
21 | allowInvalidAST: parseSettings.allowInvalidAST,
|
22 | errorOnUnknownASTType: parseSettings.errorOnUnknownASTType,
|
23 | shouldPreserveNodeMaps,
|
24 | suppressDeprecatedPropertyWarnings: parseSettings.suppressDeprecatedPropertyWarnings,
|
25 | });
|
26 | const estree = instance.convertProgram();
|
27 | |
28 |
|
29 |
|
30 | if (!parseSettings.range || !parseSettings.loc) {
|
31 | (0, simple_traverse_1.simpleTraverse)(estree, {
|
32 | enter: node => {
|
33 | if (!parseSettings.range) {
|
34 |
|
35 |
|
36 | delete node.range;
|
37 | }
|
38 | if (!parseSettings.loc) {
|
39 |
|
40 |
|
41 | delete node.loc;
|
42 | }
|
43 | },
|
44 | });
|
45 | }
|
46 | |
47 |
|
48 |
|
49 | if (parseSettings.tokens) {
|
50 | estree.tokens = (0, node_utils_1.convertTokens)(ast);
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | if (parseSettings.comment) {
|
56 | estree.comments = (0, convert_comments_1.convertComments)(ast, parseSettings.codeFullText);
|
57 | }
|
58 | const astMaps = instance.getASTMaps();
|
59 | return { estree, astMaps };
|
60 | }
|
61 | exports.astConverter = astConverter;
|
62 |
|
\ | No newline at end of file |