| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.addComment = addComment;
|
|---|
| 7 | exports.addComments = addComments;
|
|---|
| 8 | exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
|---|
| 9 | var _t = require("@babel/types");
|
|---|
| 10 | const {
|
|---|
| 11 | addComment: _addComment,
|
|---|
| 12 | addComments: _addComments
|
|---|
| 13 | } = _t;
|
|---|
| 14 | function shareCommentsWithSiblings() {
|
|---|
| 15 | if (typeof this.key === "string") return;
|
|---|
| 16 | const node = this.node;
|
|---|
| 17 | if (!node) return;
|
|---|
| 18 | const trailing = node.trailingComments;
|
|---|
| 19 | const leading = node.leadingComments;
|
|---|
| 20 | if (!trailing && !leading) return;
|
|---|
| 21 | const prev = this.getSibling(this.key - 1);
|
|---|
| 22 | const next = this.getSibling(this.key + 1);
|
|---|
| 23 | const hasPrev = Boolean(prev.node);
|
|---|
| 24 | const hasNext = Boolean(next.node);
|
|---|
| 25 | if (hasPrev) {
|
|---|
| 26 | if (leading) {
|
|---|
| 27 | prev.addComments("trailing", removeIfExisting(leading, prev.node.trailingComments));
|
|---|
| 28 | }
|
|---|
| 29 | if (trailing && !hasNext) prev.addComments("trailing", trailing);
|
|---|
| 30 | }
|
|---|
| 31 | if (hasNext) {
|
|---|
| 32 | if (trailing) {
|
|---|
| 33 | next.addComments("leading", removeIfExisting(trailing, next.node.leadingComments));
|
|---|
| 34 | }
|
|---|
| 35 | if (leading && !hasPrev) next.addComments("leading", leading);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | function removeIfExisting(list, toRemove) {
|
|---|
| 39 | if (!(toRemove != null && toRemove.length)) return list;
|
|---|
| 40 | const set = new Set(toRemove);
|
|---|
| 41 | return list.filter(el => {
|
|---|
| 42 | return !set.has(el);
|
|---|
| 43 | });
|
|---|
| 44 | }
|
|---|
| 45 | function addComment(type, content, line) {
|
|---|
| 46 | _addComment(this.node, type, content, line);
|
|---|
| 47 | }
|
|---|
| 48 | function addComments(type, comments) {
|
|---|
| 49 | _addComments(this.node, type, comments);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | //# sourceMappingURL=comments.js.map
|
|---|