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