Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / typescript-estree / dist / convert-comments.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 (k !== "default" && Object.prototype.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.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");
27 /**
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
32  * @private
33  */
34 function convertComments(ast, code) {
35     const comments = [];
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
46                 range[1] - textStart
47             : // multiline comments end 2 characters early
48                 range[1] - textStart - 2;
49         comments.push({
50             type,
51             value: code.substr(textStart, textEnd),
52             range,
53             loc,
54         });
55     }, ast);
56     return comments;
57 }
58 exports.convertComments = convertComments;
59 //# sourceMappingURL=convert-comments.js.map