[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
---|
| 7 | exports.addComment = addComment;
|
---|
| 8 | exports.addComments = addComments;
|
---|
| 9 |
|
---|
| 10 | var _t = require("@babel/types");
|
---|
| 11 |
|
---|
| 12 | const {
|
---|
| 13 | addComment: _addComment,
|
---|
| 14 | addComments: _addComments
|
---|
| 15 | } = _t;
|
---|
| 16 |
|
---|
| 17 | function shareCommentsWithSiblings() {
|
---|
| 18 | if (typeof this.key === "string") return;
|
---|
| 19 | const node = this.node;
|
---|
| 20 | if (!node) return;
|
---|
| 21 | const trailing = node.trailingComments;
|
---|
| 22 | const leading = node.leadingComments;
|
---|
| 23 | if (!trailing && !leading) return;
|
---|
| 24 | const prev = this.getSibling(this.key - 1);
|
---|
| 25 | const next = this.getSibling(this.key + 1);
|
---|
| 26 | const hasPrev = Boolean(prev.node);
|
---|
| 27 | const hasNext = Boolean(next.node);
|
---|
| 28 |
|
---|
| 29 | if (hasPrev && !hasNext) {
|
---|
| 30 | prev.addComments("trailing", trailing);
|
---|
| 31 | } else if (hasNext && !hasPrev) {
|
---|
| 32 | next.addComments("leading", leading);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | function addComment(type, content, line) {
|
---|
| 37 | _addComment(this.node, type, content, line);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | function addComments(type, comments) {
|
---|
| 41 | _addComments(this.node, type, comments);
|
---|
| 42 | } |
---|