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;
9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
14 var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
21 Object.defineProperty(exports, "__esModule", { value: true });
22 exports.convertComments = void 0;
23 const ts = __importStar(require("typescript"));
24 const util_1 = require("tsutils/util/util");
25 const node_utils_1 = require("./node-utils");
26 const ts_estree_1 = require("./ts-estree");
28 * Convert all comments for the given AST.
29 * @param ast the AST object
30 * @param code the TypeScript code
31 * @returns the converted ESTreeComment
34 function convertComments(ast, code) {
36 util_1.forEachComment(ast, (_, comment) => {
37 const type = comment.kind == ts.SyntaxKind.SingleLineCommentTrivia
38 ? ts_estree_1.AST_TOKEN_TYPES.Line
39 : ts_estree_1.AST_TOKEN_TYPES.Block;
40 const range = [comment.pos, comment.end];
41 const loc = node_utils_1.getLocFor(range[0], range[1], ast);
42 // both comments start with 2 characters - /* or //
43 const textStart = range[0] + 2;
44 const textEnd = comment.kind === ts.SyntaxKind.SingleLineCommentTrivia
45 ? // single line comments end at the end
47 : // multiline comments end 2 characters early
48 range[1] - textStart - 2;
51 value: code.substr(textStart, textEnd),
58 exports.convertComments = convertComments;
59 //# sourceMappingURL=convert-comments.js.map