UNPKG

@hygiene/core

Version:

Keep your TODOs and FIXMEs healthy

63 lines (51 loc) 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseText = parseText; var leasot = _interopRequireWildcard(require("leasot")); var _debug2 = _interopRequireDefault(require("debug")); var _codeFrame = require("@babel/code-frame"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } var debug = (0, _debug2.default)("hygiene/core"); function parseText(content, filename, extension, bodyParser) { if (!leasot.isExtensionSupported(extension)) { debug("".concat(extension, " is not supported yet")); return Promise.resolve([]); } var promises = leasot.parse(content, { extension: extension, filename: filename, // FIXME: https://github.com/pgilad/leasot/pull/109 withInlineFiles: false }).map( /*#__PURE__*/ function () { var _ref = _asyncToGenerator(function* (todoComment) { return { kind: todoComment.tag, file: todoComment.file, line: todoComment.line, text: todoComment.text, codeFrame: (0, _codeFrame.codeFrameColumns)(content, { start: { line: todoComment.line } }), // @ts-ignore Filter annotation is missing immediately annotation: yield bodyParser(todoComment.text) }; }); return function (_x) { return _ref.apply(this, arguments); }; }()); return Promise.all(promises).then(function (comments) { return comments.filter(function (comment) { return !!comment.annotation; }); }); }