1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | var babylon = require("babylon");
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var removeComment = function (str, comment, pos) {
|
23 | var nl = '';
|
24 | var isCommentLine = function (c) { return c.type === 'CommentLine'; };
|
25 | if (isCommentLine(comment)) {
|
26 | var before = str.slice(0, comment.start - pos.removed);
|
27 | var after = str.slice(comment.end - pos.removed);
|
28 | pos.removed += comment.end - comment.start - nl.length;
|
29 | return before + nl + after;
|
30 | }
|
31 | var isCommentBlock = function (c) { return c.type === 'CommentBlock'; };
|
32 | if (isCommentBlock(comment)) {
|
33 | var before = str.slice(0, comment.start - pos.removed);
|
34 | var after = str.slice(comment.end - pos.removed);
|
35 | pos.removed += comment.end - comment.start - nl.length;
|
36 | return before + nl + after;
|
37 | }
|
38 | return str;
|
39 | };
|
40 | var stripComments = function (input, options) {
|
41 | if (typeof input !== 'string') {
|
42 | throw new TypeError('expected a string');
|
43 | }
|
44 | var defaults = {
|
45 |
|
46 |
|
47 | allowReturnOutsideFunction: true,
|
48 |
|
49 | plugins: ['typescript', 'jsx']
|
50 | };
|
51 | var opts = __assign({}, defaults, options);
|
52 | var res = babylon.parse(input, opts);
|
53 | var comments = res.comments;
|
54 | var pos = { start: 0, end: 0, removed: 0 };
|
55 | if (!comments) {
|
56 | return input;
|
57 | }
|
58 | for (var _i = 0, comments_1 = comments; _i < comments_1.length; _i++) {
|
59 | var comment = comments_1[_i];
|
60 | input = removeComment(input, comment, pos);
|
61 | }
|
62 | return input;
|
63 | };
|
64 | exports.default = stripComments;
|
65 |
|
\ | No newline at end of file |