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) {
10 * The TypeScript compiler produced fundamental parse errors when parsing the
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]);
20 * Recursively convert the TypeScript AST into an ESTree-compatible AST
22 const instance = new convert_1.Converter(ast, {
23 errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
24 useJSXTextNode: extra.useJSXTextNode || false,
25 shouldPreserveNodeMaps,
27 const estree = instance.convertProgram();
29 * Optionally remove range and loc if specified
31 if (!extra.range || !extra.loc) {
32 simple_traverse_1.simpleTraverse(estree, {
35 // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
40 // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
48 * Optionally convert and include all tokens in the AST
51 estree.tokens = node_utils_1.convertTokens(ast);
54 * Optionally convert and include all comments in the AST
57 estree.comments = convert_comments_1.convertComments(ast, extra.code);
59 const astMaps = instance.getASTMaps();
60 return { estree, astMaps };
62 exports.astConverter = astConverter;
63 //# sourceMappingURL=ast-converter.js.map